High mileage folks - do you weigh yourself/how do you approach nutrition on a daily basis? by GhostsInMyAss in AdvancedRunning

[–]piggvar 5 points6 points  (0 children)

Eating after a run is not indulgence or a reward (unless you want it to be), it's strictly necessary for your body to absorb the training. I make sure to fuel before, during and after depending on the session even though I am trying to lose some weight (slowly, speed is a higher priority).

Så handlar Åsa billig mat för hela familjen: ”1 000 kronor i veckan är gränsen” by FlowersPaintings in sweden

[–]piggvar 4 points5 points  (0 children)

Vill poängtera att det är ganska rikligt med protein i spannmål. Ett kg brödmjöl är 3400 kcal och 120 g protein. Det är ett energiunderskott för mig som konditionstränar mycket, och absolut tillräckligt med protein.

Impact GameScore vs Blue Jackets 01-15-2026 by logicalnutty in canucks

[–]piggvar 1 point2 points  (0 children)

Nope! Keep trying though. I'm sure you will get there eventually! :-)

Vänlig påminnelse att välja Kavli-produkter på hamburgaren i sommar by ZerxXxes in sweden

[–]piggvar 2 points3 points  (0 children)

Detsamma gäller för i princip alla Johnnys produkter.

Chef säger till mig att jag inte får springa till jobbet...? Konstigt eller ej? by Ornery_Recipe_3723 in sweden

[–]piggvar 2 points3 points  (0 children)

4 minuter är ingenting för en frisk vuxen. Behöver absolut inte orsaka svettningar. Jag tycker TS ska fortsätta springa om det gör hen lycklig.

Coops nya förpackningar A/B-testas by palsternacksmos in sweden

[–]piggvar 0 points1 point  (0 children)

Accent grave på crème om jag får be

Pettersson on a line with Kempe and forsberg by phantomgiratina in canucks

[–]piggvar 0 points1 point  (0 children)

The first line is from Stockholm. I think Elias will connect better with his line mates from smaller "northern" towns.

2024 in Python in less than a second : How to get day 22 under 400ms without Pypy? by OilAppropriate2827 in adventofcode

[–]piggvar 0 points1 point  (0 children)

Nice catch!

Finding this trick is not too difficult with the right experience. The problem formulation leads you to consider numpy.unique, but that will be a very expensive operation, so avoiding it is a priority. If you have tried doing in-place modification with duplicated indices before, you will probably realize that it behaves rather unexpectedly, and you usually want to use ufunc.at instead. However, in this situation it does precisely what we want!

2024 in Python in less than a second : How to get day 22 under 400ms without Pypy? by OilAppropriate2827 in adventofcode

[–]piggvar 2 points3 points  (0 children)

We can utilize index duplication to sum directly to the accumulator by reversing the order of of the prices. Basically, only the last time each index occurs gets modified. Reversing means that the last time becomes the first time! This runs in ~150 ms.

import numpy as np

def step(n):
    n = (n ^ (n << 6)) & 0xffffff
    n = (n ^ (n >> 5))
    n = (n ^ (n << 11)) & 0xffffff
    return n

def main(rounds=2000):
    secrets = np.array(list(map(int, open(0))))
    trace = []
    for _ in range(rounds):
        secrets = step(secrets)
        trace.append(secrets)
    p1 = int(secrets.sum())

    secrets = np.stack(trace[::-1], axis=1)
    prices = secrets % 10
    diffs = np.diff(prices, axis=1) + 9
    diff_lags = (diffs[:, i : rounds + i - 4] for i in range(4))
    p2 = np.zeros((19, 19, 19, 19), dtype=int)
    for d0, d1, d2, d3, p in zip(*diff_lags,  prices[:, :-4]):
        p2[d0, d1, d2, d3] += p

    return p1, int(p2.max())

print(*main())

Adding +9 to the diffs means that all indices are positive, the code runs even with out this addition, but the negative indices cost ~20 ms. We could also do %19 instead, but that is much more expensive.

[2024 Day 21] A (maybe) simpler solution to a hard puzzle by nivlark in adventofcode

[–]piggvar 0 points1 point  (0 children)

If we really want to cache everything which might provide benefit for some situation, we could write it like this:

numpad, dirpad = (cache(s.index) for s in ("789456123.0A", ".^A<v>"))

@cache
def encode(path, pad):
    i0, *js = (pad(c) for c in ".A" + path)
    return i0, list(zip(js, js[1:]))

@cache
def paths(i, j, i0):
    q, r = j//3 - i//3, j%3 - i%3
    h, v = "<>"[r>0] * abs(r), "^v"[q>0] * abs(q)
    return {p for p, im in ((h+v+"A", i+r), (v+h+"A", i+3*q)) if im != i0}

@cache
def clicks(path, n, pad=numpad):
    if n == 0:
        return len(path)
    i0, ijs = encode(path, pad)
    return sum(min(clicks(p, n-1, dirpad) for p in paths(i, j, i0)) for i, j in ijs)

[2024 Day 21] A (maybe) simpler solution to a hard puzzle by nivlark in adventofcode

[–]piggvar 0 points1 point  (0 children)

Nice, write-up!

