1
Fork 0
mirror of https://github.com/RGBCube/AdventOfCode synced 2025-07-26 03:27:44 +00:00
AdventOfCode/2023/1-1.nix
2023-12-02 17:53:44 +03:00

15 lines
388 B
Nix

{ lib, input }:
with builtins; with lib; rec {
lines = splitString "\n" input;
linesChars = map (splitString "") lines;
linesOnlyNumbers = map (filter (char: (match "[0-9]" char) != null)) linesChars;
firstAndLastConcatted = list: (head list) + (last list);
linesNumbers = map firstAndLastConcatted linesOnlyNumbers;
result = foldl' add 0 (map fromJSON linesNumbers);
}