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
cycles = 0 | |
cycle_tracker = {} | |
x = 1 | |
if ARGV.empty? | |
data = DATA.readlines(chomp: true) | |
else | |
data = File.readlines(ARGV[0], 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
require 'set' | |
def parse_moves(input) | |
input | |
.map(&:chomp) | |
.map {_1.split(' ')} | |
.map {[_1[0], _1[1].to_i]} | |
end | |
def follow(head, tail) |
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 | |
else | |
data = File.readlines(ARGV[0]) | |
end | |
trees = data | |
.map(&:chomp) | |
.map {_1.chars} | |
.map {_1.map(&:to_i)} |
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 | |
else | |
data = File.readlines(ARGV[0]) | |
end | |
cwd = [] | |
dir_sizes = Hash.new { |h, k| h[k] = 0 } |
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 'rspec/autorun' | |
require 'set' | |
def marker(input, length) | |
input | |
.chars | |
.each_cons(length) | |
.map(&:to_set) | |
.find_index { |set| set.size == length } + length | |
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 read_towers(data) | |
towers = [] | |
data | |
.split("\n") | |
.map { |line| line.split(/\s{4}| /) } | |
.reverse | |
.each_with_index do |level, i| | |
next if i == 0 |
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 | |
else | |
data = File.readlines(ARGV[0]) | |
end | |
results = data | |
.map(&:chomp) |
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
# data = DATA.readlines | |
data = File.readlines(ARGV.first) | |
# PART 1 | |
# result = data | |
# .map(&:chomp) | |
# .map(&:chars) | |
# .map { _1.each_slice(_1.length / 2).to_a } | |
# .map {|(left, right)| left & right } |
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 'rspec/autorun' | |
def result(them, me) | |
me.ord - 87 | |
end | |
def bonus(them, me) | |
case [them, me] | |
in ['A', 'Z'] | ['B', 'X'] | ['C', 'Y'] | |
0 |
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
# data = DATA.readlines | |
data = File.readlines(ARGV.first) | |
p data | |
.map(&:chomp) | |
.chunk_while { _2 != "" } | |
.map { _1.map(&:to_i) } | |
.map(&:sum) | |
.sort[-3..] |