Mercurial > repos > other > adventofcode2023
diff day15.rb @ 22:ad73a2ff3d06
Implement Day 15 part 1 and all of Day 16
Hash implementation was trivial, but I skipped the rest for now.
Day 16 part 1 approach works unchanged for part 2! Just needed
to run repeatedly with different inputs.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 16 Dec 2023 14:42:06 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/day15.rb Sat Dec 16 14:42:06 2023 +0000 @@ -0,0 +1,11 @@ +#! /usr/bin/env ruby + +if ARGV.length != 1 + abort("Incorrect arguments - needs input file") +elsif not File.exist? (ARGV[0]) + abort("File #{ARGV[0]} did not exist") +end + +file = ARGV[0] + +puts File.open(file, "r").each_line(chomp: true).first.split(",").map {|str| str.each_char.map(&:ord).reduce(0) {|sum, c| puts ((sum + c) * 17) % 256; ((sum + c) * 17) % 256 }}.reduce(:+)