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)}

6 Upvotes

18 comments sorted by

View all comments

Show parent comment

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.