aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Williams <tgwil@tgwil.net>2025-01-11 14:07:50 -0500
committerTristan Williams <tgwil@tgwil.net>2025-01-11 14:07:50 -0500
commit03e14731fb51fafbf7931231674ecf7a621fcbf4 (patch)
tree969f82a20353cd279354b97b26fde756651780b3
downloadaoc-03e14731fb51fafbf7931231674ecf7a621fcbf4.tar.gz
aoc-03e14731fb51fafbf7931231674ecf7a621fcbf4.tar.bz2
aoc-03e14731fb51fafbf7931231674ecf7a621fcbf4.zip
Complete AoC 2015 Day 1
-rw-r--r--README.md25
-rw-r--r--license.txt18
-rw-r--r--src/2015.01.01-first-attempt.lisp69
-rw-r--r--src/2015.01.02-more-lispy-this-time.lisp106
-rw-r--r--src/2015.01._PUZZLE-INPUT.txt1
5 files changed, 219 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..57255bc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,25 @@
1# Advent of Code
2
3This repository contains my solutions to [Advent of Code](https://adventofcode.com/) puzzles. I intend to start from Day 1 of the first year and working through them all. I will probably eventually do this in multiple languages.
4
5All solutions are contained within the `/src` directory and are named suchly:
6
7`YEAR.DAY.ATTEMPT.EXT`
8
9First attempts (per language) are named `01-first-attempt`, and are never edited afterwards. Editing is why I designed the file naming scheme to handle multiple attempts.
10
11For example:
12- `2015.01.01-first-attempt.c`
13- `2015.01.01-first-attempt.lisp`
14- `2016.05.03-recursive.lisp`
15
16
17## Progress
18
19The following table shows the number of complete attempts I've produced for each problem+language combination.
20
21COMPLETE SOLUTIONS: 0
22
23| DAY | CL |
24|---------|----|
25| 2015.01 | |
diff --git a/license.txt b/license.txt
new file mode 100644
index 0000000..365a8f0
--- /dev/null
+++ b/license.txt
@@ -0,0 +1,18 @@
1Copyright © 2024 Tristan Williams
2
3Permission is hereby granted, free of charge, to any person obtaining a copy
4of this software and associated documentation files (the “Software”), to deal
5in the Software without restriction, including without limitation the rights
6to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7copies of the Software, and to permit persons to whom the Software is
8furnished to do so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/2015.01.01-first-attempt.lisp b/src/2015.01.01-first-attempt.lisp
new file mode 100644
index 0000000..a3fb2c9
--- /dev/null
+++ b/src/2015.01.01-first-attempt.lisp
@@ -0,0 +1,69 @@
1;;;; 2015.01.01-first-attempt.lisp
2;;;; Advent of Code 2015 Day 1, first attempt in Lisp
3
4;; ---------------------------------------------------------------------
5;;; Package Definition
6;; ---------------------------------------------------------------------
7
8(defpackage :2015-01-first-attempt
9 (:use #:common-lisp))
10(in-package :2015-01-first-attempt)
11
12
13
14
15;; ---------------------------------------------------------------------
16;;; Definitions
17;; ---------------------------------------------------------------------
18
19(defparameter *PUZZLE-INPUT-FILE* "~/proj/Learn/aoc/src/2015.01._PUZZLE-INPUT.txt"
20 "File to be used as input to the program.")
21
22(defparameter *PUZZLE-INPUT-STRING* (uiop:read-file-string *PUZZLE-INPUT-FILE*)
23 "String version of the text in `*PUZZLE-INPUT-FILE*'.")
24
25(defparameter *PUZZLE-INPUT* (loop for char across *PUZZLE-INPUT-STRING*
26 collect char)
27 "Puzzle input in lisp list form.")
28
29
30
31
32;; ---------------------------------------------------------------------
33;;; Part 1
34;; -------
35;; Santa is trying to deliver presents in a large apartment building, but
36;; he can't find the right floor - the directions he got are a little
37;; confusing. He starts on the ground floor (floor 0) and then follows
38;; the instructions one character at a time.
39;;
40;; An opening parenthesis, (, means he should go up one floor, and a
41;; closing parenthesis, ), means he should go down one floor.
42;;
43;; The apartment building is very tall, and the basement is very deep;
44;; he will never find the top or bottom floors.
45;;
46;; For example:
47;;
48;; (()) and ()() both result in floor 0.
49;; ((( and (()(()( both result in floor 3.
50;; ))((((( also results in floor 3.
51;; ()) and ))( both result in floor -1 (the first basement level).
52;; ))) and )())()) both result in floor -3.
53;;
54;; To what floor do the instructions take Santa?
55;; ---------------------------------------------------------------------
56
57(defun parse-input (INPUT)
58 "Parse `INPUT' to determine where the instructions take Santa."
59 (let ((FLOOR-NUMBER 0))
60 (+ FLOOR-NUMBER (cond ((eql (first INPUT) nil) 0)
61 ((eql (first INPUT) #\() (+ 1 (parse-input (rest INPUT))))
62 ((eql (first INPUT) #\)) (- (parse-input (rest INPUT)) 1))))))
63
64;; Test for correct answer
65(assert (= 138 (parse-input *PUZZLE-INPUT*)))
66
67
68;; I have elected to just throw this away and not do part 2 in this line of thinking.
69;; Keeping it for posterity.
diff --git a/src/2015.01.02-more-lispy-this-time.lisp b/src/2015.01.02-more-lispy-this-time.lisp
new file mode 100644
index 0000000..15614bc
--- /dev/null
+++ b/src/2015.01.02-more-lispy-this-time.lisp
@@ -0,0 +1,106 @@
1;;;; 2015.01.02-more-lispy-this-time.lisp
2;;;; Advent of Code 2015 Day 1, first attempt in Lisp
3
4;; ---------------------------------------------------------------------
5;;; Package Definition
6;; ---------------------------------------------------------------------
7
8(defpackage :2015-01-02-more-lispy-this-time
9 (:use #:common-lisp))
10(in-package :2015-01-02-more-lispy-this-time)
11
12
13
14
15;; ---------------------------------------------------------------------
16;;; Definitions
17;; ---------------------------------------------------------------------
18
19(defconstant +PUZZLE-INPUT-FILE+ "~/proj/Learn/aoc/src/2015.01._PUZZLE-INPUT.txt"
20 "File to be used as input to the program.")
21
22(defconstant +PUZZLE-INPUT-STRING+ (uiop:read-file-string +PUZZLE-INPUT-FILE+)
23 "String version of the text in `+PUZZLE-INPUT-FILE+'.")
24
25(defconstant +PUZZLE-INPUT-LIST+ (loop for char across +PUZZLE-INPUT-STRING+
26 collect char)
27 "Puzzle input in lisp list form.")
28
29(defconstant +PUZZLE-INPUT-VALUES-LIST+ (mapcar (lambda (INPUT-LIST)
30 (cond ((eql INPUT-LIST #\() 1)
31 ((eql INPUT-LIST #\)) -1)))
32 +PUZZLE-INPUT-LIST+)
33 "Puzzle input converted into floor direction values.")
34
35
36
37
38;; ---------------------------------------------------------------------
39;;; Part 1
40;; -------
41;; Santa is trying to deliver presents in a large apartment building, but
42;; he can't find the right floor - the directions he got are a little
43;; confusing. He starts on the ground floor (floor 0) and then follows
44;; the instructions one character at a time.
45;;
46;; An opening parenthesis, (, means he should go up one floor, and a
47;; closing parenthesis, ), means he should go down one floor.
48;;
49;; The apartment building is very tall, and the basement is very deep;
50;; he will never find the top or bottom floors.
51;;
52;; For example:
53;;
54;; (()) and ()() both result in floor 0.
55;; ((( and (()(()( both result in floor 3.
56;; ))((((( also results in floor 3.
57;; ()) and ))( both result in floor -1 (the first basement level).
58;; ))) and )())()) both result in floor -3.
59;;
60;; To what floor do the instructions take Santa?
61;; ---------------------------------------------------------------------
62
63(defun final-floor (INPUT)
64 "Calculate the final floor Santa ends up on given the provided `INPUT'."
65 (apply #'+ INPUT))
66
67(assert (= 138 (final-floor +PUZZLE-INPUT-VALUES-LIST+)))
68
69
70
71
72;; ---------------------------------------------------------------------
73;;; Part 2
74;; -------
75;; Now, given the same instructions, find the position of the first
76;; character that causes him to enter the basement (floor -1). The first
77;; character in the instructions has position 1, the second character
78;; has position 2, and so on.
79;;
80;; For example:
81;;
82;; ) causes him to enter the basement at character position 1.
83;; ()()) causes him to enter the basement at character position 5.
84;;
85;; What is the position of the character that causes Santa to first enter the basement?
86;; ---------------------------------------------------------------------
87
88(defun next-floor ()
89 "Determine the result of the next button press, go in that direction, and destroy the information so the Nazis don't get their dirty hands on it."
90 (let ((FLOOR-NUMBER 0)
91 (INPUT-POSITION 0)
92 (INPUT +PUZZLE-INPUT-VALUES-LIST+))
93 (lambda ()
94 (list (incf FLOOR-NUMBER (pop INPUT))
95 (incf INPUT-POSITION)))))
96(defvar next-floor (next-floor))
97
98(defun first-basement-input ()
99 "Determine the position of the input in `+PUZZLE-INPUT-VALUES-LIST' which results in the first entry into the basement (floor -1)."
100 (let ((RESULT (funcall next-floor)))
101 (loop until (= -1 (car RESULT))
102 do (setf RESULT (funcall next-floor)))
103 (cdr RESULT)))
104
105;; Test for correct result
106(assert (= 1771 (first-basement-input)))
diff --git a/src/2015.01._PUZZLE-INPUT.txt b/src/2015.01._PUZZLE-INPUT.txt
new file mode 100644
index 0000000..71a7803
--- /dev/null
+++ b/src/2015.01._PUZZLE-INPUT.txt
@@ -0,0 +1 @@
()(((()))(()()()((((()(((())(()(()((((((()(()(((())))((()(((()))((())(()((()()()()(((())(((((((())))()()(()(()(())(((((()()()((())(((((()()))))()(())(((())(())((((((())())))(()())))()))))()())()())((()()((()()()()(()((((((((()()())((()()(((((()(((())((())(()))()((((()((((((((())()((()())(())((()))())((((()())(((((((((((()()(((((()(()))())(((()(()))())((()(()())())())(()(((())(())())()()(()(()((()))((()))))((((()(((()))))((((()(()(()())())()(((()((((())((((()(((()()(())()()()())((()((((((()((()()))()((()))()(()()((())))(((()(((()))((()((()(()))(((()()(()(()()()))))()()(((()(((())())))))((()(((())()(()(())((()())))((((())))(()(()(()())()((()())))(((()((()(())()()((()((())(()()((())(())()))()))((()(())()))())(((((((()(()()(()(())())))))))(()((((((())((((())((())())(()()))))()(())(()())()())((())(()))))(()))(()((()))()(()((((((()()()()((((((((()(()(())((()()(()()))(())()())()((())))()))()())(((()))(())()(())()))()((()((()(()()())(())()()()((())())))((()()(()()((()(())()()())(((()(()()))))(())))(()(()())()))()()))))))()))))((((((())))())))(()(())())(()())))))(()))()))))))()((()))))()))))(()(()((()())())(()()))))(((())()))())())())(((()(()()))(())()(())(())((((((()()))))((()(()))))))(()))())(((()()(()))()())()()()())))))))))))))(())(()))(()))((()(())(()())(())())(()())(())()()(()())))()()()))(())())()))())())(())((())))))))(())))(())))))()))))((())(()(((()))))(()))()((()(())))(()())(((((()))()())()()))))()))))()))())(()(()()()))()))))))((()))))))))))()((()))((()(())((())()()(()()))()(()))))()()(()))()))(((())))(())()((())(())(()())()())())))))))())))()((())))()))(()))()()))(((((((()))())(()()))(()()(()))()(()((()())()))))))(((()()()())))(())()))()())(()()))()()))))))))(())))()))()()))))))()))()())))()(())(())))))()(())()()(()()))))())((()))))()))))(()(((((()))))))))())))())()(())()()))))(())))())()()())()()())()(()))))()))()))))))))())))((()))()))()))())))()())()()())))())))(()((())()((()))())))))())()(())((())))))))))))())()())(())())())(()))(()))()))())(()(())())()())()()(()))))(()(())))))))(())))())(())))))))())()()(())())())))(())))))()))()(()())()(()))())())))))()()(()))()))))())))))))))()))))()))))))())()())()()))))()())))())))))))))))()()))))()()(((()))()()(())()))))((()))))(()))(())())))(())()))))))(()))()))))(())())))))()))(()())))))))))))))())))))))))()((()())(()())))))))((()))))(())(())))()(()())())))())())(()()()())))()))))))())))))())()()())))))))))))()()(()))))()())()))((()())(()))))()(()))))))))))()())())(((())(()))))())()))()))()))))))()))))))(()))))()))))()(())))(())))(()))())()()(()()))()))(()()))))))))()))(()))())(()()(()(()())()()))()))))))))(())))))((()()(()))())())))))()))())(()())()()))())))()(()()()()))((())())))())()(()()))()))))))))(()))(())))()))))(()(()())(()))))()())())()))()()))())))))))))))())()))))))()))))))))())))))()))))())(()())))(())()))())())))))()()(()()())(()())))()()))(((()))(()()()))))()))))()))))((())))()((((((()()))))))())))))))))))(((()))))))))))))(())())))))())(()))))))(()))((()))())))()(()((()))()))()))))))))))())()))()(()()))))())))())(())()(()))()))())(()))()))))(()()))()()(())))))()))(())(()(()()))(()()())))))(((()))))))()))))))))))))(())(()))))()())())()()((()()))())))))(()))))())))))))()()()))))))))())))()(((()()))(())))))(((())())))))((()))()(()))(()))))(()())))(()))())))))()))))(())(())))()((()))(())())))()()))()))))))))()))(()()()(()()()(()))())(())()())(((()))(())))))))))(((()())))()()))))))))()(())(()))()((((())(())(()())))()))(((())()()()))((()))(()))())())))())))(()))())()())())(()(())())()()()(())))())(())))(())))(())()))()))(()((()))))))))())(()))))))())(()()))()()))()(()(()())))()()(()((()((((((()))(())))()()()))())()))((()()(()))())((()(()(()))(()()))))()())))()))()())))))))()()((()())(())))()))(()))(())(()))())(()(())))()()))))))(((()(((()()))()(()(())())((()()))()))()))()))()(()()()(()))((()())()(())))()()))(((())()()())(())()((()()()()(()(())(()()))()(((((()())))((())))))(()()()))))(((()(())))()))((()((()(())()(()((())))((()())()(()))(((()())()()(()))(())(((()((()())()((())()())(((()()))((()((())(()))(()())(()()()))((()))(())(()((()()())((()))(())))(())(())(())))(()())))(((((()(()(((((()())((((()(()())(())(()()(((())((()(((()()(((()()((((((())))())(()((((((()(()))()))()()((()((()))))()(()()(()((()()))))))(((((()(((((())()()()(())())))))))()))((()()(())))(())(()()()())))))(()((((())))))))()()(((()(()(()(()(()())()()()(((((((((()()())()(()))((()()()()()(((((((()())()((())()))((((((()(()(()(()())(((()(((((((()(((())(((((((((())(())())()))((()(()))(((()()())(())(()(()()(((()(())()))())))(())((((((())(()()())()()(((()(((())(()(((())(((((((()(((((((((()))(())(()(()(()))))((()))()(())())())((()(()((()()))((()()((()(())(())(()((())(((())(((()()()((((((()()(())((((())()))))(())((()(()((())))(((((()(()()())())((())())))((())((()((()()((((((())(((()()(()())())(()(()))(()(()))())())()(((((((()(((()(())()()((())((()(()()((()(()()(((((((((((())((())((((((())((()((((()(()((((()(((((((())()((()))))())()((()((((()(()(((()((()())))(())())(((()(((())((((((()(((((((((()()(())))(()(((((()((((()())))((()((()((()(()()(((())((((((((((((()(((())(()(((((()))(()()(()()()()()()((())(((((((())(((((())))))())()(()()(()(()(((()()(((((())(()((()((()(((()()((()((((())()))()((((())(())))()())(((())(())(()()((()(((()()((((((((((()()(()())())(((((((((())((((()))()()((((())(()((((()(((())())(((((((((((()((((())))(())(()(((()(((()((())(((((()((()()(()(()()((((((()((((()((()(()((()(()((((((()))))()()(((((()((()(()(())()))(())(((((((()((((()())(()((()((()(()))())))(())((()))))(((((((()()()())(()))(()()((()())()((()((()()()(()(()()))(()())(())(((((()(((((((((((()((()(((()(((((((()()((((((()(((((()(()((()(((((())((((((()))((((())((()()((())(((())()(((((()()(((((()((()(()(((((((()(((((()((()((()((())(())((())(()))()()))(()()(()(()()(((((((()(((()(((())()(((((()((((((()())((((())()((()((()(()()())(()))((((()()((((((()((()(()(()((((()((()((())((((((()(()(())((((((()((((((((((()((())()))()(()(()(((((()()()))((())))()(()((((((((((((((()(((()((((()((())((()((()(((()()(()(((()((())(()()())))()(()(()(((((()()(()(()((((()(((((())()(()(()))(((((()()(((()()(())((((((((((((((())((())(((((((((((())()()()(())()(()(()(((((((((())(((()))(()()())(()((((()(())(((((()())(())((((((((())()((((()((((((())(()((()(())(((()((((()))(((((((((()()))((((()(())()()()(())(()((())((()()))()(((())(((((())((((((()()))(((((((((()((((((())))(((((((()((()(()(())))())(()(()))()(((((()())(()))()(()(())(((()))))())()())))(((((()))())()((()(()))))((()()()((((((()))()()((((((((())((()(()(((()(()((())((()())(()((((())(()(((()()()(()(()()))())())((((((((((())())((()))()((())(())(())))())()(()()(())))())(()))(((()(()()(((()(((())))()(((()(())()((((((())()))()))()((((((()(()(((((()())))()))))())()()(((()(((((())((()()(()((()((()(()(()(())))(()()()()((()(())(((()((()))((((()))())(())))())(()))()()()())()))(((()()())()((())))(())(()()()()(()())((()(()()((((())))((()((()(())((()(()((())()(()()(((()())()()())((()))((())(((()()(())))()()))(((()((())()(((((()())(())((())()())())((((((()(()(((((()))(()( \ No newline at end of file