From: Mike Lowis Date: Thu, 3 Dec 2026 04:06:21 +0000 (-0500) Subject: finished 1 and 2 in ruby X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=projs%2Faoc2026.git finished 1 and 2 in ruby --- 2d522f748683701c00b3410712dcb7909ff0eee5 diff --git a/1.fs b/1.fs new file mode 100644 index 0000000..eba6166 --- /dev/null +++ b/1.fs @@ -0,0 +1,45 @@ +\ Advent of Code 2026 - Day 1 + + + + +\ 0 container-count+ +\ 0 container-count+ +\ 0 container-count+ + +\ container-ids @ @ .s + +\ allocate a buffer +\ read a file line by line +\ for each line in the file +\ parse the line into a container ID +\ increment the container count for that id +\ end for each line + + + + +256 constant max-line + +create line-buffer + max-line 2 + allot + +create container-ids + 1024 cells allot + +: container-count+ + cells + container-ids @ + + dup @ 1 + + swap ! +; + + +s" 1.txt" r/o open-file +\ line-buffer max-line fd-in read-line throw + + +\ line-buffer ." + +\ .s +\ bye ; *waves* diff --git a/1.rb b/1.rb new file mode 100755 index 0000000..45bbd55 --- /dev/null +++ b/1.rb @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby + +pp File.read("1.txt").lines.map(&:to_i).tally.map { |k, v| [v, k] }.sort[-3..-1].map(&:last).reduce(:*) \ No newline at end of file diff --git a/2.rb b/2.rb new file mode 100755 index 0000000..c647cab --- /dev/null +++ b/2.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +WAYPOINTS = "roygbv".chars.cycle +PROG = File.read("2.txt").strip + +curr = 0 +total = 0 +PROG.each_char do |c| + curr = (curr + 1) % 6 + count = 1 + WAYPOINTS.next + while WAYPOINTS.peek != c + count += 1 + WAYPOINTS.next + end + total += count +end +pp total +