r/codegolf • • Oct 16 '20

Prime numbers in 63 bytes of ruby

s=[n=2];ARGV[0].to_i.times{n+=1until s.all?{|m|n%m>0};s<<p(n)}

7 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/DutchOfBurdock Oct 16 '20

Don't ask me, I suck at maths. I almost always have a scientific calculator sat next to me coding. Just fun to do these things.

1

u/binarycat64 Oct 16 '20

It's honestly less of a question of math and more a question of computer architecture and compilers. Mod power of 2 can be done with bitshift, so is much faster, so that might make it worth it. on the other hand, it is more instructions and also more branches, so it might make it slower.