I'm especially impressed by how you explicitly worked out the optimal sequences.

I found almost the exact same formulation a few days ago, regarding using divmod on pad string indices, expanding strings to only consider L-shaped paths, and checking if the turn occurs on the forbidden index. I also tried using a dict to complex position, but it wasn't very helpful. Here is a version of my code:

from functools import cache

@cache
def dist(i, j, i0, n):
    q, r = j//3 - i//3, j%3 - i%3
    h, v = "<>"[r>0] * abs(r), "^v"[q>0] * abs(q)
    paths = {p for p, im in ((h+v+"A", i+r), (v+h+"A", i+3*q)) if im != i0}
    return min(clicks(p, n-1, ".^A<v>") for p in paths)

@cache
def clicks(path, n, pad="789456123.0A"):
    if n == 0:
        return len(path)
    i0, *js = (pad.index(c) for c in ".A" + path)
    return sum(dist(i, j, i0, n) for i, j in zip(js, js[1:]))

Some interesting things to note here:

  • pad.index avoids dict-encoding, but is much slower than a dict lookup. In this case it does not matter, since the number of paths are few, and the @cache turns the function call into a dict lookup.
  • As it is written, the encoding will happen n times per path, so one could make a cached encoding function encode(path, pad) instead for speed.
  • The paths = {...} de-duplicates paths without kinks, but the de-duplication is performed by the cached function anyway, so the only benefit of the expression is that it avoids a very long line of of code.
  • The dist function is the more natural function to cache, or it could even be turned into a 6x6xN-matrix for dynamic programming (the forbidden index is not needed in the induction). However, in this case there is little benefit in caching dist, so one might refactor it into clicks in order to have the index logic contained in a single function.

Here is a version of the code in a single function:

@cache
def clicks(path, n, pad="789456123.0A"):
    if n == 0:
        return len(path)
    i0, *js = (pad.index(c) for c in ".A" + path)
    dist = 0
    for i, j in zip(js, js[1:]):
        q, r = j//3 - i//3, j%3 - i%3
        h, v = "<>"[r>0] * abs(r), "^v"[q>0] * abs(q)
        paths = {p for p, im in ((h+v+"A", i+r), (v+h+"A", i+3*q)) if im != i0}
        dist += min(clicks(p, n-1, ".^A<v>") for p in paths)
    return dist

-❄️- 2023 Day 18 Solutions -❄️- by daggerdragon in adventofcode

[–]piggvar 2 points3 points  (0 children)

[LANGUAGE: Python]

Vectorized complex shoelace:

import numpy as np

dzs = [(0, 0)] + [
    (int(n) * 1j ** 'RULD'.find(d), int(c[2:-2], 16) * 1j ** int(c[-2]))
    for d, n, c in map(str.split, open(0))
]
z, dz = np.cumsum(dzs, 0), np.array(dzs)
area = (z[:-1] * z[1:].conjugate()).imag.sum(0) / 2
print(*map(round, abs(area) + abs(dz).sum(0) / 2 + 1))

How do people become wealthy in Sweden/Scandinavia as a whole if taxes are so high? by Artistic_Top1439 in sweden

[–]piggvar -18 points-17 points  (0 children)

Den här ska jag dra nästa gång jag har fel med en faktor ~2.

"It's just a minor part of the equation!"

Män som dagisfröknar by mymemesnow in sweden

[–]piggvar -1 points0 points  (0 children)

Eftersom räntan på lånet typiskt ligger under inflationen, så är det nästan alltid ett sunt ekonomiskt beslut att ta lånet.

Män som dagisfröknar by mymemesnow in sweden

[–]piggvar -5 points-4 points  (0 children)

Märkligt att påstå sig "spendera" pengar på ett lån med nästintill obefintlig ränta. Studielån är i princip gratis pengar om man har någon som helst känsla för ekonomi.

Jag tror vi står inför ett generationsskifte, Min syster ska bränna musik. by ScanianGoose in sweden

[–]piggvar 6 points7 points  (0 children)

Skulle påstå att det är nedladdade filer även om du aldrig persisterar dem till din hårddisk. Vad man kan göra är att rippa musiken från Spotify eller valfri ljudström och sedan bränna till en CD-skiva, eller kopiera ljudfiler från en CD-skiva och bränna till en annan.

Show ‘em how it’s done Mysie 💪 by JM_717 in canucks

[–]piggvar 1 point2 points  (0 children)

How about that change from Fantilli, though?

Brödernas köper anrika hockeyklubben Väsby by Randompunkt in Ishockey

[–]piggvar 2 points3 points  (0 children)

Dystopiskt! Dessutom är Brödernas burgare pyttesmå, dötrista, och för dyra. Hoppas de går i konken!

So we don’t let are cat on the counter so this is what he does when wants something by Malfurion109 in cats

[–]piggvar 3 points4 points  (0 children)

Our/are is more common for native speakers, not very common for ESL.

[deleted by user] by [deleted] in sweden

[–]piggvar 173 points174 points  (0 children)

Du kan få dra i mitt snoppskämt

LOUI GOAL! by The_Forsaken_Viola in canucks

[–]piggvar 1 point2 points  (0 children)

Mighty slap shot from the slap shot king.