by ichabod801 » Sat Mar 09, 2013 2:26 pm
The webpage wouldn't render at work. I'm assuming it's an IE issue, but still. That first question (print as many primes as you can) was just begging for an infinite loop, so I gave it one:
- Code: Select all
primes = [2, 3]
print(2)
print(3)
n = 4
while True:
for p in primes:
if not n % p:
break
else:
primes.append(n)
print(n)
n += 1
That did not run forever, as it should have. Not that I didn't expect a catch for infinite loops, but that would seem to bias the web site against Python. If the check for infinite loops is time based, then for any given Python implementation of the problem you could make a faster C++ implementation with similar code that would print more primes in the given time.
It gave me a score of 1094100 for that, but I'm not sure what that means. When I did an initial test of just:
- Code: Select all
print(2)
print(3)
it gave me a score of 200. Maybe that means I printed 10941 primes before the cutoff? It did say I was 35th on the leader board, but the top ten (or four, there were a lot of ties for fourth) were all C or C++.
That was with the Python 3 setting, so it's working for me at least.
Craig "Ichabod" O'Brien
Minimalist, buddhist, theist, and programmer
Current languages: Python, SAS, and C++
Previous serious languages: R, Java, VBA, Lisp, HyperTalk, BASIC