Skip to content

Instantly share code, notes, and snippets.

View cjavdev's full-sized avatar
👉

CJ Avilla cjavdev

👉
View GitHub Profile
cycles = 0
cycle_tracker = {}
x = 1
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV[0], chomp: true)
end
require 'set'
def parse_moves(input)
input
.map(&:chomp)
.map {_1.split(' ')}
.map {[_1[0], _1[1].to_i]}
end
def follow(head, tail)
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)}
if ARGV.empty?
data = DATA.readlines
else
data = File.readlines(ARGV[0])
end
cwd = []
dir_sizes = Hash.new { |h, k| h[k] = 0 }
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
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
require 'set'
if ARGV.empty?
data = DATA.readlines
else
data = File.readlines(ARGV[0])
end
results = data
.map(&:chomp)
# 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 }
# 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
# data = DATA.readlines
data = File.readlines(ARGV.first)
p data
.map(&:chomp)
.chunk_while { _2 != "" }
.map { _1.map(&:to_i) }
.map(&:sum)
.sort[-3..]