Solution for 2023 day 1 part 1

quickdudley
Jul 17, 2024, 10:58 PM
LMKWOZVDWEBUHOH7TPO2AQKL4CTUVLA36Q74MBPE3U3QAF53E6FQC

Dependencies

Change contents

  • file addition: 2023 (d--r------)
    [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)))
    )