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 |
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 } |