aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
Diffstat (limited to '2024')
-rw-r--r--2024/10/.gitignore1
-rw-r--r--2024/10/Makefile1
-rw-r--r--2024/10/input52
-rw-r--r--2024/10/puzzles.lisp42
4 files changed, 96 insertions, 0 deletions
diff --git a/2024/10/.gitignore b/2024/10/.gitignore
new file mode 100644
index 0000000..5fcaefb
--- /dev/null
+++ b/2024/10/.gitignore
@@ -0,0 +1 @@
+puzzle-[12].lisp \ No newline at end of file
diff --git a/2024/10/Makefile b/2024/10/Makefile
new file mode 100644
index 0000000..5a21270
--- /dev/null
+++ b/2024/10/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/lisp.mk \ No newline at end of file
diff --git a/2024/10/input b/2024/10/input
new file mode 100644
index 0000000..507eadb
--- /dev/null
+++ b/2024/10/input
@@ -0,0 +1,52 @@
+5678543238765121087216787432128921016563210454323433
+4169654119654037892107894549017430457654782369412812
+3018767001843246543210787678186543368945691078908903
+2189678914980158934345698187098901275632100165001894
+3434589125678767891016521096167872984789321874112765
+7823678034569876780123434545252766543215476903233456
+6910167012423495679654321032341057630306985012945101
+5401986543410584508765678211352348921437894123876298
+4323877892543673210104569300235496530890123434565387
+3210967871652598789213075410145687432765210123432456
+0101454960701659654322186703456710101854321076501201
+1012343459898741023763099812769823478923212987655652
+4323012321101232212854210129876012569012503234234743
+5011001410765540101940110238787112876503414105109892
+6722340543894691001233221045698108976434565696589321
+9821059652023782317874536789587012885325676787678780
+9778968701110678498965945893496543494018989801210690
+8769878889231589567767893672109824323561234892309541
+1454399998342490430850104589678012012370348763458032
+0141287107654321521943213212565503123987659654567123
+1230236256565410101237870101419654598543210508948910
+2340145348978321253210965432308765687696501417654323
+3986501567899010344789876323219454766787432321078890
+5677432450987432455670189410012349845696501434569701
+0548901321976501964563208231987210036723109621435652
+1239678100823457877854010145676210129814918730898543
+4310369234710165756905423210122305610905825623567678
+3423456765600874543814554761201456723876734514410569
+2102109894321984562323669854398556894985232305320438
+3076521003965433871234778034567647895894101476761023
+4585412312870122930129872129867634456783230585872310
+5694303456781211123123401256798521065656187694965432
+6783201019892100054076540346543438980521090123456501
+0340112387653456963981639457832523671439876101219602
+1258903490144327870190128768901214512112725614308712
+2569876589231016983278787434980108903003014525456893
+1876767676546781074349896523076587654394523496327854
+0945778789035690165234765014123496543487621087018969
+1239869876124789234105676543287017012567634589829678
+9018756765453210785411085010196528921298565676543549
+8723605034301305696532398923483437430143476589762138
+7634514125212154387783437654589016521052187679854023
+6501323896521093210598568943078723632367098512763210
+7432454787436789765677678732189654045458963403892001
+8901343474345658894389589823476902102167872354301123
+7623676543216743001210438214567813458054961065689054
+5012389012109812123309321301054324569123452876548765
+4589438729001901014578010102344567078212556989231076
+3676567438782342145665430230133898167901665476102989
+2109652145699654398765421321212101237810174345603478
+1078743034328765219876323478903894376521089298714565
+2167634145410898701101210569816765489432100107623434 \ No newline at end of file
diff --git a/2024/10/puzzles.lisp b/2024/10/puzzles.lisp
new file mode 100644
index 0000000..696bb25
--- /dev/null
+++ b/2024/10/puzzles.lisp
@@ -0,0 +1,42 @@
+#!/usr/bin/sbcl --script
+
+
+(defun main (filename)
+ (let ((lines (read-file-to-lines filename)))
+ (loop with dimensions = (array-dimensions lines)
+ for i from 0 below (first dimensions)
+ summing (loop for j from 0 below (second dimensions)
+ when (char= #\0 (aref lines i j))
+ summing (score-for-trail-head lines i j)))))
+
+(defun read-file-to-lines (filename)
+ (with-open-file (stream filename)
+ (let ((lines (loop for line = (read-line stream nil)
+ while line
+ collect (coerce line 'array))))
+ (make-array (list (length lines)
+ (length (first lines)))
+ :initial-contents lines))))
+
+(defun score-for-trail-head (lines i j)
+ (let* ((positions (positions-of-nines lines i j))
+ ;; START PART 1
+ (positions (remove-duplicates positions :test 'equal))
+ ;; END PART 1
+ )
+ (length positions)))
+
+(defun positions-of-nines (lines i j)
+ (let ((char (aref lines i j)))
+ (if (char= #\9 char)
+ (list (cons i j))
+ (loop with needs = (code-char (1+ (char-code char)))
+ with dimensions = (array-dimensions lines)
+ for (i . j) in (list (cons (1- i) j) (cons i (1- j))
+ (cons (1+ i) j) (cons i (1+ j)))
+ when (and (< -1 i (first dimensions))
+ (< -1 j (second dimensions))
+ (char= (aref lines i j) needs))
+ append (positions-of-nines lines i j)))))
+
+(format t "~a~%" (main "input")) \ No newline at end of file