Code for the Advent of Code event
aoc advent-of-code
at main 14 lines 355 B view raw
1#!/usr/bin/env ruby 2# frozen_string_literal: true 3 4SIZE = 25 5NUMS = ARGF.readlines.map(&:to_i).freeze 6 7part1 = NUMS[SIZE..].find.with_index { |n, i| 8 ri = i + SIZE 9 NUMS[ri - SIZE...ri].combination(2).none? { _1 + _2 == n } 10}.tap { puts _1 } 11 12puts (2..).lazy.map { |s| 13 NUMS.each_cons(s).find { _1.sum == part1 } 14}.find { _1 }.then { _1.min + _1.max }