Created
June 8, 2017 23:52
-
-
Save kenmazaika/e0f9ea68ddbbb3ebce638487b06c04d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_missing_number(sequence) | |
| # sort the numbers in ascending numerical order | |
| # non-string values will be at the beginning | |
| # will be the value 0. This doesn't modify | |
| # the actual array (convert it to an integer) | |
| # it just uses this to map to the array. | |
| numbers = sequence.split.sort do |x, y| | |
| x.to_i <=> y.to_i | |
| end | |
| prev = 0 | |
| numbers.each do |number| | |
| puts number.inspect | |
| if number.to_i.to_s != number | |
| return 1 | |
| end | |
| if number.to_i != prev + 1 | |
| return prev + 1 | |
| end | |
| prev = prev + 1 | |
| end | |
| return 0 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment