Skip to content

Commit cfaf35c

Browse files
committed
The previous version wasn't working correctly.
1 parent c50724b commit cfaf35c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

BaseNegativeNumbers/BaseNegativeNumbers.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
else
66
nums = n.chars.map.with_index do |c, i|
77
j = n.length - i - 1
8-
if j % 2 != 0
9-
r ** (j + 1) - (r - c.to_i) * r ** j
8+
if j % 2 != 0 && c.to_i != 0
9+
r ** (j + 1) + (r - c.to_i) * r ** j
1010
else
1111
c.to_i * r ** j
1212
end
1313
end
1414
nums.reduce(&:+).to_s r
1515
end
1616

17-
puts result
17+
puts result

0 commit comments

Comments
 (0)