Avatar

__init__

__init__@programming.dev
Joined
0 posts • 13 comments
Direct message

Spontaneous trailer harness combustion, spontaneous oil pump combustion, what’s next?

permalink
report
parent
reply

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

permalink
report
reply

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.

permalink
report
reply

Yeah, this was especially irritating in a python project that uses poetry, cause every single one would cause a merge conflict. We stopped using it altogether because of that. Will have to give this a try.

permalink
report
parent
reply

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.

permalink
report
reply

(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=}")
permalink
report
reply

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=}")
permalink
report
reply

They got me good with this one time. It looked like a newsletter from like Seattle times or something, I was like I didn’t sign up for this shit and immediately clicked the unsubscribe link, boom enrolled in training. Well played, guys.

permalink
report
parent
reply

Some more examples of why piracy is a service problem

permalink
report
reply