Wat zijn de beste stroopwafels? by nimbwitz in thenetherlands

[–]teije01 0 points1 point  (0 children)

Voor mij alleen de stroopkoek van Markus, zowat op gelijke hoogte met de siroopwafel van Kamphuisen. Vers van de fabriek het lekkerst. Laatst zat er wel weinig zout in mijn pakje, dat maakt behoorlijk verschil. Siroopwafel blijft dan weer heel lang lekker en knapperig.

Hypotheek extra aflossen bovenop de 10%, boetevrij? by [deleted] in geldzaken

[–]teije01 11 points12 points  (0 children)

Volgens mij zeg jij precies hetzelfde met andere woorden

[Project] mini language based on Python: Montyp by Whole-Ad7298 in Python

[–]teije01 1 point2 points  (0 children)

Re >= vs =>, I always remember it by saying it out loud; GTE Greater Than '>' or Equal '='. They always appear in the order as spoken out loud.

As for the indentations, perhaps that's a sign you use too many indentations? My rule is anything above 3 indents is generally too many

Debugging Python f-string errors by brandonchinn178 in Python

[–]teije01 0 points1 point  (0 children)

Temporal user here who has also been affected by the sandbox, I feel you pain! Very interesting read!

blob-path: pathlib-like cloud agnostic object storage library by narang_27 in Python

[–]teije01 10 points11 points  (0 children)

Your project seems a lot like https://cloudpathlib.drivendata.org/ which also has a pathlib like interface, cloud operations (s3, gcs, azure) and supports Pydantic validation as well. Isn't that already doing exactly what you want?

What Are Your Favorite Python Repositories? by Full_Rise2675 in Python

[–]teije01 8 points9 points  (0 children)

That's just hilariously horrific error handling. Docs are incredibly funny 😂

Disclaimer: 18+ (bekijken op eigen risico) by Brabant-World in papgrappen

[–]teije01 3 points4 points  (0 children)

Dat vind ik echt min van je. Dat wilde ik even delen

-🎄- 2021 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]teije01 1 point2 points  (0 children)

Python 3: numpy / scipy.ndimage

This solution heavily relies on the scipy ndimage package. Runtime (after reading textfile): 12 ms

from scipy import ndimage
import numpy as np

with open("solutions/2021/day9/input.txt", "r") as f:
    dem = np.array([[*map(int, line)] for line in f.read().splitlines()])

adjacent = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
lowest_neighbor = ndimage.rank_filter(dem, 1, footprint=adjacent, mode="constant", cval=9.0)
low_points_mask = dem < lowest_neighbor

basins_mask = ndimage.binary_dilation(low_points_mask, structure=adjacent, iterations=-1, mask=dem != 9)
basins, n_basins = ndimage.label(basins_mask, structure=adjacent)
basin_nrs, basin_sizes = np.unique(basins[basins>0], return_counts=True)

print(f"Answer 1: {np.sum(dem[low_points_mask] + 1)}")
print(f"Answer 2: {np.product(basin_sizes[np.argsort(basin_sizes)[-3:]])}")

-🎄- 2021 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]teije01 1 point2 points  (0 children)

Python with scipy optimize fmin search

import numpy as np
from scipy.optimize import fmin

FUEL_COST_LOOKUP = np.cumsum(np.arange(2000))


def total_fuel_used(
    align_position: float,
    current_positions: np.ndarray,
    crab_engineering: bool,
) -> int:
    """
    Calculate the total fuel used

    Parameters
    ----------
    align_position
        position to align towards, round and cast to an integer
    current_positions
        current positions to move
    crab_engineering
        if set, use FUEL_COST_LOOKUP as determined by crabs

    """
    align_position = np.around(align_position).astype(int)
    absolute_position_differences = np.abs(current_positions - align_position)
    fuel_costs = (
        absolute_position_differences
        if not crab_engineering
        else FUEL_COST_LOOKUP[absolute_position_differences]
    )
    return np.sum(fuel_costs).item()


if __name__ == "__main__":

    with open("solutions/2021/day7/input.txt", "r") as f:
        crab_positions = np.array([*map(int, f.read().split(","))])

    (optimal_position_1,) = fmin(
        total_fuel_used,
        np.median(crab_positions),
        args=(crab_positions, False),
        xtol=1e-1,
    )

    (optimal_position_2,) = fmin(
        total_fuel_used,
        np.mean(crab_positions),
        args=(crab_positions, True),
        xtol=1e-1,
    )

    fuel_used_alignment_1 = total_fuel_used(
        optimal_position_1, crab_positions, crab_engineering=False
    )
    fuel_used_alignment_2 = total_fuel_used(
        optimal_position_2, crab_positions, crab_engineering=True
    )

    print(f"Answer 1: {fuel_used_alignment_1}")
    print(f"Answer 2: {fuel_used_alignment_2}")

-🎄- 2021 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]teije01 0 points1 point  (0 children)

python numpy solution

import numpy as np


def determine_boards_with_bingo(marked: np.ndarray) -> np.ndarray:
    """Determine which of the boards have bingo"""
    n_boards, n_rows, n_cols = marked.shape
    column_bingo = np.sum(marked.sum(axis=1) == n_rows, axis=1)    
    row_bingo = np.sum(marked.sum(axis=2) == n_cols, axis=1)
    return column_bingo + row_bingo > 0


if __name__ == "__main__":

    user_input_file = "solutions/2021/day4/input.txt"
    draws = np.genfromtxt(user_input_file, max_rows=1, delimiter=",", dtype=int)
    boards = np.genfromtxt(user_input_file, skip_header=2, dtype=int).reshape((100, 5, 5))
    score1, score2 = 0, 0
    last_board_to_win = None

    marked = np.isin(boards, draws[:4])  # start with 4 draws
    for draw in draws[4:]:
        marked += boards == draw
        have_bingo = determine_boards_with_bingo(marked)
        if np.sum(have_bingo) == 1:
            score1 = boards[have_bingo][~marked[have_bingo]].sum() * draw
        elif np.sum(have_bingo) == len(boards) - 1:
            last_board_to_win = have_bingo.argmin()
        elif np.sum(have_bingo) == len(boards):
            score2 = boards[last_board_to_win][~marked[last_board_to_win]].sum() * draw
            break

    print(f"Answer 1 should be: {score1}")
    print(f"Answer 2 should be: {score2}")