Lucas-Lehmer test for Mersenne numbers (Ruby)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Erlang | Haskell | J | Java | Lisp | Python | Ruby | Scheme

This program is a code dump.
Code dumps are articles with little or no documentation or rearrangement of code. Please help to turn it into a literate program. Also make sure that the source of this code does consent to release it under the MIT or public domain license.


def lucas_lehmer(p)
  s = 4
  m = (2 ** p) - 1
  for i in 1..(p - 2)
    s = ((s * s) - 2) % m
  end
  return (s == 0)
end
Download code
Views