Solution for 2023 day 1 part 1
Dependencies
- [2]
UMRCR7E6
Change contents
- file addition: 2023[2.1]
- file addition: shell.nix[0.16]
{ pkgs ? import <nixpkgs> {} }: pkgs.mkShell {nativeBuildInputs = with pkgs; [sbcl];} - file addition: day1.lisp[0.16]
(defun process (instream)(loop for line = (read-line instream nil) while line sum(calibration line)))(defun calibration (line)(let ((a NIL) (b NIL))(loop for c across line do (let ((x (digit-char-p c)))(when x (setq b x) (unless a (setq a x)))))(when (and a b) (+ (* 10 a) b))))(loop for arg in (cdr *posix-argv*) do(with-open-file (s arg :direction :input) (format T "~d~&" (process s))))