Skip to content

Instantly share code, notes, and snippets.

@maxluzuriaga
Created April 25, 2014 23:37
Show Gist options
  • Save maxluzuriaga/11306913 to your computer and use it in GitHub Desktop.
Save maxluzuriaga/11306913 to your computer and use it in GitHub Desktop.
Fog Creek Puzzle Solution
LETTERS = "acdegilmnoprstuw"
def reverse(h, str)
if (h == 7)
return str.reverse
elsif (h < 7)
return false
end
if ((h % 1) != 0)
return false
end
0.upto(LETTERS.length - 1) do |i|
newh = (h - i) / 37.0
newstr = str + LETTERS[i]
result = reverse(newh, newstr)
if (result != false)
return result
end
end
end
puts reverse(910897038977002, "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment