mirror of
https://github.com/RGBCube/AdventOfCode
synced 2025-07-26 03:27:44 +00:00
Add day 1 part 1
This commit is contained in:
parent
781a8c6669
commit
58850f81a6
4 changed files with 1067 additions and 0 deletions
1000
2023/1-1.in
Normal file
1000
2023/1-1.in
Normal file
File diff suppressed because it is too large
Load diff
17
2023/1-1.nix
Normal file
17
2023/1-1.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{ lib, input }:
|
||||
|
||||
with lib; with builtins; let
|
||||
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;
|
||||
|
||||
sumOfLinesNumbers = foldl' add 0 (map fromJSON linesNumbers);
|
||||
|
||||
result = sumOfLinesNumbers;
|
||||
in result
|
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1701253981,
|
||||
"narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
23
flake.nix
Normal file
23
flake.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
description = "RGBCube's Advent of Code Solutions.";
|
||||
|
||||
inputs = {
|
||||
nixpkgs = {
|
||||
url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { nixpkgs, ... }: let
|
||||
lib = nixpkgs.lib;
|
||||
|
||||
pathToResult = path: import ./${path}.nix {
|
||||
inherit lib;
|
||||
|
||||
input = builtins.concatStringsSep "\n"
|
||||
(builtins.filter (line: line != "")
|
||||
(lib.splitString "\n" (builtins.readFile ./${path}.in)));
|
||||
};
|
||||
in lib.genAttrs [
|
||||
"2023/1-1"
|
||||
] pathToResult;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue