Compare commits
2 Commits
eb6496a97a
...
700e40b5e3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
700e40b5e3 | ||
|
|
338a76a552 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.direnv/
|
||||
27
2025/05/part1.py
Normal file
27
2025/05/part1.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
if (os.path.isfile("./input")):
|
||||
input = open("./input", "r").read()
|
||||
else:
|
||||
input = "3-5\n10-14\n16-20\n12-18\n\n1\n5\n8\n11\n17\n32\n"
|
||||
|
||||
input = input[:-1]
|
||||
|
||||
isList = True
|
||||
fresh = []
|
||||
c = 0
|
||||
for line in input.split('\n'):
|
||||
if (line == ""):
|
||||
isList = False
|
||||
continue
|
||||
|
||||
if (isList):
|
||||
fresh.append([int(line.split('-')[0]), int(line.split('-')[1])])
|
||||
|
||||
if (not isList):
|
||||
for f in fresh:
|
||||
if (int(line) >= f[0] and int(line) <= f[1]):
|
||||
c += 1
|
||||
break
|
||||
|
||||
print(c)
|
||||
51
2025/05/part2.py
Normal file
51
2025/05/part2.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
|
||||
if (os.path.isfile("./input")):
|
||||
input = open("./input", "r").read()
|
||||
else:
|
||||
input = "3-5\n10-14\n16-20\n12-18\n\n"
|
||||
|
||||
#input = input[:-1]
|
||||
|
||||
fresh = []
|
||||
c = 0
|
||||
|
||||
for line in input.split('\n'):
|
||||
if (line == ""):
|
||||
break
|
||||
|
||||
s = int(line.split('-')[0])
|
||||
e = int(line.split('-')[1])
|
||||
|
||||
for f in fresh:
|
||||
if (f[0] <= s <= f[1]):
|
||||
s = f[1] + 1;
|
||||
if (f[0] <= e <= f[1]):
|
||||
e = f[0] - 1;
|
||||
|
||||
if (s > e):
|
||||
continue
|
||||
fresh.append([s, e])
|
||||
fresh.sort()
|
||||
c += (e - s) + 1
|
||||
|
||||
print(c)
|
||||
|
||||
ranges = []
|
||||
for line in input.split("\n"):
|
||||
if line == "":
|
||||
break
|
||||
ranges.append([int(line.split('-')[0]), int(line.split('-')[1])])
|
||||
|
||||
ranges.sort()
|
||||
|
||||
merged = []
|
||||
for s, e in ranges:
|
||||
if not merged or s > merged[-1][1] + 1:
|
||||
merged.append([s, e])
|
||||
else:
|
||||
merged[-1][1] = max(merged[-1][1], e)
|
||||
|
||||
c = sum(e - s + 1 for s, e in merged)
|
||||
|
||||
print(c)
|
||||
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1751274312,
|
||||
"narHash": "sha256-/bVBlRpECLVzjV19t5KMdMFWSwKLtb5RyXdjz3LJT+g=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "50ab793786d9de88ee30ec4e4c24fb4236fc2674",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-24.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
28
flake.nix
Normal file
28
flake.nix
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
description = "a test development environment for python";
|
||||
|
||||
inputs = {
|
||||
|
||||
nixpkgs = {
|
||||
url = "nixpkgs/nixos-24.11";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
outputs = inputs@{ nixpkgs, ... }:
|
||||
{
|
||||
devShell = {
|
||||
x86_64-linux = let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
gcc python3
|
||||
];
|
||||
shellHook = ''
|
||||
echo -e "\x1B[0;33mentering python test development environment...\x1B[0m"
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user