Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Created December 22, 2011 21:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save d11wtq/29ee078033a901ae023e to your computer and use it in GitHub Desktop.
Removing the sugar from a some complex ruby code for a newbie
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment