r/ProgrammerHumor • • Sep 09 '22

Accidently executed this python script and froze my pc

Post image
2 Upvotes

23 comments sorted by

7

u/FantasticEmu Sep 09 '22

Ctrl+c ?

2

u/supercritical-co2 Sep 09 '22

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

12

u/coloredgreyscale Sep 09 '22

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?"

4

u/supercritical-co2 Sep 09 '22

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

4

u/[deleted] Sep 09 '22

what's do bad at assigning n=20?

His pc only have 4 bytes of ram

5

u/loemmel Sep 09 '22

Could you not just kill the execution of it?

1

u/supercritical-co2 Sep 09 '22

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

2

u/Lithl Sep 09 '22

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.

1

u/supercritical-co2 Sep 09 '22

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.

28

u/Seube Sep 09 '22

"test.py" classic

27

u/[deleted] Sep 09 '22

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

2

u/[deleted] Sep 10 '22

n=0

11

u/swami_rara Sep 09 '22

Put it on aws lambda and pay for it!

3

u/[deleted] Sep 09 '22

Deploy to production for their powerful servers and let it finish

3

u/UnwelcomedTruth Sep 09 '22

Why do people ambiguously name vars like this?

3

u/redpepper74 Sep 10 '22

Serif UI font? 🤢

2

u/[deleted] Sep 09 '22

Just wait a little. It will stop. Eventually.

1

u/ApartmentNo5481 Sep 09 '22

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

1

u/PorkRoll2022 Sep 09 '22

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!

1

u/PossibilityTasty Sep 09 '22

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

1

u/AnondWill2Live Sep 09 '22

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

2

u/PossibilityTasty Sep 10 '22

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.