]> git.mdlowis.com Git - projs/aoc2026.git/commitdiff
finished 1 and 2 in ruby master
authorMike Lowis <mike@mdlowis.com>
Thu, 3 Dec 2026 04:06:21 +0000 (23:06 -0500)
committerMike Lowis <mike@mdlowis.com>
Thu, 3 Dec 2026 04:06:21 +0000 (23:06 -0500)
1.fs [new file with mode: 0644]
1.rb [new file with mode: 0755]
2.rb [new file with mode: 0755]

diff --git a/1.fs b/1.fs
new file mode 100644 (file)
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 (executable)
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 (executable)
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
+