Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
684 B · 37 lines
Ruby
at rust
1234567891011121314151617181920212223242526272829303132333435363738#!/usr/bin/env ruby# frozen_string_literal: true
OPPOSITE_TYPE = { generator: :microchip, microchip: :generator}.freeze
START_FLOOR = 0TARGET_FLOOR = 3
Item = Struct.new('Item', :type, :element) do def compatible?(other) type == OPPOSITE_TYPE[other.type] && element == other.element end
def to_s "#{element} #{type}" end
def inspect "#{element} #{type}" endend
State = Struct.new('State', :items, :elevator)
floors = ARGF.map do |line| line.scan(/([a-z]+)(?:-compatible)? (generator|microchip)/).map { |e, t| Item.new t.to_sym, e.to_sym }end
# state: elevator position, elevator contents, floor contents
p floors
require 'pry'binding.pry