aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-20 09:02:44 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-20 09:02:44 +0100
commit069db00a05cdc880a44891e0cbb16543bfd57ebd (patch)
treed874fd83d730d98716f43131f5f06abf8fc63102
parenteee14769b46a0dbf5f6765827b6daab333d259fc (diff)
Add 2019 day 8 solutionsHEADmaster
-rw-r--r--2019/08/puzzle-1.el25
-rw-r--r--2019/08/puzzle-2.el27
2 files changed, 52 insertions, 0 deletions
diff --git a/2019/08/puzzle-1.el b/2019/08/puzzle-1.el
new file mode 100644
index 0000000..ad82334
--- /dev/null
+++ b/2019/08/puzzle-1.el
@@ -0,0 +1,25 @@
+;;; -*- lexical-binding: t; -*-
+
+(defun main (filename)
+ (with-temp-buffer
+ (insert-file-contents-literally filename)
+ (let* ((width 25)
+ (height 6)
+ (area (* width height))
+ (min-zeros most-positive-fixnum)
+ answer)
+ (while (not (eobp))
+ (let* ((end (+ (point) area))
+ (string (buffer-substring (point) end))
+ (zeros (seq-count (make-= ?0) string)))
+ (when (< zeros min-zeros)
+ (setq min-zeros zeros
+ answer (* (seq-count (make-= ?1) string)
+ (seq-count (make-= ?2) string))))
+ (goto-char end)))
+ answer)))
+
+(defun make-= (x)
+ (lambda (y) (= x y)))
+
+(message "%d" (main "input")) \ No newline at end of file
diff --git a/2019/08/puzzle-2.el b/2019/08/puzzle-2.el
new file mode 100644
index 0000000..61eed93
--- /dev/null
+++ b/2019/08/puzzle-2.el
@@ -0,0 +1,27 @@
+;;; -*- lexical-binding: t; -*-
+
+(defun main (filename)
+ (let* ((string (with-temp-buffer
+ (insert-file-contents-literally filename)
+ (buffer-substring-no-properties (point-min) (point-max))))
+ (width 25)
+ (height 6)
+ (area (* width height))
+ (image (thread-last
+ (seq-partition string area)
+ (apply #'seq-mapn #'first-visible-pixel)
+ (apply #'string))))
+ (switch-to-buffer "*Advent of Code — 2019 Day 8*")
+ (save-excursion
+ (insert image))
+ (while (not (eobp))
+ (goto-char (+ (point) width))
+ (insert ?\n))))
+
+(defun first-visible-pixel (&rest pixels)
+ (pcase (seq-find (lambda (x) (/= x ?2)) pixels ?2)
+ (?0 ?.)
+ (?1 ?#)
+ (?2 32)))
+
+(main "input") \ No newline at end of file