Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created August 18, 2012 23:51
Show Gist options
  • Select an option

  • Save lune-sta/3390398 to your computer and use it in GitHub Desktop.

Select an option

Save lune-sta/3390398 to your computer and use it in GitHub Desktop.
Project Euler 31
$p = [1,2,5,10,20,50,100,200]
$ans = 0
def dfs(n)
case n.inject{|a,b|a+b}
when 0..199
$p.each{|a|dfs(n<<a)}
when 200
$ans += 1
p n
else
end
end
$p.each{|a|dfs([a])}
p $ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment