day 2 part 1
This commit is contained in:
parent
920f9032dd
commit
46f10c043e
4 changed files with 107 additions and 0 deletions
47
02a.lisp
Normal file
47
02a.lisp
Normal file
|
|
@ -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"))
|
||||||
1
02example.txt
Normal file
1
02example.txt
Normal file
|
|
@ -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
|
||||||
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
32
flake.nix
Normal file
32
flake.nix
Normal file
|
|
@ -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]))
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue