Code for the Advent of Code event
aoc advent-of-code
at rust 17 lines 594 B view raw
1#!/usr/bin/env ruby 2# frozen_string_literal: true 3 4eval(ARGF.read.gsub(/(?<=\d)\b/, '.0').gsub(/(\w+): (.+)\n?/) do 5 if $1 == 'root' 6 "def #{$1}; #{$2}; end; def #{$1}2; #{$2.scan(/\w+/).join(' - ')}; end;" 7 else 8 "def #{$1}; #{$2}; end;" # rubocop:disable Lint/OutOfRangeRegexpRef 9 end 10end) 11 12puts root.to_i 13 14part2 = (0..100_000_000_000_000).bsearch { |n| eval("def humn; #{n}; end"); root2 <=> 0 } # rubocop:disable Style/EvalWithLocation 15part2 ||= (0..100_000_000_000_000).bsearch { |n| eval("def humn; #{n}; end"); 0 <=> root2 } # rubocop:disable Style/EvalWithLocation 16 17puts part2