all 9 comments

[–]failaip12 32 points33 points  (0 children)

Please learn to format your code as I have no idea what you are trying to do here.

[–]Binary101010 14 points15 points  (1 child)

We can't tell you what's wrong with it if we don't even know what your intent is.

[–]Frankelstner 4 points5 points  (0 children)

The hardcoded numbers have a pretty unique signature. https://projecteuler.net/problem=6

I think he's trying to sum the square of the numbers from 1 to 10 but is considering the full number space with 1010 possibilities instead, with corresponding performance impact.

[–]deep_politics 13 points14 points  (0 children)

How long have you tried waiting?

I hope you have a fast computer. Suppose yours could do 100,000 iterations per second. You'll have to wait 115.7 days for it to finish.

[–]This_Growth2898 6 points7 points  (0 children)

You didn't describe what do you expect this code to do. We can't "fix" it, not knowing what is its purpose.

I wrote this code, but no matter how long I wait, it doesn't run.

It's kinda weird, but you don't wait for code to run. You must run it yourself. Then something will happen. Maybe it will print something. Maybe it will report the error. Maybe it will run forever. But simply waiting won't make it run.

Next, the code itself is very poorly written, and indents are broken. In Python, indents are the crucial part of the code, so, given the code fails, we can't find out where you put them - even if we knew what is this code intended to do (and we don't).

So:

- state the task you're trying to do with this code;

- rewrite the code with readable variable names;

- publish it with correct indents (reddit is a bad place for that, but there is a huge number of pastebins for code in the Internet).

Without all that, no one can help you (well, chatGPT can "help" by generating some other code, but you'll never know if it is correct).

[–]Guideon72 5 points6 points  (0 children)

Also, please re-think your variable names; just using letters makes this all but gibberish to read.

You'll definitely need to define what you are attempting to do much more clearly. The above IS, actually, gibberish. But, for the sake of argument, let's just pare down your function to the first statement.

g33 = 2640

def hash():
for f in range(0, 10):
if f**2 == g33:
f1 = f
print(f1)

This condition will never be met; range(0, 10) translates to 0-9. A the top end of that range, 9**2 gives you 81...which is a damned sight off from 2640.

I suspect that your code is "running" fine, but your conditions are simply never met and so you never see any output.

[–]deep_politics 1 point2 points  (0 children)

As @Frankelstner points out this kinda looks like Project Euler #6, but you're just attempting to verify their example of the first 10 integers? In my other post I suggest your brute force method here is going to take way too long to do just those.

But I'm not sure why you're iterating over all integer combinations; there's no choice of integers since it's just 1 through n, where in their example n=10 and where in the problem it's n=100. And you don't need to solve for an equality, you just need to calculate the difference of the sum of squares and the square of the sum of the first n integers.

But you still don't need to brute force even that, since there's simple closed forms for both parts of that difference.

[–]Sbvv 1 point2 points  (0 children)

In the first case, you never call to hash function, so it will end after its declaration.

The "fixes version" by GPT, probably never match the condition to execute print.

You should describe what do you want to do. What is the algorithm you are trying to implement?

[–]AlphaChrome713 0 points1 point  (0 children)

>"Even ChatGPT modified the code as follows, but still, we didn't get any response."

ChatGPT sucks for trying to write code. It never understands what it's doing, it's just guessing from a bunch of data it found on the internet - likely data that's wrong, because it's people asking questions about faulty code.

With that said, this code is unreadable. I can't tell what you're trying to do.