same implemention on java and python, two very different running times
Question: My friend and I made a program to do the same thing, his was in java and mine
in python. The question we had to solve was "What is the smallest positive
number that is evenly divisible by all of the numbers from 1 to 20?" We both
got the right answers, and as far as I can tell implemented pretty similarly,
but his one finished in a about three seconds while mine took over a minute.
Can anyone possibly see why this happened? Just to be clear, I know that both
ways aren't the best, but they both worked and what I'm interested in is
seeing why there was such a significant time difference. Thanks!

Java:

    
    
    for (int i = 1; i > 0; i++) {
        for (int j = 1; j < 21; j++) { 
            if (i % j != 0) {                  
                break;
            }
            if (j == 20) {
                System.out.println("ANSWER: " + i);
                System.exit(0);
            }
        }
    }
    

python:

    
    
    e=1
    while e > 0 :
        num =1
        while num < 21:
    
            if e % num != 0:
                break
            num += 1
    
    
    
        if num == 21:
            print e
            break
        e += 1
    


Answer: While your implementation in python looks similar, the indentation is very
important. In the Java version, this block:

    
    
    if(j == 20){
        System.out.println("ANSWER: " + i);
        System.exit(0);
    }
    

is inside the second for loop. In the python version, the block:

    
    
    if num == 21:
        print e
        break
    

is outside the second while loop.

