Code for the Advent of Code event
aoc
advent-of-code
1#!/usr/bin/env ruby
2# frozen_string_literal: true
3
4OPPOSITE_TYPE = {
5 generator: :microchip,
6 microchip: :generator
7}.freeze
8
9START_FLOOR = 0
10TARGET_FLOOR = 3
11
12Item = Struct.new('Item', :type, :element) do
13 def compatible?(other)
14 type == OPPOSITE_TYPE[other.type] && element == other.element
15 end
16
17 def to_s
18 "#{element} #{type}"
19 end
20
21 def inspect
22 "#{element} #{type}"
23 end
24end
25
26State = Struct.new('State', :items, :elevator)
27
28floors = ARGF.map do |line|
29 line.scan(/([a-z]+)(?:-compatible)? (generator|microchip)/).map { |e, t| Item.new t.to_sym, e.to_sym }
30end
31
32# state: elevator position, elevator contents, floor contents
33
34p floors
35
36require 'pry'
37binding.pry