Skip to content

Instantly share code, notes, and snippets.

@Mk-Etlinger
Last active March 8, 2018 14:05
Show Gist options
  • Save Mk-Etlinger/e264dbdf495f55af78bd9f388cf5baf2 to your computer and use it in GitHub Desktop.
Save Mk-Etlinger/e264dbdf495f55af78bd9f388cf5baf2 to your computer and use it in GitHub Desktop.
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