From 5e1f67166cc7607b2b45396a210462ec62b0433e Mon Sep 17 00:00:00 2001
From: Oscar Najera <hi@oscarnajera.com>
Date: Sat, 10 Dec 2022 18:44:41 +0100
Subject: [AoC2022] ELisp 10-1

---
 AoC2022/10/eg-in     | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++
 AoC2022/10/input     | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++
 AoC2022/10/solver.el |  49 +++++++++++++++++
 3 files changed, 339 insertions(+)
 create mode 100644 AoC2022/10/eg-in
 create mode 100644 AoC2022/10/input
 create mode 100644 AoC2022/10/solver.el

(limited to 'AoC2022/10')

diff --git a/AoC2022/10/eg-in b/AoC2022/10/eg-in
new file mode 100644
index 0000000..37ee8ee
--- /dev/null
+++ b/AoC2022/10/eg-in
@@ -0,0 +1,146 @@
+addx 15
+addx -11
+addx 6
+addx -3
+addx 5
+addx -1
+addx -8
+addx 13
+addx 4
+noop
+addx -1
+addx 5
+addx -1
+addx 5
+addx -1
+addx 5
+addx -1
+addx 5
+addx -1
+addx -35
+addx 1
+addx 24
+addx -19
+addx 1
+addx 16
+addx -11
+noop
+noop
+addx 21
+addx -15
+noop
+noop
+addx -3
+addx 9
+addx 1
+addx -3
+addx 8
+addx 1
+addx 5
+noop
+noop
+noop
+noop
+noop
+addx -36
+noop
+addx 1
+addx 7
+noop
+noop
+noop
+addx 2
+addx 6
+noop
+noop
+noop
+noop
+noop
+addx 1
+noop
+noop
+addx 7
+addx 1
+noop
+addx -13
+addx 13
+addx 7
+noop
+addx 1
+addx -33
+noop
+noop
+noop
+addx 2
+noop
+noop
+noop
+addx 8
+noop
+addx -1
+addx 2
+addx 1
+noop
+addx 17
+addx -9
+addx 1
+addx 1
+addx -3
+addx 11
+noop
+noop
+addx 1
+noop
+addx 1
+noop
+noop
+addx -13
+addx -19
+addx 1
+addx 3
+addx 26
+addx -30
+addx 12
+addx -1
+addx 3
+addx 1
+noop
+noop
+noop
+addx -9
+addx 18
+addx 1
+addx 2
+noop
+noop
+addx 9
+noop
+noop
+noop
+addx -1
+addx 2
+addx -37
+addx 1
+addx 3
+noop
+addx 15
+addx -21
+addx 22
+addx -6
+addx 1
+noop
+addx 2
+addx 1
+noop
+addx -10
+noop
+noop
+addx 20
+addx 1
+addx 2
+addx 2
+addx -6
+addx -11
+noop
+noop
+noop
diff --git a/AoC2022/10/input b/AoC2022/10/input
new file mode 100644
index 0000000..062e859
--- /dev/null
+++ b/AoC2022/10/input
@@ -0,0 +1,144 @@
+addx 2
+addx 3
+noop
+addx 1
+addx 27
+addx -23
+addx 5
+noop
+addx 1
+noop
+addx 4
+addx 1
+noop
+addx 4
+addx 5
+noop
+noop
+noop
+addx 5
+addx -4
+addx 4
+noop
+addx 1
+addx -38
+noop
+noop
+addx 7
+addx 8
+addx -3
+noop
+addx 3
+noop
+addx 5
+noop
+noop
+addx -2
+addx 2
+addx 9
+addx -2
+addx 6
+addx 1
+addx -4
+addx 5
+addx 2
+addx -14
+addx -6
+addx -16
+addx 1
+addx 5
+addx 1
+addx 4
+addx -2
+noop
+addx -7
+addx -3
+addx 17
+addx 5
+noop
+noop
+addx 19
+addx -16
+noop
+addx 14
+addx -8
+addx 2
+noop
+addx 4
+noop
+addx -35
+addx -2
+noop
+noop
+addx 7
+addx 19
+addx -26
+addx 10
+addx 29
+addx -21
+noop
+addx 4
+noop
+noop
+addx -9
+addx 4
+addx 8
+addx 7
+noop
+addx -2
+addx 5
+addx 2
+addx -19
+addx -18
+noop
+noop
+noop
+noop
+addx 7
+addx -7
+addx 37
+addx -27
+addx 5
+addx 2
+addx -12
+addx 4
+addx 11
+noop
+noop
+noop
+addx 5
+addx -14
+addx 21
+addx -4
+addx 5
+addx 2
+noop
+addx -35
+noop
+noop
+noop
+noop
+addx 7
+addx 1
+noop
+noop
+addx 5
+addx -1
+addx 5
+addx 1
+noop
+addx 4
+addx 1
+noop
+noop
+addx 4
+noop
+addx 1
+addx 2
+addx 5
+addx 2
+addx 1
+noop
+noop
+noop
+noop
diff --git a/AoC2022/10/solver.el b/AoC2022/10/solver.el
new file mode 100644
index 0000000..5a8b6f8
--- /dev/null
+++ b/AoC2022/10/solver.el
@@ -0,0 +1,49 @@
+;;; solver.el --- Day 10 -*- lexical-binding: t; -*-
+;;
+;; Copyright (C) 2022 Óscar Nájera
+;;
+;; Author: Óscar Nájera <hi@oscarnajera.com>
+;; Maintainer: Óscar Nájera <hi@oscarnajera.com>
+;; Created: December 10, 2022
+;; Modified: December 10, 2022
+;;
+;; This file is not part of GNU Emacs.
+;;
+;;; Commentary:
+;;
+;;  Day 10
+;;
+;;; Code:
+
+(require 'f)
+(require 'subr-x)
+(require 'cl-lib)
+(require 'ert)
+
+(defsubst solver-probe (cycle register)
+  (when (memq cycle '(20 60 100 140 180 220))
+    (* cycle register)))
+
+(let ((register 1)
+      (cycle 1)
+      measures)
+  (dolist (instruction (split-string (f-read "input") "\n"))
+    (cl-incf cycle)
+    (let ((step1 (solver-probe cycle register)) ;; the noop default
+          (step2                                ;; addx takes 2 cycles
+           (when (string-prefix-p "addx" instruction)
+             (cl-incf cycle)
+             (cl-incf register (string-to-number (cadr (split-string instruction))))
+             (solver-probe cycle register))))
+      (when-let ((probe (or step1 step2)))
+        (push probe measures))))
+  (list (reverse measures)
+        (apply #'+ measures)
+        cycle))
+
+
+
+
+
+(provide 'solver)
+;;; solver.el ends here
-- 
cgit v1.2.3