Last active
March 8, 2018 14:05
-
-
Save Mk-Etlinger/e264dbdf495f55af78bd9f388cf5baf2 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 self.parse(string) | |
sum = 0 | |
char_array = string.split | |
char_array.each_with_index do |char, i| | |
sum += char.to_i | |
next unless char == '-' && char_array[i + 2] | |
if char_array[i + 2].to_i == 0 | |
char_array[i + 1] = char + char_array[i + 1] | |
else | |
char_array[i + 2] = char + char_array[i + 2] | |
end | |
end | |
sum | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment