Initial commit
Add boilerplate and day1 solution
This commit is contained in:
commit
92f2a860e8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/.direnv/
|
1000
day1/input.txt
Normal file
1000
day1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
44
day1/run.py
Normal file
44
day1/run.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from typing import List, Dict
|
||||
|
||||
EXAMPLE = """
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
"""
|
||||
|
||||
|
||||
class SplitLists:
|
||||
def __init__(self, input: str):
|
||||
self.list1, self.list2 = zip(*[val.split() for val in input.split("\n") if val])
|
||||
|
||||
def __str__(self) -> str:
|
||||
part1 = 0
|
||||
for val in self.distances():
|
||||
part1 += val
|
||||
part2 = 0
|
||||
for val, occ in zip(self.list1, self.occurances()):
|
||||
part2 += int(val) * occ
|
||||
return f"Part1: {part1}\nPart2: {part2}"
|
||||
|
||||
def distances(self) -> List[int]:
|
||||
return [
|
||||
abs(int(val1) - int(val2))
|
||||
for val1, val2 in zip(sorted(self.list1), sorted(self.list2))
|
||||
]
|
||||
|
||||
def occurances(self) -> List[int]:
|
||||
return [self.list2.count(key) for key in self.list1]
|
||||
|
||||
|
||||
def main(*args, **kwargs) -> None:
|
||||
example = SplitLists(input=EXAMPLE)
|
||||
print(example)
|
||||
with open("input.txt", "r") as f:
|
||||
print(SplitLists(input=f.read()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
27
flake.lock
Normal file
27
flake.lock
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1733064805,
|
||||
"narHash": "sha256-7NbtSLfZO0q7MXPl5hzA0sbVJt6pWxxtGWbaVUDDmjs=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "31d66ae40417bb13765b0ad75dd200400e98de84",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
33
flake.nix
Normal file
33
flake.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
outputs =
|
||||
{ self, nixpkgs }:
|
||||
let
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-linux"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
python = pkgs.${system}.python3;
|
||||
pythonEnv = python.withPackages (
|
||||
ps: with ps; [
|
||||
isort
|
||||
mypy
|
||||
]
|
||||
);
|
||||
in
|
||||
{
|
||||
default = pkgs.${system}.mkShellNoCC { packages = [ pythonEnv ]; };
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue