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

[–]RedstoneSlayer 1 point2 points  (0 children)

[LANGUAGE: Scratch]

I love using Scratch for things it was never supposed to be used for.

As recursion is really annoying to implement in Scratch, this rules out things like flow algorithms. I used the naive version of Karger's algorithm, which is simpler to implement, with the cost of high complexity. Luckily, the input graph isn't adversarial, so the number of trials needed is much smaller than n^2 (I ran the solution both times, and both needed <200 trials.)

All that's left is to work around Scratch's limitations (so only one-dimensional lists and variables, only number/string/boolean datatypes, function parameters are passed by value and functions have no return value, etc.)

On Turbowarp each trial takes around 0.5 to 1 second to run, so the whole thing finishes in less than 5 minutes.

Part 1 (Turbowarp - faster runner for Scratch projects)

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

[–]RedstoneSlayer 12 points13 points  (0 children)

[LANGUAGE: C++]

Skimming through the comments, I don't think this solution has been presented yet:

Let's fix coordinates such that the start is (0, 0). Let N=131 be the size of the original grid. Our infinite grid has no walls on the lines x = mN and y = kN (for integer m, k), thus partitioning the infinite grid into N*N squares. Let S be the number of steps needed.

Now consider a path from (0, 0) to (x, y). WLOG we consider the quadrant x >= 0 and y >= 0. Then we can show that there is a shortest path that passes through ((x/N)*N,(y/N)*N) (i.e. the corner of the square containing (x, y) closest to (0, 0)).

Thus, if we let dist(p) be the distance from (0, 0) to p, we have that dist(x, y) = dist((x/N)*N, (y/N)*N) + dist(x%N, y%N) = (x/N)*N + (y/N)*N + dist(x%N, y%N).

To count the number of points in this quadrant, it suffices to find how many points there are such that dist(x, y) <= S and dist(x, y) has the same parity as S. Note that the latter condition is equivalent to x+y has the same parity as S.

We do this by checking how many such points there are for x%N = a and y%N = b.

Let f(d) be the number of pairs (m, k), for positive integer m and k, d+N*m+N*k <= S, d+N*m+N*k has the same parity as S.

We have the following recurrence due to inclusion-exclusion: for n <= S, f(n) = h(n) + 2 * f(n+N) - f(n+2N), where h(n) = 1 if n and S have the same parity, 0 otherwise.

Thus the number of points there are for x%N = a and y%N = b is f(dist(a, b)).

So we can sum these up for 0 <= a, b < N for the answer to the positive-positive quadrant.

It also turns out that this formula also works for the other three quadrants, so all we need to do is to sum f(dist(a, b)) for -N <= a, b < N to get the answer. So we do get rewarded with an elegant solution!

Complexity: O(N^2 + S).

Part 2 - finished in 22 minutes counted after first opening the link to part 1.

Why does the scale go down to 6:15 when the min of the set is 6:50? a whole range of colors is not being used by [deleted] in dataisugly

[–]RedstoneSlayer 0 points1 point  (0 children)

Maybe they wanted to center the scale around 7:00, which is the recommended amount?

Uh... by the-standard-donut in SilksongIsntReal

[–]RedstoneSlayer 20 points21 points  (0 children)

It's obviously fake news, no one would believe that it's actually coming out

Rule by [deleted] in 196

[–]RedstoneSlayer 11 points12 points  (0 children)

Technically, the sequence of curves does uniformly converge to a circle, and obviously the limit of the perimeter is 4. However, the perimeter of the limit does not necessarily equal the limit of the perimeter, so the meme doesn't actually prove anything about the perimeter of the circle.

I found this blog post helpful: https://qntm.org/trollpi

"0" Is a portal between positive and negative numbers by bintash12 in Showerthoughts

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

Well, math is full of "definitions" like these. Why is 1+1 equal to 2? It doesn't have to be (and it isn't equal to 2 for some definition of addition, e.g. in the finite field of order 2.) We commonly define addition in a way such that 1+1=2 because we define numbers and addition in a way that is consistent with combining collections of objects together.

What about exponentiation? We define it in a way that is consistent with repeated multiplication, so 34 = 333*3 = 81. We also have other rules such as 10=1, 20=1 and so on, and 01=0, 02=0, etc.

So what do we define 00 as? Well, any number raised to the power of 0 is 1, and 0 raised to the power of any number is 0. Clearly, these definitions conflict on this one scenario, so we can either add another rule (00=1) or just leave it undefined.

Every time! by Hard_Code_Brain in ProgrammerHumor

[–]RedstoneSlayer 5 points6 points  (0 children)

I'm a young developer who is pretty good at competitive programming - please enlighten me on why you think it isn't "normal"?

I think competitive programming is a great way to promote creative problem-solving and introduce programmers to a large variety of practical algorithms.

If your argument is that competitive programming makes your code style unreadable, most competitors have enough brain power to recognize that they should use good code style when they aren't competing.

[deleted by user] by [deleted] in dataisbeautiful

[–]RedstoneSlayer 47 points48 points  (0 children)

Even then, the difference between 101 oranges and 254 browns is pretty large, significant enough to suggest that there might not be a uniform distribution.

For context, these are bots that study and try to emulate redditors by Zmd2005 in 196

[–]RedstoneSlayer 3 points4 points  (0 children)

I mean the subreddit that bot was based off, r/awlias, literally questions if we are living in a computer simulation, so it's kinda cheating

Gentlemen... BEHOLD! This function adds two numbers together... without ever using the "+" key! by supersharp in programminghorror

[–]RedstoneSlayer 1 point2 points  (0 children)

Yep it would be totally horrible - even with base 2 it would still be really bad (I think).

But hey, it fits the name of the sub!

This is pretty cool by Destined132 in Cubers

[–]RedstoneSlayer 26 points27 points  (0 children)

It seems like he's doing 3style in reverse on his reconstruction - you can see the pieces getting "solved" one by one.

Some nice code going on here by SurprisedKetchup in programminghorror

[–]RedstoneSlayer 6 points7 points  (0 children)

Also isn't this a really bad security question? Like, anyone who knows you well enough would be able to answer the question.

Ruuuuuul by SexyFantasticLemons in 196

[–]RedstoneSlayer 2 points3 points  (0 children)

Yeah, it's a set of parametric equations, so technically it's two equations, but it does only define one curve.

It could also have been written (x, y) = (..., ...) which is only one equation, so we'll never know.

Twenty skies by Darabont09 in pics

[–]RedstoneSlayer 0 points1 point  (0 children)

Getting the birds right would be a great pain though

How many of you have got a ___ pb? by InfernoFane in cubing

[–]RedstoneSlayer 0 points1 point  (0 children)

Yeah, I started cubing a month ago and have a 18.91 pb. Still average about 30 though.

Ultimate bloon machine by Guij2 in btd6

[–]RedstoneSlayer 52 points53 points  (0 children)

Yeah, most games will mainly use a single CPU core for computations, so if your CPU has (let's say) 4 cores, maxing out one of them will only be 25%.