diff options
author | Oscar Najera <hi@oscarnajera.com> | 2022-12-06 16:47:44 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2022-12-06 16:47:44 +0100 |
commit | f34c85b78a1cbefa475a252184c13b68c9727332 (patch) | |
tree | 11b7b49735ca72adca4701f5f0a7619d6ed9bd6c /AoC2022 | |
parent | 48fd41b4a011d04634830c9132cf137d33ad555a (diff) | |
download | scratch-f34c85b78a1cbefa475a252184c13b68c9727332.tar.gz scratch-f34c85b78a1cbefa475a252184c13b68c9727332.tar.bz2 scratch-f34c85b78a1cbefa475a252184c13b68c9727332.zip |
[AoC2022] Lisp 06
Diffstat (limited to 'AoC2022')
-rw-r--r-- | AoC2022/06/input | 1 | ||||
-rw-r--r-- | AoC2022/06/makefile | 15 | ||||
-rw-r--r-- | AoC2022/06/solver.el | 33 | ||||
-rw-r--r-- | AoC2022/06/solver.lisp | 17 |
4 files changed, 66 insertions, 0 deletions
diff --git a/AoC2022/06/input b/AoC2022/06/input new file mode 100644 index 0000000..1daaf7d --- /dev/null +++ b/AoC2022/06/input @@ -0,0 +1 @@ +hlfhfzffqnnrlnnvnmmgbgwgttbppcrcnnmdmfdmmgwwrrqnrrscrctcbttvcvtvvhchjhccjgjttmddplplqplqlbqlblrrbrvvprpffpmmzpmpcczjzzbwwfssvrrvggncgncgcwczzswwqqjjflffpwfpwpbwpwpdpbpvvqffcfcjffjllncczfzzmhzzmddgdrgrwwjzzdjjsnjsjfsjsjhhcchlccchqchhzzpnngdgndnpnppsdsggbvgvgpprqrqmmlzmzllvrrcvclcwczcqqcdcfcqqmmzbzdzdjzdjdmjdjzdjjcvjvcjvcvssltstttfbtftrfrlrdllrqqfssslccjdcjdjfdjfjqjnqjnjnrnddtnndtnnztzqztqztqzzpmzmggzrgrwwdqwdwcdwdnnmlmgmtmtstwssbffcnclclnclcjjcjpcpqcpqcpqpmqqfccpcjppnspsnnzggnpntndtdqtthwhnhwnwllzhlzhlzzghzghhlhvhwhjhfjjcnjnvjnjvvqccdmmgddllnmnrrdtdnncggfhgfglfgfmfnnpvvggznnwvnwwfgghrrfwrwzwszzzldzdldhlhblhblhbbbgjgsjggmqqmrrzggrhhwpwdpwdpwplpgpbggtssqffbqfbqbnnsqnqfnngcnnmwnmnbmmmslsjllbtbbpllltzzhgzztllsdllrvvhvjvbbhcbhchmchcctbcttvccgwcwpcchrcrdrdggcrrntrrfllcffbdfflrrrgbgrbbbdqbqjbbgbgrrqwqtwqwhwghwhzwwcswsnwnqqjhjhwhfwhffdfgddgjgsjgjhgglhlwhlhssfqfhhdmdnmnppdcddfzzhmhqqntqnnjvnjvjddcvcgcbgbbpjbjtbjjfgftgffplljfjrrhqqpddlssrvsrvrpppsllsdsqqqzzfttqsqzssjbbrnbnnrbbsrshsrrshrhwhbwbrrsrfrttfqtfqqfddvrvjrjvjsjhjsjdjqdjjlqjjjgcjcmcncfcrcwrwsrsslffzszmsszrsssrnrjjvbvpvcppptbbhhrddbcbggbqbmmsqqwggfpfbblmldmmpmwpwfwjfjsjnjmmpllccjzcjcwwpswshhpthhzchctcbcrrrrmvrvrdvvjmmvgmgwglghllvmllzlzzsvzzrmmhnnsjnnpvpwvpwwmvwwdqqdffhhhmccfgfvggchcctrrmdrrhrhnhnzzgpzzgttnhthvhzzqvvvwpwqpqdppsnnrgnnhphphmhcmcrmrvvqlvqqsccqhchzhwwmvmzmczzgsgdsggthgglrlnrlllbdllhwlwltwwcswsgssbhbsbvsbsbwbhbnncrcllttbrbppjccfpfhhgshschsccmrcmmcrrrzvvrcrggmwgwjwnwjjbffjddjnjgngqgdgnndznndvvfqfgfvvrvqrvvpllnsszbsbdbbdzbdbzbqbzznrznzjzpptcptccvwccfscffrftrrsnsvvswvvhbhzzfbzffncchhcnngzzcpcmmfttsntnjjsccqbcqqmzzgppdhppdtppmffgtgvvlzlpptdtttdppqjqtqctcrrzsswwtnwtnwnqqvbbdgjhvmmzpnhfvsbddzhgdwcnfdstvhhbzlzcfjwhlptbhmbmblprtsdmrd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chdgwtrhhcmppcqlmrqlnwqccfphsdhbsbmtjvpcwwjrmrllbpnrmpbvwgwbftpdpphccwqcblcnvvbbppscmnjqgddllbnbvmmqzdffrrjtqwllzgpqrmnlfqrptzqmdmnrfnjpvqvjbsqrhljslgqqcqqtmtbwjrpphtjgjbqpzmzrzjrfjwcdcnbsjfljclffjplnrrcfbmhphtcjrzlrvvjcznpgpnrdwwqvgnbnzqnlcghhgwvhqbvjzfbdvhrzlqfbtlqhpltfjlfpbnjbphmmpntzqgjmwjtchwmlwvfjmfflqzpqnvvrgnbddzlfpdpdjghfgbsfddjspnfdwvqppncmdgfrnvrpcrflhgjgbwdsbwblfcwbtlrrnjjdhbvmrzgsvjwgfnnhqfbvhprlmwwqgclzlbqbrdspcbhftmdscsmpwrggrmnsvjphjmzmmrlrhnmdhwjlbmjchtvsrcplfspsssjznmzcrqnsjjtwjzvlhshbptqwwvjhjvzrhphphsbphpnzpfbwcdnqrhrrvlrwrztlpqnrcfzrncsvpzqzgslrlrwhvtgjmfncldqmvshlmnlpqbgvnwqfcthgrgllmqrjqmfgznspgltpptglpdcvhtzsprprbldbzhbmjsqzwvjggwhsczltcvgwqhspzpzvljwqjgrgtwswjdswlzjzslrsslvqzncjwhbbjpbdthqpgmhfglggmlrgwdsplgscrwstntvrhjzjjlshtgmnnhvsjwfmcjbpzjcstmnpvtbgrfcfdwjljsrfhdphrdcslwhgvlnwltwchplvfzntfgcnlsvzrvnnczhhqdlwjvqprhmtjdtwmppffmszzzqtfrgnhnzqgqzhrjzgntcszstrfhhtptgvswvzvjcgcntmhzzmdgsmtgzhpfvqfnwmsjdhtfgmmbrrfsdlptchqqzqdqjncmtpznfssrcnmcdnthglmfzsfgltrndqsfmdftmfgchbwmzgrtjvgqtshlltthnnpqnzfrchzhdzrrnpzvfzblrmhwdwjnqdptlbvndmmlhzhvsfdlmlhqrgqqzsdqtpczwcrwcbsftvvphfbwjrvrnrcqbbcsqgnhltwzvllljcvpwjgslbmngcdmpdvjlgcnrzwqjdgrblncpqmrgjmpqjzvdmcmwfnwqlszdgwqdfznhsnpsjrfwrqpqmpvhstmzgqblfmcfvwljbhdfhdmqcvrwnqcstwtzgmng diff --git a/AoC2022/06/makefile b/AoC2022/06/makefile new file mode 100644 index 0000000..fce871b --- /dev/null +++ b/AoC2022/06/makefile @@ -0,0 +1,15 @@ +## +# run solutions +# +# @file +# @version 0.1 + + + +# end + +run: + sbcl --load ~/.sbclrc --script solver.lisp + emacs -batch -l ert -l solver.el -f ert-run-tests-batch-and-exit + # rustc solver.rs && ./solver + # elixir solver.ex diff --git a/AoC2022/06/solver.el b/AoC2022/06/solver.el new file mode 100644 index 0000000..60d1654 --- /dev/null +++ b/AoC2022/06/solver.el @@ -0,0 +1,33 @@ +;;; solver.el --- Day 06 -*- 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 06, 2022 +;; Modified: December 06, 2022 +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; Day 06 +;; +;;; Code: +;;; + +(require 'ert) + +(defun solver (start-marker-len) + (with-temp-buffer + (insert-file-contents-literally "input") + (goto-char (point-min)) + (cl-loop with acc = (make-ring start-marker-len) + for chr = (prog1 (char-after) (forward-char)) + do (ring-insert acc chr) + count chr + while (< (length (seq-uniq (ring-elements acc) #'eq)) start-marker-len)))) + +(ert-deftest test-solver () + (should (= 1655 (solver 4))) + (should (= 2665 (solver 14)))) diff --git a/AoC2022/06/solver.lisp b/AoC2022/06/solver.lisp new file mode 100644 index 0000000..36aab05 --- /dev/null +++ b/AoC2022/06/solver.lisp @@ -0,0 +1,17 @@ + +(defun solver (marker-size) + (with-open-file (in "input" :element-type 'unsigned-byte) + (loop with acc = (make-array marker-size :element-type 'unsigned-byte) + for char = (ash 1 (- (read-byte in) 96)) ;; all lowercase letters thus subtract ascii start + and idx from 1 + do (setf (aref acc (mod idx marker-size)) char) + when (<= marker-size (logcount (reduce (lambda (set v) (logxor set v)) acc))) + return idx))) + +(ql:quickload :fiveam) + +(fiveam:test results + (fiveam:is (= 1655 (solver 4))) + (fiveam:is (= 2665 (solver 14)))) + +(fiveam:run-all-tests) |