This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
else | |
data = File.readlines(ARGV.first, chomp: true) | |
end | |
def blueprints(data) | |
data.map do |line| | |
match = /Blueprint (?<id>\d+): Each ore robot costs (?<ore_robot_ore>\d+) ore. Each clay robot costs (?<clay_robot_ore>\d+) ore. Each obsidian robot costs (?<obsidian_robot_ore>\d+) ore and (?<obsidian_robot_clay>\d+) clay. Each geode robot costs (?<geode_robot_ore>\d+) ore and (?<geode_robot_obsidian>\d+) obsidian./.match(line) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Piece | |
attr_reader :shape, :kind | |
ORDER = [ | |
:dash, | |
:plus, | |
:jay, | |
:line, | |
:square |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
else | |
data = File.readlines(ARGV[0], chomp: true) | |
end | |
VALVES = {} | |
GRAPH = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require 'set' | |
# require 'byebug' | |
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
else | |
data = File.readlines(ARGV[0], chomp: true) | |
end | |
ADJ = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
y = 10 | |
MAX = 20 | |
else | |
data = File.readlines(ARGV[0], chomp: true) | |
y = 2000000 | |
MAX = 4000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
y = 10 | |
else | |
data = File.readlines(ARGV[0], chomp: true) | |
y = 2000000 | |
end | |
sensors = Set.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'byebug' | |
if ARGV.empty? | |
input = <<~INPUT | |
498,4 -> 498,6 -> 496,6 | |
503,4 -> 502,4 -> 502,9 -> 494,9 | |
INPUT | |
else | |
input = File.read(ARGV.first, chomp: true) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid(l, r) | |
return nil if l.empty? && r.empty? | |
return true if l.empty? | |
return false if r.empty? | |
l_head, *l_tail = l | |
r_head, *r_tail = r | |
case [l_head, r_head] | |
in [Integer, Integer] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
else | |
data = File.readlines(ARGV[0], chomp: true) | |
end | |
grid = data.map(&:chars) | |
heights = Array.new(grid.size) { Array.new(grid[0].size) } | |
distances = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Monkey | |
attr_reader :inspection_count, :test | |
@monkeys = {} | |
def self.parse(monkey_data) | |
n, i, o, t, tr, fa = monkey_data.split("\n") | |
name = n.split(/:| /)[1].to_i | |
items = i.split(': ').last.split(', ').map(&:to_i) | |
operation = o.split('= ').last | |
test = t.split(' ').last.to_i |