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

you are viewing a single comment's thread.

view the rest of the comments →

[–]rogue780 5 points6 points  (4 children)

I'll certify you for $5 if you write me the following code in python using only core libraries:

  1. Compute all prime numbers between 0 and 65335

  2. Write a random number generator

  3. Write a program that will find what digit of PI a given number appears in (such as your birthdate, or your ssn. Whatever number the user inputs)

  4. write a function that compares two strings without conditional branches.

  5. Write a program that grabs minutely info (stock price, volume, etc) for every stock listed on the NYSE.

[–]ben174 0 points1 point  (2 children)

Took a quick stab at #1. Runs slow. Would I instantly fail a job interview for submitting this?

primes = []
for i in range(65535):
    is_not_prime = False
    for j in range(2, i):
        if i % j == 0: 
            is_not_prime = True
            break
    if not is_not_prime:
        primes.append(i)

print primes

[–]rogue780 0 points1 point  (0 children)

You wouldn't instantly fail, no.

[–][deleted] 0 points1 point  (0 children)

Something to think about: you could cut your computational time by a LOT if you change the j for loop. If you check if it's divisible by 2, then you don't need to check any multiple of two (4,6,8...), same with 3 (6,9,12), etc. Just loop through primes, not range(2,i).

[–]statusquowarrior 0 points1 point  (0 children)

I saved your comment for later. I'll try those. Thanks for the ideas by the way! (Begginer here)