Skip to content

Instantly share code, notes, and snippets.

@wasamasa
Last active July 29, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasamasa/3962b3ab98e80d760545e247b1c29388 to your computer and use it in GitHub Desktop.
Save wasamasa/3962b3ab98e80d760545e247b1c29388 to your computer and use it in GitHub Desktop.
# ugly
(0..5).each do |i|
(0..(5 - i)).each do |j|
(0..(5 - i - j)).each do |k|
l = 5 - i - j - k
p [i, j, k, l]
end
end
end
# better
magic(sum: 5, depth: 4).each { |i, j, k, l| p [i, j, k, l] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment