secret
Created

Removing the sugar from a some complex ruby code for a newbie

  • Download Gist
senza-zucchero.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
digit = [ 4, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8 ]
decade = [4, 3, 6, 6, 5, 5, 5, 7, 6, 6]
 
sum = 0
 
for n in (1..1000)
if n > 999
sum += 11
n = n % 1000
end
 
if n > 99
sum += digit[n / 100] + 7
if n % 100 > 0
sum += 3
end
n = n % 100
end
 
if n > 19
sum += decade[n / 10]
n = n % 10
end
 
if n > 0
sum += digit[n]
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.