Compare commits

...

7 commits

8 changed files with 4191 additions and 0 deletions

7
.envrc Normal file
View file

@ -0,0 +1,7 @@
use_flake() {
watch_file flake.nix
watch_file flake.lock
eval "$(nix print-dev-env)"
}
use flake

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Generated by Nix
/.pre-commit-config.yaml

18
2021/d01/ex1/ex1.py Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List
def solve(input: List[int]) -> int:
return sum(prev < cur for (prev, cur) in itertools.pairwise(input))
def main() -> None:
input = [int(line) for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2000
2021/d01/ex1/input Normal file

File diff suppressed because it is too large Load diff

30
2021/d01/ex2/ex2.py Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env python
import collections
import itertools
import sys
from typing import List
def sliding_window(iterable, n):
it = iter(iterable)
window = collections.deque(itertools.islice(it, n), maxlen=n)
if len(window) == n:
yield tuple(window)
for x in it:
window.append(x)
yield tuple(window)
def solve(input: List[int]) -> int:
windowed = [sum(window) for window in sliding_window(input, 3)]
return sum(prev < cur for (prev, cur) in itertools.pairwise(windowed))
def main() -> None:
input = [int(line) for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2000
2021/d01/ex2/input Normal file

File diff suppressed because it is too large Load diff

69
flake.lock Normal file
View file

@ -0,0 +1,69 @@
{
"nodes": {
"futils": {
"locked": {
"lastModified": 1638122382,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "master",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1638286143,
"narHash": "sha256-A+rgjbIpz3uPRKHPXwdmouVcVn5pZqLnaZHymjkraG4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "29d1f6e1f625d246dcf84a78ef97b4da3cafc6ea",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-utils": [
"futils"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1637745948,
"narHash": "sha256-DmQG1bZk24eS+BAHwnHPyYIadMLKbq0d1b//iapYIPU=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "c3b4f94350b0e59c2546fa85890cc70d03616b9c",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "master",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"futils": "futils",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}

65
flake.nix Normal file
View file

@ -0,0 +1,65 @@
{
description = "Advent of Code answers";
inputs = {
futils = {
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "master";
};
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-unstable";
};
pre-commit-hooks = {
type = "github";
owner = "cachix";
repo = "pre-commit-hooks.nix";
ref = "master";
inputs = {
flake-utils.follows = "futils";
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = { self, futils, nixpkgs, pre-commit-hooks }:
futils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
checks = {
pre-commit = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
black = {
enable = true;
};
isort = {
enable = true;
};
nixpkgs-fmt = {
enable = true;
};
};
};
};
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
python310 # Latest version at the moment
];
inherit (self.checks.${system}.pre-commit) shellHook;
};
});
}