aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2022-12-10 18:44:41 +0100
committerOscar Najera <hi@oscarnajera.com>2022-12-10 18:44:41 +0100
commit5e1f67166cc7607b2b45396a210462ec62b0433e (patch)
tree9ec465ad707161b1aec263602986c29ae8f9dc80 /AoC2022
parentf414e9a4a26d74402a569ddcb1ba964394267899 (diff)
downloadscratch-5e1f67166cc7607b2b45396a210462ec62b0433e.tar.gz
scratch-5e1f67166cc7607b2b45396a210462ec62b0433e.tar.bz2
scratch-5e1f67166cc7607b2b45396a210462ec62b0433e.zip
[AoC2022] ELisp 10-1
Diffstat (limited to 'AoC2022')
-rw-r--r--AoC2022/10/eg-in146
-rw-r--r--AoC2022/10/input144
-rw-r--r--AoC2022/10/solver.el49
3 files changed, 339 insertions, 0 deletions
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