Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Last active December 5, 2017 18:29
Show Gist options
  • Save RoxasShadow/ea6849bad6e841f8ed06c66138a6dd79 to your computer and use it in GitHub Desktop.
Save RoxasShadow/ea6849bad6e841f8ed06c66138a6dd79 to your computer and use it in GitHub Desktop.
puzzle = <<-EOF
5 1 9 5
7 5 3
2 4 6 8
EOF
puzzle.lines.map { |l| l.split.map(&:to_i).minmax.inject(:-).abs }.inject(:+)
@RoxasShadow
Copy link
Author

Part 2:

puzzle.lines.map { |l| l.split.map(&:to_i).permutation(2).to_a.select { |a, b| a % b == 0 }.map { |a, b| a / b } }.flatten.inject(:+)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment