D
D
Dazai2021-07-13 01:07:37
Python
Dazai, 2021-07-13 01:07:37

How to shorten and optimize the algorithm?

I am solving the 23rd problem from the Euler project, I solved it in a rather greedy way, so greedy that I did not wait for the result ...
I ask you to help me reduce the code and optimize it, because after looking at other people's solutions, I understood the code, but did not understand why they did it some of the actions.

def izb(n:int):
    delt = []
    for i in range(1,n):
        if n % i == 0:
            delt.append(i)
    else:
        if sum(delt) > n:
            return True
        else:
            return False

def allizb():
    all_izb = []
    for i in range(12,28124):
        if izb(i) == True:
            all_izb.append(i)
    else:
        return all_izb

alizb = allizb()

i = 1 
otv = []

for i in range(12,28124):
    for g in alizb:
        for h in alizb:
            if i != (g+h):
                otv.append(i)
            print(i)
else:
    print( sum(otv ))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Imaev, 2021-07-14
@AIRC24

you can see here you
can use nimpy (uses NIM), pypy (JIT), Cython (C code compiles your program).
source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question