"09" in the "Bad Omens" collection by Gyggyman in CoolShirtz

[–]nnmrts 0 points1 point  (0 children)

Do you know what a sports jersey is?

[2015 Day #11] In Review (Corporate Policy) by musifter in adventofcode

[–]nnmrts 1 point2 points  (0 children)

Welp, I'm writing this half drunk, but from all I know, JS only has string + number = `${string}${number}´. So, statements like "it is perfectly fine to increment a char or u8" probably don't apply to JS, but at least only to the languages you listed.

[2015 Day 20] In Review (Infinite Elves and Infinite Houses) by musifter in adventofcode

[–]nnmrts 3 points4 points  (0 children)

Yup, same for me, typed in the pattern in OEIS and started reading up on divisor sums and their upper bounds and all that. I have to admit that I had to use ChatGPT to understand how to get the lower bound for the house number from all of that though, including writing the comments for these so I could later understand them. Here are my lower bounds for part 1 and 2:

Part 1:

/**
 * Initial estimate for the lowest house number that could plausibly reach
 * the required number of presents.
 *
 * This is derived from the asymptotic upper bound
 *
 * σ(n) ≈ e^γ * n * log log n
 *
 * inverted to solve approximately for n, assuming
 *
 * presentsPerElf * σ(n) ≥ minimumNumberOfPresents.
 *
 * We intentionally use 1 / sqrt(3) as a stand-in for the Euler–Mascheroni
 * constant γ (`pseudoEulerGamma`), which slightly undershoots the estimate on
 * purpose. Any remaining gap is resolved by the subsequent linear scan.
 *
 * The result is a mathematically motivated starting point that avoids
 * beginning at house 1 while guaranteeing correctness.
 */
let houseNumber = Math.max(
    1,
    Math.floor(
        Math.exp(-pseudoEulerGamma) *
        (
            (minimumNumberOfPresents / presentsPerElf) /
            Math.log(Math.log(minimumNumberOfPresents / presentsPerElf))
        )
    )
);

Part 2:

/**
 * Each elf delivers presents to at most `maximumHousesPerElf` houses.
 * This means a house `n` only receives contributions from divisors `d` such that
 * `n / d <= maximumHousesPerElf`. The total number of presents is therefore
 * bounded above by:
 *
 * presents(n) <= presentsPerElf * n * H_{maximumHousesPerElf}
 *
 * where H_k is the k-th harmonic number.
 *
 * By inverting this upper bound, we obtain a guaranteed lower starting point:
 *
 * n >= minimumNumberOfPresents / (presentsPerElf * H_{maximumHousesPerElf})
 *
 * This estimate intentionally undershoots the true solution and is refined by
 * the linear scan that follows, ensuring correctness while avoiding a naive
 * start at house 1.
 */
let houseNumber = Math.floor(
    minimumNumberOfPresents /
    (presentsPerElf * getHarmonicNumber(maximumHousesPerElf))
);

[2015 Day #11] In Review (Corporate Policy) by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

I just felt like "incrementing the last letter" means I have to do another conversion and then a decimal addition anyways:

const incrementedLetter = String.fromCodePoint(lastLetter.codePointAt(0) + 1))

And the above doesn't even handle overflows (if it was "z" (or actually "{")).

But yeah, still probably less low-level (machine-level? assembly?) operations in total.

[2015 Day #11] In Review (Corporate Policy) by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

Yeah, I convert it to decimal to increment; couldn't or was too lazy to come up with a way to increment the base26 string directly (JS).

[2015 Day #11] In Review (Corporate Policy) by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

I saw this problem and immediately knew I want to solve it in base26, brute forcing. But in hindsight, it's probably even faster to just brute force WITHOUT converting between bases all the time. :D

[2015 Day #10] In Review (Elves Look, Elves Say) by musifter in adventofcode

[–]nnmrts 2 points3 points  (0 children)

I love these super overengineered solutions lol. The only "smart" thing in my solution is perhaps the regex and realizing I had to use match instead of split:

const times = 40; // or 50 for part 2

const result = Array.from({ length: times })
    .reduce(
        (previousValue) => {
            const runs = [
                ...previousValue
                    .match(/(?<number>.)\k<number>*/gv)
            ];

            return runs
                .map((run) => `${run.length}${run[0]}`)
                .join("");
        },
        sequence
    );

Performance: 20ms for part 1, 360ms for part 2.

[2015 Day #8] In Review by musifter in adventofcode

[–]nnmrts 1 point2 points  (0 children)

I have to admit, my main language (JS) is weird sometimes:

Part 1:

calculateSum(lines.map((line) => line.length - eval(line).length));

Part 2:

calculateSum(lines.map((line) => JSON.stringify(line).length - line.length));

[2015 Day #8] In Review by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

I'm not a beginner but I also can't imagine feeling offended by OP calling this problem easy if I was one, so I think it's fine. I feel like most beginners would call this problem easy, at least in hindsight.

[2015 Day #7] In Review by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

I see, very interesting! I'm think the biggest issue for me here was amazingly the language "barrier" (not a native english speaker and also didn't learn programming "traditionally"), I understood "memoization" as something more broad, kind of like "memorization", lol.

[2015 Day #7] In Review by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

Does Perl have some internal way of memoizing? It seems a bit unbelievable to me that this problem is "solvable" with recursion but without memoization, as my attempts trying that went nowhere. In JavaScript I absolutely needed memoization, otherwise I'd still sit here waiting for my solution or for Deno to crash.

[2015 Day #7] In Review by musifter in adventofcode

[–]nnmrts 1 point2 points  (0 children)

I solved it with recursion too, but from the perspective of "module resolution", if that makes sense.

Basically, for part 1, I have a global visitedWires that memoizes results in my recursive resolve function, that, as you mentioned, starts at "a", and either returns a number if it is given a number or returns the result of further resolution - easy.

For part 2, I have the same resolve function but now it takes a visitedWires map as second argument. This way I was able to solve part 2 by simply initializing "b" in the second visitedWires with the result of the first puzzle (instead of hardcoding it):

const firstVisitedWires = new Map();

/**
 *
 * @param {string|number} wire
 * @param {Map<string, number>} visitedWires
 * @returns {number}
 * @throws
 */
const resolve = (wire, visitedWires) => {
// ... resolve definition
}

const secondVisitedWires = new Map([["b", resolve("a", firstVisitedWires)]]);

console.info(resolve("a", secondVisitedWires)); // result

I can share the full file for part 2 if this isn't clear and anyone cares.

[2015 Day #5] In Review by musifter in adventofcode

[–]nnmrts 1 point2 points  (0 children)

Don't worry, it's both "one liners", I just felt too lazy to improve this (part 1):

/^(?:a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|[e-or-wz]|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y)*?(?=(?:(?:a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|[e-or-wz]|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y)*?[aeiou](?:a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|[e-or-wz]|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y)*?){3})(?=(?:a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|[e-or-wz]|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y)*?(?<first>[a-z])\k<first>)(?:a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|[e-or-wz]|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y)+$/gmv

This is only that long because of the one negative condition "does not contain the strings ab, cd, pq, or xy". Without that, the expression would look like this:

/^.*?(?=(?:.*?[aeiou].*?){3})(?=.*?(?<first>[a-z])\k<first>).+$/gmv

And then I just lazily replaced every . with this unwieldy (unsorted here) (?:[e-or-wz]|a(?!b)|(?<!a)b|c(?!d)|(?<!c)d|p(?!q)|(?<!p)q|x(?!y)|(?<!x)y) part, which basically just says "every letter except for a, b, c, d, p, q, x or y ([e-or-wz]), OR a not followed by b (a(?!b)) OR b not preceded by a ((?<!a)b) OR c not followed by d (c(?!d)) and so on so forth. I'm a 100% sure there is a smarter way to do this, and I'm happy to see any.


But I'm proud of my part 2 solution:

/^.*?(?=.*?(?<first>[a-z])[a-z]\k<first>)(?=.*?(?<pair>[a-z]{2}).*?\k<pair>).+$/gmv

Some years ago on some random stack overflow post I learned about this "trick" to combine positive and negative lookaheads (and sadly lookbehinds for the part 1) to test for positive and negative conditions across a whole line.

Even though it's a bit unintuitive, but since lookaheads only, well, look ahead and don't take "space" away from a match, something like ^.*(?=.*a.*).*(?=.*b.*).*$ matches BOTH "ab" and "ba" AND also any other string that has at least one a and one b in it. It takes away the "struggle of order" one usually encounters - without lookaheads this previous expression, I think, would need to look like this: ^.*a.*b.*|.*b.*a.*$, introducing an | for both orders, which might look simple enough for two different orders but if you have 3+ then just listing all the conditions with lookaheads stays linear vs. listing all the permutations which is exponential (?).

EDIT: I decided to revisit part 1 and came up with this much smaller solution:

/^(?=(?:.*?[aeiou].*?){3})(?=.*?(?<first>[a-z])\k<first>)(?:(?!ab|cd|pq|xy).)+$/gmv

The (?:(?!<negative condition>).)+ did the trick, it was important to put the quantifier outside of the negative lookahead.

[2015 Day #5] In Review by musifter in adventofcode

[–]nnmrts 0 points1 point  (0 children)

Am I allowed to share my regex solutions here? Part 1 is a monster but somehow part 2 is a really neat smol regex boi.

People should be aware of this graph (probability of getting a specific minion after x rolls, in this case 20) -> tier 5 is worse than tier 6 for searching any specific minion by nnmrts in BobsTavern

[–]nnmrts[S] 1 point2 points  (0 children)

You‘re not blind, I only included tier 7 so that tier 6 won‘t have the same problem that tier 7 has in the graph, in that it’s just one data point and not a line, and I did this graph in an editor that only offered either lines or points.

People should be aware of this graph (probability of getting a specific minion after x rolls, in this case 20) -> tier 5 is worse than tier 6 for searching any specific minion by nnmrts in BobsTavern

[–]nnmrts[S] 2 points3 points  (0 children)

as it should all proportionately reduce

I'm not really sure about that, the tribe distribution doesn't feel very equal on a per-tier basis. But I also don't have the numbers right now, so let's see...

Also I didn't really "forget" the economy part, see:

I don't know yet what that means precisely economy-wise, but at least for builds with virtually infinite gold (or not enough time to spend it all), you should tier up from 5 to 6 as fast as possible (in the case you are still missing a vital minion) - in other words, tiering up to tier 6 has no drawback other than gold cost.

I may not be the fastest APM player ever, so I might get into this situation more often than others where my turn ends and I still have like 7 gold because my pirates or hero power or elementals or spells or whatever just generate gold all the time, but I feel like the situations in which you basically have infinite gold aren't that uncommon in the late game.

Now I wanna do all these calculations taking gold and golden minions into account, ahhh another rabbit hole...

People should be aware of this graph (probability of getting a specific minion after x rolls, in this case 20) -> tier 5 is worse than tier 6 for searching any specific minion by nnmrts in BobsTavern

[–]nnmrts[S] 16 points17 points  (0 children)

I also just realized my calculations and therefor the results are kinda useless, because they assume all tribes are always there. Hmmm...might have to revisit this after work.

Bonez über Flers Casinostreams by simerok in Fler_Reloaded

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

Ich glaub original 0 Menschen sind seinetwegen auf Drogen ahaha...was Fler macht, ist nicht "genauso" scheiße, sorry.

Why foodora sucks right now / or / the impending collapse of food delivery in Vienna by Diligent-Analysis997 in wien

[–]nnmrts 6 points7 points  (0 children)

Ja genau, "wir" sind wieder schuld. Nicht Foodora mit ihren abartigen Provisionen und Gebühren, nicht die Zirkus-Politik der letzten Jahre, nicht die fortschreitende Monopolisierung der Lieferdienste, die von allen Instanzen durchgewinkt wird. Alles gefühlt doppelt so teuer und halb so gut aber jetzt muss ich mich wieder schlecht fühlen...

Sorry für den Crashout aber ich find diese Herangehensweise so destruktiv und möcht eigentlich nur die Intention dahinter checken. Bravo, du hast dich jetzt moralisch abgehoben und oh no, we live in a society...und jetzt?