Code for the Advent of Code event
aoc advent-of-code
at rust 9 lines 310 B view raw
1#!/usr/bin/env ruby 2# frozen_string_literal: true 3 4input = $stdin.each_line.map { |l| l.split.map(&:to_i) } 5part1 = input.reduce(0) { |a, e| a + e.max - e.min } 6part2 = input.reduce(0) { |a, e| a + e.permutation(2).find { |p| p.reduce(&:%) == 0 }.reduce(&:/) } 7 8puts "Part 1: #{part1}" 9puts "Part 2: #{part2}"