But that isn't an increment of 0.1. 1.2 is in your list twice, and 1.15 doesn't belong there at all. Are you really talking about floating values, or are you
talking about some kind of version number or the like?
Anyway, the algorithm is easy. Given the increment and the array, take the
starting value in the array and add the increment to it to form your expected
value. Then loop through the array from the second element on: for each
element, while it's more than the expected value, put the expected value in
your list of missing values and increment it. If the array element is equal
to your expected value, increment the expected value and go on to the next
Where I say "more than" or "equal to", allow for floating point imprecision and rounding error.
Alternatively, collect all values equal to the starting value plus some multiple of
the increment that are between the starting and ending values (perhaps as hash keys), then remove all those that appear in your array. What's left are the
If the increment isn't provided, you could initially take it as the difference
between the first two elements in the array, then correct it if you find values
that don't work with that increment.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||