andreiursan/prime-numbers — pull request #1 by paterson (2014-05-06 16:09:54+00:00)
Title: Update one_liner.rb

Hey there :)

Using Fermat's Little Theorem is a much much more efficient way of checking if a number is prime than the way you were doing it. This should make prime checking, and prime generation a lot faster.

I ran numerous benchmarks on my machine (MacBook Pro):

https://gist.github.com/paterson/18493006a7c673e8beaa

(Results are in gist).

Anyway I was studying and got kinda bored. Should help, it's not always that one line pull request can make an up to 90000% speed improvement :)