__init__
Some more examples of why piracy is a service problem
I don’t understand the purpose of this library. The article makes it sound like the problem is circular dependencies, which is not something that is addressed by the library in any way. Deleting and regenerating all the migrations instead of squashing is something I’ve done before (it often generates a much simpler squashed migration than squashmigrations does), but it is very much a manual process, for example you must review the generated migration and bring in any runpython/runsql operations, because makemigrations won’t do that. And the replaces
directive built in to Django handles fixing the history across environments already.
Oh man. I like to think my sql-fu is pretty decent but I can’t imagine trying to pull off some of these solutions in sql haha
Python
Easy one today
code
import pathlib
base_dir = pathlib.Path(__file__).parent
filename = base_dir / "day9_input.txt"
with open(base_dir / filename) as f:
lines = f.read().splitlines()
histories = [[int(n) for n in line.split()] for line in lines]
answer_p1 = 0
answer_p2 = 0
for history in histories:
deltas: list[list[int]] = []
last_line: list[int] = history
while any(last_line):
deltas.append(last_line)
last_line = [last_line[i] - last_line[i - 1] for i in range(1, len(last_line))]
first_value = 0
last_value = 0
for delta_list in reversed(deltas):
last_value = delta_list[-1] + last_value
first_value = delta_list[0] - first_value
answer_p1 += last_value
answer_p2 += first_value
print(f"{answer_p1=}")
print(f"{answer_p2=}")
Nice. I’m a long time fan of poetry, but I’m trying out a couple new tools too. Been wanting to check out ruff to replace flake8. And mypy, cause I’ve never worked on a project that used a type checker, though there hasn’t really been much for it to do on the solutions I’ve hammered out so far.
(python) Much easier than day 3.
code
import pathlib
base_dir = pathlib.Path(__file__).parent
filename = base_dir / "day4_input.txt"
with open(base_dir / filename) as f:
lines = f.read().splitlines()
score = 0
extra_cards = [0 for _ in lines]
n_cards = [1 for _ in lines]
for i, line in enumerate(lines):
_, numbers = line.split(":")
winning, have = numbers.split(" | ")
winning_numbers = {int(n) for n in winning.split()}
have_numbers = {int(n) for n in have.split()}
have_winning_numbers = winning_numbers & have_numbers
n_matches = len(have_winning_numbers)
if n_matches:
score += 2 ** (n_matches - 1)
j = i + 1
for _ in range(n_matches):
if j >= len(lines):
break
n_cards[j] += n_cards[i]
j += 1
answer_p1 = score
print(f"{answer_p1=}")
answer_p2 = sum(n_cards)
print(f"{answer_p2=}")
Nobody doing python? It is my first time participating so I think I’ll try it out my strongest language first. I think if I were to try something else it would be Go, to brush up, or Typescript, which I’ve been wanting to learn but haven’t really had an application for, yet.
Before I had it all automated, I used to use a browser extension which would send them to the web ui without having to actually open deluge at all. I think it was called deluge siphon.