Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Check For Primality With A Regexp

DZone's Guide to

Check For Primality With A Regexp

·
Free Resource
Original perl code here:

http://montreal.pm.org/tech/neil_kandalgaonkar.shtml


class Fixnum
  def prime?
    ('1' * self) !~ /^1?$|^(11+?)\1+$/
  end
end
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}