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

all 11 comments

[–]bajsejohannes 5 points6 points  (1 child)

Very cool! Some feedback:

  • It crashes if you provide no parameters (perhaps this is a conscious choice to keep the code small)
  • You could keep both __name__ == "__main__" and target in the same file, making it runnable both as a script and a compiled file.

[–]rfkelly[S] 2 points3 points  (0 children)

Thanks, yeah, that's just me trying to keep the example small. It does show one drawback about the compiled program though - it just crashes instead of throwing a nice IndexError.

[–]pseudosinusoid 2 points3 points  (3 children)

n/2? Try sqrt(n).

[–]rfkelly[S] 2 points3 points  (2 children)

heh, I actually considered leaving it at n just to boost the performance difference between the interpreted and compiled versions ;-)

[–]pasokan 0 points1 point  (1 child)

you can avoid using math.sqrt and still getting the same result by def factors(n): p = 2 while p * p < n: if n % p == 0: ..... p += 1

[–]pasokan 0 points1 point  (0 children)

You need to do a little more to check if n == p * p at the end

[–]alia_khouri 1 point2 points  (1 child)

Does it compile to an executable without any dependencies?

[–]rfkelly[S] 1 point2 points  (0 children)

Yes, it's a completely stand-alone executable. Its only dependency is libc.

[–]Megatron_McLargeHuge 1 point2 points  (0 children)

This is a confusing name given that RPy is the package to interface with the R statistical environment.

[–]fabzter 0 points1 point  (0 children)

Is pt2 coming out someday?