aoc3-1
This commit is contained in:
parent
919c46d25e
commit
f5d075e328
6 changed files with 739 additions and 0 deletions
204
src/aoc3.lisp
Normal file
204
src/aoc3.lisp
Normal file
|
|
@ -0,0 +1,204 @@
|
||||||
|
;; #!/bin/sbcl --script
|
||||||
|
(defun is-symbol (subject)
|
||||||
|
(and (not(digit-char-p subject)) (not(char= #\. subject)))
|
||||||
|
)
|
||||||
|
|
||||||
|
(with-open-file (file "aoc3input.txt")
|
||||||
|
(let((result 0) (previousLine "") (currentLine "") (parsingNumber nil) (validNumber nil) (currentNumber "") (lineLen 0) (partialNumberPos '()))
|
||||||
|
|
||||||
|
(loop for line = (read-line file nil)
|
||||||
|
while line do
|
||||||
|
(setf currentLine line)
|
||||||
|
(if(string= previousLine "")
|
||||||
|
(progn
|
||||||
|
;(setf previousLine line)
|
||||||
|
(setf lineLen (length line)) )
|
||||||
|
(progn
|
||||||
|
;(print currentNumber)
|
||||||
|
(setf currentLine line)
|
||||||
|
(format T "~%")
|
||||||
|
(print previousLine)
|
||||||
|
(print currentLine)
|
||||||
|
(loop for c across previousLine
|
||||||
|
with currentIdx = 0
|
||||||
|
do
|
||||||
|
(cond ((digit-char-p c) (progn
|
||||||
|
;USEFUL (format T "~%~a ~d" "A digit! In: " currentIdx)
|
||||||
|
(if (not parsingNumber) (setf parsingNumber t))
|
||||||
|
(setf currentNumber (format nil "~a~c" currentNumber c))
|
||||||
|
;(print "currentNumber expanded")
|
||||||
|
(dolist (item (mapcar #'is-symbol (list (char currentLine currentIdx)
|
||||||
|
(if(zerop currentIdx) #\. (char currentLine (- currentIdx 1)))
|
||||||
|
(if(zerop currentIdx) #\. (char previousLine (- currentIdx 1)))
|
||||||
|
) ))
|
||||||
|
(when item (setf validNumber t))
|
||||||
|
)
|
||||||
|
|
||||||
|
;(print "Number ended")
|
||||||
|
))
|
||||||
|
((not(char= c #\.)) (progn
|
||||||
|
;USEFUL (format T "~%~a ~d" "A symbol! In: " currentIdx)
|
||||||
|
(if parsingNumber
|
||||||
|
(progn
|
||||||
|
(format T "~%~a ~a" "Insert left: " currentNumber)
|
||||||
|
(setf parsingNumber nil) (setf validNumber nil)
|
||||||
|
;USEFUL(format T "~%~a ~a" "Previous result: " result)
|
||||||
|
(setf result (+ result (parse-integer currentNumber)))
|
||||||
|
(format T " ~a ~a" "Result added:" result)
|
||||||
|
(setf currentNumber "")
|
||||||
|
))
|
||||||
|
;;TODO
|
||||||
|
(let((wasPreviousMatch nil) (checkIdx (- currentIdx (if(equal currentIdx lineLen) 0 1))) )
|
||||||
|
(loop while (<= checkIdx (+ currentIdx (if(equal (+ currentIdx 1) lineLen) 0 1)))
|
||||||
|
do
|
||||||
|
;USEFUL(format T "~%~a" "We do be checkin' under")
|
||||||
|
(if(digit-char-p(char currentLine checkIdx))
|
||||||
|
(progn
|
||||||
|
;USEFUL(format T "~%~a" "Sumthn' was under!")
|
||||||
|
(if(not wasPreviousMatch)
|
||||||
|
(progn
|
||||||
|
(push checkIdx partialNumberPos)
|
||||||
|
(setf wasPreviousMatch t) )
|
||||||
|
))
|
||||||
|
|
||||||
|
(if wasPreviousMatch (setf wasPreviousMatch nil))
|
||||||
|
|
||||||
|
)
|
||||||
|
(incf checkIdx))) ))
|
||||||
|
(t (progn
|
||||||
|
;USEFUL(format T "~%~a ~d-~d" "A dot! In: " currentIdx currentNumber)
|
||||||
|
(if(and parsingNumber (is-symbol (char currentLine currentIdx)) )
|
||||||
|
(progn
|
||||||
|
;USEFUL(format T "~%~a" "Under point, there was a symbol! ")
|
||||||
|
(setf validNumber t))
|
||||||
|
)
|
||||||
|
|
||||||
|
(if (and parsingNumber validNumber)
|
||||||
|
(progn
|
||||||
|
(format T "~%~a ~d" "Dot insert..." currentNumber)
|
||||||
|
(setf parsingNumber nil) (setf validNumber nil)
|
||||||
|
(setf result (+ result (parse-integer currentNumber)))
|
||||||
|
(format T " ~a~d" "Result added: " result)))
|
||||||
|
;USEFUL(if(not(string= "" currentNumber)) (format T "~%~a ~a" "Number discarded:" currentNumber)))
|
||||||
|
(setf currentNumber "") (setf parsingNumber nil) (setf validNumber nil)
|
||||||
|
)) )
|
||||||
|
(incf currentIdx)
|
||||||
|
finally
|
||||||
|
;Numbers in currentLine marked by Symbol in previousLine
|
||||||
|
(if(and parsingNumber validNumber)
|
||||||
|
(progn
|
||||||
|
(format T "~%~a ~d" "Number ending line..." currentNumber)
|
||||||
|
(setf parsingNumber nil) (setf validNumber nil)
|
||||||
|
(setf result (+ result (parse-integer currentNumber)))
|
||||||
|
(format T " ~a~d" "Result added: " result)))
|
||||||
|
(setf currentNumber "") (setf parsingNumber nil) (setf validNumber nil)
|
||||||
|
(format T "~%~a" "Parsing under.")
|
||||||
|
(dolist (item partialNumberPos)
|
||||||
|
(let((tempPos (- item 1)) (cnt t) )
|
||||||
|
(loop while cnt
|
||||||
|
do
|
||||||
|
;(print (char currentLine tempPos))
|
||||||
|
(if (digit-char-p(char currentLine tempPos))
|
||||||
|
(progn
|
||||||
|
(setf currentNumber (format nil "~c~a" (char currentLine tempPos) currentNumber))
|
||||||
|
(if(equal 0 tempPos) (setf cnt nil) (decf tempPos) ) )
|
||||||
|
(setf cnt nil)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(setf cnt t) (setf tempPos item)
|
||||||
|
(loop while cnt
|
||||||
|
do
|
||||||
|
(if (digit-char-p (char currentLine tempPos))
|
||||||
|
(progn
|
||||||
|
(setf currentNumber (format nil "~a~c" currentNumber (char currentLine tempPos) ))
|
||||||
|
(if(equal lineLen (+ tempPos 1)) (setf cnt nil) (incf tempPos) ) )
|
||||||
|
(setf cnt nil)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(format T "~%~a ~a" "Under number:" currentNumber)
|
||||||
|
;USEFUL(format T "~%~a ~a" "Previous value: " result)
|
||||||
|
(if(not(string= "" currentNumber)) (setf result (+ result (parse-integer currentNumber))) )
|
||||||
|
(format T " ~a~d" "Result added: " result)
|
||||||
|
(setf currentNumber "")
|
||||||
|
(setf partialNumberPos '())
|
||||||
|
))
|
||||||
|
)))
|
||||||
|
(setf previousLine currentLine))
|
||||||
|
(print result)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
;; (with-open-file (file "aoc4input.txt")
|
||||||
|
;; (let((result 0) (playerNumbersLen 0) (repetitions '())
|
||||||
|
;; (lineLen 0) (manipulatedLine "") (winnerLine "") (playerLine "") (currentNumber "") (playerNumbers '()))
|
||||||
|
;; (loop for line = (read-line file nil)
|
||||||
|
;; while line do
|
||||||
|
;; (setf lineLen (length line))
|
||||||
|
;; (setf manipulatedLine (subseq line (+ 2 (position #\: line :test #'equalp)) lineLen ))
|
||||||
|
;; (setf winnerLine (subseq manipulatedLine 0 (- (position #\| manipulatedLine :test #'equalp) 1)) )
|
||||||
|
;; (setf playerLine (subseq manipulatedLine (+ 2 (position #\| manipulatedLine :test #'equalp)) (length manipulatedLine) ))
|
||||||
|
;; (print winnerLine)
|
||||||
|
;; ;;(print manipulatedLine)
|
||||||
|
;; (print playerLine)
|
||||||
|
;; (loop for c across playerLine
|
||||||
|
;; with currentIdx = 0
|
||||||
|
;; do
|
||||||
|
;; (if(not(char= c #\Space))
|
||||||
|
;; (progn
|
||||||
|
;; (setf currentNumber (format nil "~a~c" currentNumber c))
|
||||||
|
;; (if(equal (+ currentIdx 1) (length playerLine))
|
||||||
|
;; (progn
|
||||||
|
;; (push (parse-integer(format nil "~%~a" currentNumber)) playerNumbers )
|
||||||
|
;; (setf currentNumber ""))))
|
||||||
|
;; (progn
|
||||||
|
;; ;;(format T "~%~d|~d" (+ currentIdx 1) (length playerLine))
|
||||||
|
;; (if(not(string= currentNumber ""))
|
||||||
|
;; (progn
|
||||||
|
;; (push (parse-integer(format nil "~%~a" currentNumber)) playerNumbers )
|
||||||
|
;; (setf currentNumber "")))))
|
||||||
|
;; (incf currentIdx))
|
||||||
|
;; (format T "~%~a ~a" "playerNumbersLen:" playerNumbersLen)
|
||||||
|
;; (if(equal 0 playerNumbersLen)
|
||||||
|
;; (progn
|
||||||
|
;; (setf playerNumbersLen (list-length playerNumbers))
|
||||||
|
;; (loop with idx = 0
|
||||||
|
;; while (< idx playerNumbersLen)
|
||||||
|
;; do
|
||||||
|
;; (push 1 repetitions)
|
||||||
|
;; (incf idx))
|
||||||
|
;; (print repetitions)))
|
||||||
|
;; (let((numOfInstances 0) (nextToClone 0))
|
||||||
|
;; (setf numOfInstances (first repetitions))
|
||||||
|
;; (setf result (+ result numOfInstances))
|
||||||
|
;; ;;(format T "~%~a ~a" "Number of cards won:" result)
|
||||||
|
;; (pop repetitions)
|
||||||
|
;; (setf repetitions (append repetitions '(1)))
|
||||||
|
;; (print repetitions)
|
||||||
|
;; (loop for c across winnerLine
|
||||||
|
;; with currentIdx = 0
|
||||||
|
;; do
|
||||||
|
;; (if(not(char= c #\Space))
|
||||||
|
;; (progn
|
||||||
|
;; (setf currentNumber (format nil "~a~c" currentNumber c))
|
||||||
|
;; (if(equal (+ currentIdx 1) (length winnerLine))
|
||||||
|
;; (progn
|
||||||
|
;; (dolist (item playerNumbers)
|
||||||
|
;; (if (equal (parse-integer currentNumber) item)
|
||||||
|
;; (progn
|
||||||
|
;; (setf (nth nextToClone repetitions) (+ (nth nextToClone repetitions) numOfInstances))
|
||||||
|
;; (incf nextToClone)
|
||||||
|
;; (print nextToClone))))
|
||||||
|
;; (setf currentNumber ""))))
|
||||||
|
;; (progn
|
||||||
|
;; (if(not(string= currentNumber ""))
|
||||||
|
;; (progn
|
||||||
|
;; (dolist (item playerNumbers)
|
||||||
|
;; (if (equal (parse-integer currentNumber) item)
|
||||||
|
;; (progn
|
||||||
|
;; (setf (nth nextToClone repetitions) (+ (nth nextToClone repetitions) numOfInstances))
|
||||||
|
;; (incf nextToClone)
|
||||||
|
;; (print nextToClone))))
|
||||||
|
;; (setf currentNumber "")))))
|
||||||
|
;; (incf currentIdx)))
|
||||||
|
;; (setf playerNumbers '())
|
||||||
|
;; (format T "~%~a ~a" "Number of cards won:" result))))
|
||||||
140
src/aoc3input.txt
Normal file
140
src/aoc3input.txt
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
.........798...145.........629....579.....455.....................130.............243.................154........167........................
|
||||||
|
............*.....*...........*...&...179.*........737...194.........*854........./...........52..560*............................699...&...
|
||||||
|
........459..489.817........880.........*..996........*....*........................................................................*.36....
|
||||||
|
...........@.........................813............234.552..307....184............370..................736.....960..............631........
|
||||||
|
...100...................*...............131..................*........=......435..*......34...........*....................................
|
||||||
|
......+....#126.......214..........$......*.....+.............939................/..729..............861.....243..........438...............
|
||||||
|
...................................854....979....177.......%.........280..138................158*241............*..........*....*904...#....
|
||||||
|
.......427............................................683&.726...303........*.......905.......................&..115.....412.479.....491....
|
||||||
|
.....=.*...........989......888.....................$............../.226....922.172....*..702*693...........543.............................
|
||||||
|
..924..219...........*.....*........979............191.%.........+..............*.....323....................................777............
|
||||||
|
....................109........................559.....835.....708........989..685................................#.............=.915.......
|
||||||
|
........................................*........=.........751........886................243.......154+..922...347................/.........
|
||||||
|
......923...............571.....@.672....963.471.......154...*.........*.....................914...........*.............891.........73*212.
|
||||||
|
.........*......654+....&....309...=.........*....543.........583....871.....*........................551...370...$......*...492............
|
||||||
|
..618*....60.........................426...&.645....*....................203..310....$...........@166...........477...@.......%......150*...
|
||||||
|
......353......381..........416.....*....19......536......#..312..../790.*............779..$.........../............985..................761
|
||||||
|
...........#............636..*....238...................576.....*........899................460.841..829.415...271*.......168.77....=.......
|
||||||
|
..........427............$.......................................75..............789...942........-......*.........795......*.......73......
|
||||||
|
....863................%.......920..........*152.....852*387.........990.....563..*.....*...629........772....912............283............
|
||||||
|
837*.......897.......674...966....&.%621..77..................................&..571...272.........566.....16*.....936.....&......980.......
|
||||||
|
..............*............*....-.........................*..............424#...................53.*......................203...............
|
||||||
|
...826.781.....105......&...771.982............967......40.223.....................71............*..123.........-...@....................998
|
||||||
|
...$................64.562.............../382....*.................866-....276.....*........750.975...........878..156..........188.........
|
||||||
|
...........38+..............937...................142.........*712........$.....619..*734............424..................=.................
|
||||||
|
....746...................@....+..868..-......881...........................+.........................*.......832.../....649...-.......181..
|
||||||
|
...*.......+637...478....628......%.....651....................../.....399%..396.............&..293.472..........*.960..........988....*....
|
||||||
|
....693..........$..................-.......711.99.489.878....541...........................565..#.........32..710......499............888..
|
||||||
|
....................681.59.442.....368.%.........*.......&..........................974............*........%...............................
|
||||||
|
677....924......797.......*............964......666.................89......309.......*.........324.179..........437.......235.321...678....
|
||||||
|
............+..........$......5...............$......./......23..............$.........328..564.........392......*............*........*....
|
||||||
|
...298......811.........976..*.................400...140....*.......893................................*....%.682.....345.............726...
|
||||||
|
..............................570.839......................828.....*......-......59....373.......%...558..271...........*......*751.........
|
||||||
|
.....570...........353*674........#....636........659..............647.....226..*.......+......684...............139...290..401........290..
|
||||||
|
........&..................231...............80..........@112....................892......605...............247...+................$...*....
|
||||||
|
165........*329..94*254..........115...............938.................192...............*......$58.............@......786.....328..59..285.
|
||||||
|
.........98........................$.....895......*...............459..*...............399..641..................285...$..........*.........
|
||||||
|
.............../..455*429............794*.....................512.*....770.....448...........@...................................336.175....
|
||||||
|
......#......277................................763............*..254.....................*....143...495..$.......676...................#...
|
||||||
|
.......272.........-..................711..911...*.....614..516............747.389.....803........%.....*.832.......*....905....576..#......
|
||||||
|
625.................595......989...............291.....*................*.....*............$..201.............528.722....%.....*......896...
|
||||||
|
....342............................................569..486.......@..278.184.........259..107................%.................749..........
|
||||||
|
...#..................851.......16..436*910.......@..............338...........989...*..........+.367.867............=..918.................
|
||||||
|
.................106..#.........@...........................@.....................-...99......38....%....*.18&....550..*..........250.......
|
||||||
|
..................+.........................&732....53....258....850..................................306.............539....@..............
|
||||||
|
658*869..............684*636....422.686............*...............*...955..............*......................../...........313.....$......
|
||||||
|
.............604.............................954....357.........458..................168.310.......698............435......%......394.......
|
||||||
|
.....109....*.........163...........962$.....@..........=..................876*........................230..125...........24..972.....641...
|
||||||
|
......*...312..........#........................*914....740....466*............374.............+......%....*...........46....*.....60.......
|
||||||
|
...422............804......$.@......%........589...................500..958.............21..301...........889............*..717.............
|
||||||
|
..........474..=.....*...302.475.155.............665..800..46..............=...................................19......902........936...887.
|
||||||
|
............*.754...831...............8@.@............................110.....554..........732...=913.........*.....$............*..........
|
||||||
|
456......211.................562.........183........................@......+..*.....839...............@...500.739..962.....105...528..-.....
|
||||||
|
...............794.882.......+.....@..........833............595....704.693......=...*..............81...*.............571*............727..
|
||||||
|
......590.30......*.................872...@...................................773.....156......&346......807.813.285+.........380...........
|
||||||
|
........$..*...........*621.....528.....835.....556.......*85...516-.......................28.........*......-..........791$.....%..........
|
||||||
|
....................965.....507.*.............*....*...377.............957................@....835.707.409.....987*...........=.......729...
|
||||||
|
.....503......471..........*....267..169....200.369..........499..#...*....................................161.....464.....794.....*...#....
|
||||||
|
........$.......*..........808......*....&..........643.....*....39....354......159........117@...308....-...*.........144.........452......
|
||||||
|
..........$......910...........195..952..320.........*......832.................*...296.............*..860..401.........%....157/...........
|
||||||
|
.......438..721................@..............89..144..332........987.........979..*.....%.........824............709................710....
|
||||||
|
...209.......-........../............=952..............*.............*292.........582.661.....$........815.............857....254....*......
|
||||||
|
....&..218%..........100................................74....................*................692.-.......545...................*..........
|
||||||
|
.............297..........101....276.756..............#....462......492*578..636......=............860..........................399.........
|
||||||
|
........171..............=........#..*...............407...%.......................331..915..............................919................
|
||||||
|
....454*...................*83......100..702..............................271...........@...........59....582.../........*...........+......
|
||||||
|
..............185*......687...........................186............739-...=......*.................+....*.....380..539..192.80......455...
|
||||||
|
.......174........686.........562...958......192.......*..117...108.............567.298.................545...........*...........$.........
|
||||||
|
.....$.....887........131..........-....955...*.....504...........%.243..281........................877.............610......216..130...-...
|
||||||
|
.....646....*......76....................%..50.......................*.......541.......782.....752+....*......296*.......523...@......881...
|
||||||
|
............802....*........976.................223*478........96...785.142.*......530....*721.........577........317.......*.....295.......
|
||||||
|
....412.114........561...#....+............................52....*......*....999......*./....................................221.....*40....
|
||||||
|
......*./......*.........435..........168..779....-..........*.272.....372.........652...489........*988.......810..........................
|
||||||
|
80.110.......137....938...........924....#.+...896........305....................................885...........................831..........
|
||||||
|
........&...............792.........................................773*100.958..&78.....*..............902....286................+.........
|
||||||
|
........873..............&...........585..................127*899..............*.......60.982...........$......@....268..370.............567
|
||||||
|
............781...*...........*174...*...............................26........203.652................................*............538......
|
||||||
|
.............$.....534.....848......170......418........494/....298...*....792......./.......%......+687..............179............@.160..
|
||||||
|
..474...711....................417.................................@.458....$..........*338..719............509..488......781.982...........
|
||||||
|
.....*..........235.................622............$...804+..............*......577.870.............&..43.....&..-.............*.....278....
|
||||||
|
....696.222.604.*.......*29...........$.....&....755...........55.....631.202.....................443....*....................692...*.......
|
||||||
|
...........*....55...456.....782..422.......133......844........*..........................286-...........865.89..27...718........317.......
|
||||||
|
.......611.....................-...*..995........712..*..........89...............@166..............771............*.....*..............589.
|
||||||
|
...........417.....150..678...........*.............$.417..298.............611&..........811.327......*..$...610%.614.....443......-...*....
|
||||||
|
.......658*..........-...*.......622..940.............................&....................*../..773.194.479..........996.........263..872..
|
||||||
|
....90......%550.587......215.......*.......322.....229......841*....996...........826....305......@.........#405.....$.....................
|
||||||
|
......*...........*..................671....*......*.............695.......694....+..............................................223.462.826
|
||||||
|
..419.832.......271...828................228.................380........21*..........644............725....703......255..330........*.......
|
||||||
|
.....................*.............................357.................................*........360...+.....#..%173...*..../../.............
|
||||||
|
..................182...........88.664*......865..*................................428.................................143...829.552.....829
|
||||||
|
...&..................425..894...*.....792...*.....321..219................=...564....*..166....%....+.....764...................*......=...
|
||||||
|
..619.....529..384.....*......*...693.........188......-............281.238......=.339....*...124...278.....+....490.....481....416.........
|
||||||
|
.................*.442..76....801.....376.................+511.......*......*.............967.......................*.68*............919....
|
||||||
|
...731..484....875..#....................*243...681.................135..191.162.688%.........29.....*............688..........437......*...
|
||||||
|
.....%.=........................329*87.............*138.-949..186.................................595.554...............755....*.....454....
|
||||||
|
............341..302.........&...........330.....................@.......................779..............353......@.......*..535...........
|
||||||
|
.....766.....*..*..........315......856.*................540..............136............*.......914..162*.......7..336..383............642.
|
||||||
|
......../..253...502................*...990.....299.......+...413............*..........338.......%.............................294*........
|
||||||
|
.....&..................636.986.431.345...............693.......*.......*...............................276..........836@.278.......716..469
|
||||||
|
.....247........*.905*....$..*...*.......................$.....502...177.........72=......$...232......*................................*...
|
||||||
|
.........674.905......664...124............*127.............................564........924.....*.....&.616...661..403....10.........429.724.
|
||||||
|
........../..............................78..............#5..................*................498..650..........*.......*............*......
|
||||||
|
.....348....*.........488...........414..........................962...552...107...@...533......................109....432....*......423....
|
||||||
|
....*.......536................283....&......800.............&.......+..../........677.$..................32...............410.392..........
|
||||||
|
....826.............755........*........396..*......../.......771.....837........=.............577.................53...............314.....
|
||||||
|
.........@....109$...*..........988........$..241..750.............@............169...162......*...%....575.743......*..................278.
|
||||||
|
..........862........227....585........158.............262.....51..151..................*..509...31............*..........+....144.481.&....
|
||||||
|
........*........467........*.........#..../..........*......................%....973..218..*..........@.......543......678.......*.........
|
||||||
|
......32.106...$...*......260...........425.........912.................383..392.*...........503....546..212........%......./442.....221....
|
||||||
|
..............668...593............422.......966*37................503..*.........776.....5$..............*......833.................&......
|
||||||
|
............-...................21....*.-497............................133...........862......241.............-..........824...............
|
||||||
|
.........215.......................851.........-........932........@./.......-.......-....%..................597..........*........@........
|
||||||
|
................*323....557....782..........964...14..$....$.....631.144.....588.........316......................252..396........257...957.
|
||||||
|
.............367........*......*.....64.97........=..976.....245................../982..........135...169........*.....................=....
|
||||||
|
....513..........96.101..359.212.585..............................965*287.803.501.........460.........*.........618....98.208...............
|
||||||
|
.............802*...+............#..............804..123...579*..............*.............*.......282.....263...........*..................
|
||||||
|
.707....522....................................*........@......106..143.........716......770...........576*......................497........
|
||||||
|
......#.../...=.........835............545*610.462..188............*.............*.....$...............................*115......*....*.....
|
||||||
|
928%.606.......207.......*......61..........................797.....228..357....484..492..........247...............574..........880.994....
|
||||||
|
...........541...........444......@....122......................505......+...14..........534........*.....210...........150.948..........210
|
||||||
|
..............*..676*765...............*.....295.156...601#....*......-.......*.....709..........901.....*........714......*............&...
|
||||||
|
.......723...299................325...965...........*.........656......156....824...../..............840.383...........249..........=.......
|
||||||
|
..................................#........26*781.456................#.....................745......*.............165.*..........278..452...
|
||||||
|
.746..............953.943.............................877.....59......128............#....+......585......641....%.....229...*2........*....
|
||||||
|
...*.......614=......*.......903.............433.370...=...54....+..............&.....336.....$.............*..........................856..
|
||||||
|
698...272.....................%......545.....-....$.............223.183..........339........189............994.......531.815*206............
|
||||||
|
........./................657...........#...............571............=..-832.+....................876..............................754....
|
||||||
|
.....&.....*960....628.............597.............747$.*......776..+..........709..................*..........266..........225.....*.......
|
||||||
|
...541..511.............353.......*......................649.....*..753...719......212..526=...578..634..........*..........*......113......
|
||||||
|
................996=...*...........18........#628..............321........*.......*...........*...................194....334.............126
|
||||||
|
......................627..693.........248..........290.................@..204..=..247...574..311......791....................679*..........
|
||||||
|
.......@....................=......283*............*.............38..214........90.........*.......447...+.............77...%.....265.......
|
||||||
|
......566......&.................*..........965...929...........*......................869.908.753..$.......437....848*.....943.............
|
||||||
|
...........403.950..............439............*............340.419...........868.....*...........*...128.....&.....................869.....
|
||||||
|
............*..........637...............256.793........436*....................*.....85.361.....280..................349...................
|
||||||
|
.........654...........*..............=.-........949............=....224..506.631....................*21.@...........%......................
|
||||||
|
.............#..44.......105.108...190..........*....$173......750....*...../.........37.......-..461.....727...75.......................893
|
||||||
|
......@...583.....*........*................358...........750........................*......532..................*...22...../....512...#....
|
||||||
|
863...112................178...+...........*...........5./............98......584..222..........862...235.....448...*.....737.....*.....516.
|
||||||
|
....#.......425..............923.84*......947......999*..............*....280*...........732...&.....*.............14.............683.......
|
||||||
|
.....353............................914........105.................829...........112...............75.......................................
|
||||||
10
src/aoc3test.txt
Normal file
10
src/aoc3test.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
467..114..
|
||||||
|
...*......
|
||||||
|
..35..633.
|
||||||
|
......#...
|
||||||
|
617*......
|
||||||
|
.....+.58.
|
||||||
|
..592.....
|
||||||
|
......755.
|
||||||
|
...$.*....
|
||||||
|
.664.598..
|
||||||
75
src/aoc5.lisp
Normal file
75
src/aoc5.lisp
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
;; #!/bin/sbcl --script
|
||||||
|
(with-open-file (file "aoc4input.txt")
|
||||||
|
(let((result 0) (playerNumbersLen 0) (repetitions '())
|
||||||
|
(lineLen 0) (manipulatedLine "") (winnerLine "") (playerLine "") (currentNumber "") (playerNumbers '()))
|
||||||
|
(loop for line = (read-line file nil)
|
||||||
|
while line do
|
||||||
|
(setf lineLen (length line))
|
||||||
|
(setf manipulatedLine (subseq line (+ 2 (position #\: line :test #'equalp)) lineLen ))
|
||||||
|
(setf winnerLine (subseq manipulatedLine 0 (- (position #\| manipulatedLine :test #'equalp) 1)) )
|
||||||
|
(setf playerLine (subseq manipulatedLine (+ 2 (position #\| manipulatedLine :test #'equalp)) (length manipulatedLine) ))
|
||||||
|
(print winnerLine)
|
||||||
|
;;(print manipulatedLine)
|
||||||
|
(print playerLine)
|
||||||
|
(loop for c across playerLine
|
||||||
|
with currentIdx = 0
|
||||||
|
do
|
||||||
|
(if(not(char= c #\Space))
|
||||||
|
(progn
|
||||||
|
(setf currentNumber (format nil "~a~c" currentNumber c))
|
||||||
|
(if(equal (+ currentIdx 1) (length playerLine))
|
||||||
|
(progn
|
||||||
|
(push (parse-integer(format nil "~%~a" currentNumber)) playerNumbers )
|
||||||
|
(setf currentNumber ""))))
|
||||||
|
(progn
|
||||||
|
;;(format T "~%~d|~d" (+ currentIdx 1) (length playerLine))
|
||||||
|
(if(not(string= currentNumber ""))
|
||||||
|
(progn
|
||||||
|
(push (parse-integer(format nil "~%~a" currentNumber)) playerNumbers )
|
||||||
|
(setf currentNumber "")))))
|
||||||
|
(incf currentIdx))
|
||||||
|
(format T "~%~a ~a" "playerNumbersLen:" playerNumbersLen)
|
||||||
|
(if(equal 0 playerNumbersLen)
|
||||||
|
(progn
|
||||||
|
(setf playerNumbersLen (list-length playerNumbers))
|
||||||
|
(loop with idx = 0
|
||||||
|
while (< idx playerNumbersLen)
|
||||||
|
do
|
||||||
|
(push 1 repetitions)
|
||||||
|
(incf idx))
|
||||||
|
(print repetitions)))
|
||||||
|
(let((numOfInstances 0) (nextToClone 0))
|
||||||
|
(setf numOfInstances (first repetitions))
|
||||||
|
(setf result (+ result numOfInstances))
|
||||||
|
;;(format T "~%~a ~a" "Number of cards won:" result)
|
||||||
|
(pop repetitions)
|
||||||
|
(setf repetitions (append repetitions '(1)))
|
||||||
|
(print repetitions)
|
||||||
|
(loop for c across winnerLine
|
||||||
|
with currentIdx = 0
|
||||||
|
do
|
||||||
|
(if(not(char= c #\Space))
|
||||||
|
(progn
|
||||||
|
(setf currentNumber (format nil "~a~c" currentNumber c))
|
||||||
|
(if(equal (+ currentIdx 1) (length winnerLine))
|
||||||
|
(progn
|
||||||
|
(dolist (item playerNumbers)
|
||||||
|
(if (equal (parse-integer currentNumber) item)
|
||||||
|
(progn
|
||||||
|
(setf (nth nextToClone repetitions) (+ (nth nextToClone repetitions) numOfInstances))
|
||||||
|
(incf nextToClone)
|
||||||
|
(print nextToClone))))
|
||||||
|
(setf currentNumber ""))))
|
||||||
|
(progn
|
||||||
|
(if(not(string= currentNumber ""))
|
||||||
|
(progn
|
||||||
|
(dolist (item playerNumbers)
|
||||||
|
(if (equal (parse-integer currentNumber) item)
|
||||||
|
(progn
|
||||||
|
(setf (nth nextToClone repetitions) (+ (nth nextToClone repetitions) numOfInstances))
|
||||||
|
(incf nextToClone)
|
||||||
|
(print nextToClone))))
|
||||||
|
(setf currentNumber "")))))
|
||||||
|
(incf currentIdx)))
|
||||||
|
(setf playerNumbers '())
|
||||||
|
(format T "~%~a ~a" "Number of cards won:" result))))
|
||||||
277
src/aoc5input.txt
Normal file
277
src/aoc5input.txt
Normal file
|
|
@ -0,0 +1,277 @@
|
||||||
|
seeds: 858905075 56936593 947763189 267019426 206349064 252409474 660226451 92561087 752930744 24162055 75704321 63600948 3866217991 323477533 3356941271 54368890 1755537789 475537300 1327269841 427659734
|
||||||
|
|
||||||
|
seed-to-soil map:
|
||||||
|
155461856 2688731658 31130392
|
||||||
|
3624223750 2439220990 158522039
|
||||||
|
3782745789 828496007 83184667
|
||||||
|
1329508120 2383184162 2195641
|
||||||
|
1221066973 4005538912 108441147
|
||||||
|
3908459768 630332333 84015758
|
||||||
|
3174818941 2385379803 53841187
|
||||||
|
1929319035 442552891 126280229
|
||||||
|
2999332985 2077874265 61338040
|
||||||
|
4047976345 4113980059 50652162
|
||||||
|
3509978464 2319317936 63866226
|
||||||
|
2676242573 568833120 11879128
|
||||||
|
4146174193 3589840038 35847908
|
||||||
|
3865930456 2986517951 42529312
|
||||||
|
1737209176 3963710397 41828515
|
||||||
|
2545388005 3458985470 130854568
|
||||||
|
388171875 2946497456 40020495
|
||||||
|
3396281190 4164632221 79956015
|
||||||
|
186592248 1068698177 201579627
|
||||||
|
3060671025 714348091 114147916
|
||||||
|
2841183920 2139212305 158149065
|
||||||
|
2055599264 3290256747 27665085
|
||||||
|
2770917385 3029047263 24920289
|
||||||
|
4203978667 2597743029 90988629
|
||||||
|
2795837674 911680674 45346246
|
||||||
|
2083264349 2813972956 124101205
|
||||||
|
3573844690 4244588236 50379060
|
||||||
|
3228660128 274931829 167621062
|
||||||
|
1331703761 1270277804 23145153
|
||||||
|
123824510 3053967552 31637346
|
||||||
|
1354848914 63482157 211449672
|
||||||
|
1566298586 3085604898 170910590
|
||||||
|
63482157 3398643117 60342353
|
||||||
|
3476237205 3256515488 33741259
|
||||||
|
1212643678 2938074161 8423295
|
||||||
|
4182022101 2297361370 21956566
|
||||||
|
3992475526 2758472137 55500819
|
||||||
|
428192370 1293422957 784451308
|
||||||
|
1817647778 957026920 111671257
|
||||||
|
2690196100 3317921832 80721285
|
||||||
|
1779037691 2719862050 38610087
|
||||||
|
4098628507 582786647 47545686
|
||||||
|
2207365554 3625687946 338022451
|
||||||
|
2688121701 580712248 2074399
|
||||||
|
|
||||||
|
soil-to-fertilizer map:
|
||||||
|
2233530624 2071120505 422489795
|
||||||
|
3959649465 4044567411 67616189
|
||||||
|
457224864 3135270167 41569374
|
||||||
|
3394360972 4112183600 182783696
|
||||||
|
813178253 653702020 183734547
|
||||||
|
498794238 2963315974 171954193
|
||||||
|
3577144668 3394360972 216442995
|
||||||
|
996912800 2493610300 327275852
|
||||||
|
3309722439 3282071367 51304963
|
||||||
|
670748431 2820886152 142429822
|
||||||
|
1324188652 3273822993 8248374
|
||||||
|
3793587663 4006086952 11248169
|
||||||
|
2190085090 3176839541 43445534
|
||||||
|
2656020419 0 653702020
|
||||||
|
4267735006 4017335121 27232290
|
||||||
|
1396875915 3333376330 27651072
|
||||||
|
4027265654 3610803967 240469352
|
||||||
|
1424526987 1241123513 765558103
|
||||||
|
403686946 3220285075 53537918
|
||||||
|
3804835832 3851273319 154813633
|
||||||
|
1332437026 2006681616 64438889
|
||||||
|
0 837436567 403686946
|
||||||
|
|
||||||
|
fertilizer-to-water map:
|
||||||
|
490664090 841327865 158559818
|
||||||
|
3248785910 3009217852 86780947
|
||||||
|
3361383178 811709798 29618067
|
||||||
|
1492567300 999887683 10142868
|
||||||
|
708758546 1053715632 8318621
|
||||||
|
2922655819 2337575757 139997093
|
||||||
|
412870134 1010030551 43685081
|
||||||
|
825309561 1895146974 205741813
|
||||||
|
3832608203 4026085284 5525526
|
||||||
|
2833741007 722794986 88914812
|
||||||
|
1502710168 0 86876502
|
||||||
|
1091543314 2480502815 191523114
|
||||||
|
2191676162 1359275248 59328417
|
||||||
|
3724763033 3918240114 107845170
|
||||||
|
4132175069 4031610810 162792227
|
||||||
|
1589586670 3262683858 70888723
|
||||||
|
3932786977 4194403037 100564259
|
||||||
|
649223908 2280749089 56826668
|
||||||
|
717077167 268230878 108232394
|
||||||
|
4033351236 3819416281 98823833
|
||||||
|
2417689638 1418603665 416051369
|
||||||
|
3062652912 3333572581 186132998
|
||||||
|
1438604483 2100888787 28445966
|
||||||
|
398871700 1190738587 13998434
|
||||||
|
456555215 2975108977 34108875
|
||||||
|
2062848712 2151921639 128827450
|
||||||
|
1283066428 112692823 155538055
|
||||||
|
0 475753543 244333473
|
||||||
|
3838133729 3724763033 94653248
|
||||||
|
244333473 1204737021 154538227
|
||||||
|
1963558441 376463272 99290271
|
||||||
|
3335566857 86876502 25816321
|
||||||
|
3497674085 1062034253 22031494
|
||||||
|
706050576 720087016 2707970
|
||||||
|
1467050449 2129334753 22586886
|
||||||
|
1660475393 2672025929 303083048
|
||||||
|
3391001245 1084065747 106672840
|
||||||
|
1031051374 1834655034 60491940
|
||||||
|
1489637335 2477572850 2929965
|
||||||
|
2251004579 3095998799 166685059
|
||||||
|
|
||||||
|
water-to-light map:
|
||||||
|
2001282667 520918173 10302354
|
||||||
|
2377955968 3484205484 30954740
|
||||||
|
3394017453 2582587136 46684978
|
||||||
|
99573517 443623963 59355616
|
||||||
|
2759073879 2842283022 106219470
|
||||||
|
3153456782 2203695607 115107673
|
||||||
|
1088011149 228872916 37401521
|
||||||
|
823056142 1852553918 234443509
|
||||||
|
1892663777 1743935028 108618890
|
||||||
|
2223186841 3648924866 154769127
|
||||||
|
3440702431 3849149039 360654480
|
||||||
|
1125412670 266274437 146838028
|
||||||
|
2524006636 2432683670 149903466
|
||||||
|
86866324 508210980 12707193
|
||||||
|
3289576295 3621907778 27017088
|
||||||
|
659725308 531220527 163330834
|
||||||
|
336816212 1738401718 5533310
|
||||||
|
1057499651 413112465 30511498
|
||||||
|
1495475061 998625681 113056371
|
||||||
|
1277482099 1111682052 217992962
|
||||||
|
4022707650 2629272114 213010908
|
||||||
|
1611665062 1454269373 134219470
|
||||||
|
1272250698 502979579 5231401
|
||||||
|
3801356911 2996165168 221350739
|
||||||
|
2463542360 3803693993 45455046
|
||||||
|
3367828633 3458016664 26188820
|
||||||
|
3105794106 2948502492 47662676
|
||||||
|
0 1329675014 86866324
|
||||||
|
342349522 694551361 126187241
|
||||||
|
158929133 820738602 177887079
|
||||||
|
1608531432 1735268088 3133630
|
||||||
|
2673910102 4209803519 85163777
|
||||||
|
3316593383 2152460357 51235250
|
||||||
|
3268564455 2116439287 21011840
|
||||||
|
2508997406 2137451127 15009230
|
||||||
|
2011585021 153460510 75412406
|
||||||
|
1745884532 1588488843 146779245
|
||||||
|
621997273 1416541338 37728035
|
||||||
|
2865293349 3217515907 240500757
|
||||||
|
2408910708 2318803280 54631652
|
||||||
|
468536763 0 153460510
|
||||||
|
4235718558 2373434932 59248738
|
||||||
|
2116439287 3515160224 106747554
|
||||||
|
|
||||||
|
light-to-temperature map:
|
||||||
|
1588027222 1909294051 23480302
|
||||||
|
2215874455 2960213648 162391531
|
||||||
|
2129487527 3462600798 86386928
|
||||||
|
3484568571 1932774353 37497788
|
||||||
|
1911434001 1113198957 54894781
|
||||||
|
880849827 535842660 44062779
|
||||||
|
1450966888 2803663201 137060334
|
||||||
|
0 175732913 3492989
|
||||||
|
820881151 879323733 45588873
|
||||||
|
2593908227 3122605179 276522050
|
||||||
|
4086321665 3399127229 59629850
|
||||||
|
1267064668 2940723535 19490113
|
||||||
|
872717966 579905439 8131861
|
||||||
|
17372207 0 175732913
|
||||||
|
325280839 781495589 97828144
|
||||||
|
485661210 200622719 335219941
|
||||||
|
866470024 712695420 6247942
|
||||||
|
1113198957 1970272141 153865711
|
||||||
|
3384296082 2124137852 23097298
|
||||||
|
3492989 186743501 13879218
|
||||||
|
1966328782 1746135306 163158745
|
||||||
|
3522066359 3730711990 564255306
|
||||||
|
1611507524 2661100955 108644269
|
||||||
|
193105120 588037300 124658120
|
||||||
|
423108983 718943362 62552227
|
||||||
|
2870430277 2147235150 513865805
|
||||||
|
2559990250 2769745224 33917977
|
||||||
|
4145951515 1168093738 149015781
|
||||||
|
1720151793 1558696817 187438489
|
||||||
|
3407393380 1317109519 77175191
|
||||||
|
1286554781 1394284710 164412107
|
||||||
|
317763240 179225902 7517599
|
||||||
|
2378265986 3548987726 181724264
|
||||||
|
1907590282 3458757079 3843719
|
||||||
|
|
||||||
|
temperature-to-humidity map:
|
||||||
|
2368894659 1388350150 55368176
|
||||||
|
3669222180 3739392779 16773160
|
||||||
|
4199646729 3863166637 79873794
|
||||||
|
399562411 1508754364 89530529
|
||||||
|
355021451 346145384 44540960
|
||||||
|
3348191019 2804337123 32367820
|
||||||
|
4153047357 3630809755 46599372
|
||||||
|
801745354 3027789847 194064703
|
||||||
|
295043332 1932435496 59978119
|
||||||
|
2173824398 0 195070261
|
||||||
|
3586766138 3780710595 82456042
|
||||||
|
2063962300 390686344 109862098
|
||||||
|
2424813637 2262322190 16002572
|
||||||
|
694625758 2155376830 106945360
|
||||||
|
4279520523 3615362982 15446773
|
||||||
|
489092940 1655816946 66193390
|
||||||
|
0 3221854550 178998524
|
||||||
|
1882939638 1912164198 20271298
|
||||||
|
178998524 1187862900 104517087
|
||||||
|
288525818 1292379987 6517514
|
||||||
|
995810057 1598284893 57532053
|
||||||
|
3220600544 1992413615 127590475
|
||||||
|
1857243139 195070261 25696499
|
||||||
|
2424262835 1443718326 550802
|
||||||
|
3143673104 1375907946 12442204
|
||||||
|
3776575836 3943040431 220205828
|
||||||
|
1053342110 693558780 494304120
|
||||||
|
2630970071 2286623883 512703033
|
||||||
|
638901084 2284929071 1694812
|
||||||
|
801571118 2836704943 174236
|
||||||
|
640595896 2836879179 54029862
|
||||||
|
4128502701 3756165939 24544656
|
||||||
|
1684527036 520842677 172716103
|
||||||
|
1547646230 2890909041 136880806
|
||||||
|
3524782486 3677409127 61983652
|
||||||
|
3685995340 3524782486 90580496
|
||||||
|
3380558839 500548442 20294235
|
||||||
|
2440816209 1722010336 190153862
|
||||||
|
283515611 2799326916 5010207
|
||||||
|
1903210936 2120004090 35372740
|
||||||
|
561890639 1298897501 77010445
|
||||||
|
555286330 2278324762 6604309
|
||||||
|
1938583676 220766760 125378624
|
||||||
|
3996781664 4163246259 131721037
|
||||||
|
3156115308 1444269128 64485236
|
||||||
|
|
||||||
|
humidity-to-location map:
|
||||||
|
2420477851 2725678119 154870744
|
||||||
|
341010579 1968896618 161603351
|
||||||
|
2771047693 3040747240 63786420
|
||||||
|
1473264654 231223255 158065928
|
||||||
|
300743457 665216997 40267122
|
||||||
|
4266394999 3974648226 28572297
|
||||||
|
44642725 3145344681 187170981
|
||||||
|
3913829571 3489505645 352565428
|
||||||
|
2132898063 571123277 94093720
|
||||||
|
2945529238 1729589230 52970089
|
||||||
|
3205711977 3366573953 87052626
|
||||||
|
3077771609 1429791513 87129347
|
||||||
|
3840363983 3901182638 31190715
|
||||||
|
3674520209 3842071073 59111565
|
||||||
|
3733631774 4003220523 106732209
|
||||||
|
0 2326199067 44642725
|
||||||
|
1631330582 389289183 181834094
|
||||||
|
2226991783 2370841792 193486068
|
||||||
|
2911470947 3332515662 34058291
|
||||||
|
1999501975 1516920860 133396088
|
||||||
|
1813164676 1782559319 186337299
|
||||||
|
502613930 2880548863 91268626
|
||||||
|
1242041399 0 231223255
|
||||||
|
3586449755 4206896842 88070454
|
||||||
|
2834834113 1353642962 76148551
|
||||||
|
3164900956 3104533660 40811021
|
||||||
|
3489505645 4109952732 96944110
|
||||||
|
2910982664 2564327860 488283
|
||||||
|
3292764603 2564816143 160861976
|
||||||
|
231813706 2971817489 68929751
|
||||||
|
2575348595 2130499969 195699098
|
||||||
|
593882556 705484119 648158843
|
||||||
|
3871554698 3932373353 42274873
|
||||||
|
2998499327 1650316948 79272282
|
||||||
33
src/aoc5test.txt
Normal file
33
src/aoc5test.txt
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
seeds: 79 14 55 13
|
||||||
|
|
||||||
|
seed-to-soil map:
|
||||||
|
50 98 2
|
||||||
|
52 50 48
|
||||||
|
|
||||||
|
soil-to-fertilizer map:
|
||||||
|
0 15 37
|
||||||
|
37 52 2
|
||||||
|
39 0 15
|
||||||
|
|
||||||
|
fertilizer-to-water map:
|
||||||
|
49 53 8
|
||||||
|
0 11 42
|
||||||
|
42 0 7
|
||||||
|
57 7 4
|
||||||
|
|
||||||
|
water-to-light map:
|
||||||
|
88 18 7
|
||||||
|
18 25 70
|
||||||
|
|
||||||
|
light-to-temperature map:
|
||||||
|
45 77 23
|
||||||
|
81 45 19
|
||||||
|
68 64 13
|
||||||
|
|
||||||
|
temperature-to-humidity map:
|
||||||
|
0 69 1
|
||||||
|
1 0 69
|
||||||
|
|
||||||
|
humidity-to-location map:
|
||||||
|
60 56 37
|
||||||
|
56 93 4
|
||||||
Loading…
Add table
Add a link
Reference in a new issue