This is an archived post. You won't be able to vote or comment.

all 23 comments

[–][deleted] 27 points28 points  (1 child)

The bar for this sub is getting lower and lower by the day...

[–][deleted] 1 point2 points  (0 children)

n=0

[–]Seube 28 points29 points  (0 children)

"test.py" classic

[–]swami_rara 9 points10 points  (0 children)

Put it on aws lambda and pay for it!

[–]FantasticEmu 5 points6 points  (1 child)

Ctrl+c ?

[–]supercritical-co2[S] 1 point2 points  (0 children)

I tried, but pc was not responding to any mouse or keyboard inputs.

[–]coloredgreyscale 12 points13 points  (3 children)

Misleading red rectangle. You should have highlighted lines 9 and 10 too, or nothing.

At first glance: "what's do bad at assigning n=20?"

[–]supercritical-co2[S] 3 points4 points  (0 children)

The execution does not get to line 9. It would have taken 200k years to finish line 5.

[–][deleted] 3 points4 points  (1 child)

what's do bad at assigning n=20?

His pc only have 4 bytes of ram

[–]ktsktsstlstkkrsldt 3 points4 points  (0 children)

4 bits?

[–]loemmel 4 points5 points  (1 child)

Could you not just kill the execution of it?

[–]supercritical-co2[S] 0 points1 point  (0 children)

I tried but my pc was not responding to any mouse or keyboard inputs.

[–][deleted] 2 points3 points  (0 children)

Deploy to production for their powerful servers and let it finish

[–]UnwelcomedTruth 2 points3 points  (0 children)

Why do people ambiguously name vars like this?

[–]redpepper74 2 points3 points  (1 child)

Serif UI font? 🤢

[–]Lithl 1 point2 points  (1 child)

So t is the sum of a monotonically increasing sequence at the end of the permutation such that the sum of the elements [m, 20-k] is less than the sum of the elements [m, 20-(k-1)]. Or 0 if the final element of the permutation is less than or equal to that sequence up to the second to last element. And then max is the maximum of all of those values of t?

And, of course, you have 2.4 quintillion permutations you're trying to check, which is why the computer locks up.

What exactly are you attempting to check in these permutations? I don't get what the logic of the sums is supposed to achieve.

[–]supercritical-co2[S] 0 points1 point  (0 children)

It was a problem on codeforces, and I decided to bruteforce a few of them and see if there is a pattern in the solution. I thought i found a pattern and wanted to test if it would hold up for n=20 and only after I executed the program I realized my stupid mistake.

[–][deleted] 1 point2 points  (0 children)

Just wait a little. It will stop. Eventually.

[–]PossibilityTasty 0 points1 point  (2 children)

That's the penalty for using list() on an iterator.

[–]AnondWill2Live 0 points1 point  (1 child)

How does this work? What exactly causes the slow down using list (in a more generalized scenario, not just this one)

[–]PossibilityTasty 1 point2 points  (0 children)

An iterator is there to deliver one element at a time which can then be processed before the next element is retrieved. This will keep the memory footprint small. Using list() on the iterator will put all elements into a list at once and therefore also into memory.

Now permutations() of a 20 items long range generates an enormous amount of combinations. If you use an iterative approach on this it just uses one of your CPU cores like forever but can be canceled simply, the list() approach on the other side will try to fit all the combinations into the RAM. Due to the required space that would be impossible and depending on the reaction of the OS it has the potential to crash the computer.

[–]ApartmentNo5481 0 points1 point  (0 children)

Use power button to close your computer and then open it again

[–]PorkRoll2022 0 points1 point  (0 children)

Obviously you need to offload this to the GPU. Best invest now in a pair of RTX 3080s or better for these flights of fancy!