diff --git a/02a.lisp b/02a.lisp new file mode 100644 index 0000000..abf5fc0 --- /dev/null +++ b/02a.lisp @@ -0,0 +1,47 @@ +(require :uiop) +(load (sb-ext:posix-getenv "ASDF")) +(asdf:load-system 'str) + +(defun get-range (range) + (let ((range (str:split "-" range))) + (loop for i from (parse-integer (car range)) to (parse-integer (car (cdr range))) collect i) + ) + ) +(get-range "11-22") + +(defun get-ranges (instr) + (loop for range in + (str:split "," (string-trim '(#\Newline) instr)) + collect + (get-range range) + ) + ) +(get-ranges "1-3,4-5") + +(defun validate-product-id (product-id) + (let ((product-id (format nil "~A" product-id))) + (setq product-id-length (length product-id)) + (setq split-at (/ product-id-length 2)) + ;(print product-id) + (cond + ((not (evenp product-id-length)) t) + (t (not (string= (subseq product-id 0 split-at) (subseq product-id split-at)))) + ) + ) + ) +(validate-product-id 1212) +(validate-product-id 123) +(validate-product-id 1234) + +(defun sum-all-invalid-ids (text) + (reduce #'+ + (remove-if #'validate-product-id + (reduce #'append + (get-ranges text) + ) + ) + ) + ) + +(sum-all-invalid-ids (uiop:read-file-string "02example.txt")) +(sum-all-invalid-ids (uiop:read-file-string "02data.txt")) diff --git a/02example.txt b/02example.txt new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/02example.txt @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..31a72ac --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1764522689, + "narHash": "sha256-SqUuBFjhl/kpDiVaKLQBoD8TLD+/cTUzzgVFoaHrkqY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a47cafa --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "A Nix-flake-based Shell development environment"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; # unstable Nixpkgs + + outputs = {self, ...} @ inputs: let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forEachSupportedSystem = f: + inputs.nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + pkgs = import inputs.nixpkgs {inherit system;}; + } + ); + in { + devShells = forEachSupportedSystem ( + {pkgs}: { + default = pkgs.mkShellNoCC { + packages = with pkgs; [ + shellcheck + (sbcl.withPackages (ps: [ps.str])) + ]; + }; + } + ); + }; +}