Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
663 B · 29 lines
Ruby
at rust
123456789101112131415161718192021222324252627282930#!/usr/bin/env ruby# frozen_string_literal: true
map = Hash.new(10)ARGF.readlines.each_with_index do |l, r| l.strip.chars.map(&:to_i).each_with_index { map[[_2, r]] = _1 }end
def around(pos) [ [pos[0], pos[1] - 1], [pos[0], pos[1] + 1], [pos[0] - 1, pos[1]], [pos[0] + 1, pos[1]] ]end
lows = map.keys.select { |p| around(p).all? { map[p] < map[_1] } }
puts lows.map { map[_1] + 1 }.sum
puts lows.map { |start| visited = Set.new queue = [start] while queue.any? current = queue.pop visited << current queue.push *around(current).select { !visited.include?(_1) && map[_1] < 9 } end visited.size}.sort.pop(3).reduce(:*)