タグ

ブックマーク / www.noulakaz.net (1)

  • A regular expression to check for prime numbers

    Noulakaz The blog of Avinash, Christina, Anya and Kyan Meetoo. Regular expressions are extremely powerful. This is something I read at least once or twice every day while reading articles and blogs on the Web. While browsing today, I found this page which thoroughly describes the use of the regular expression /^1?$|^(11+?)\1+$/ in Perl to check if a number is prime or not!!! /^1?$|^(11+?)\1+$/ To

    rjj
    rjj 2022/03/06
    数字nをn個連続の文字に変換し(ここでは1を使ってるが何でもよい)、最初の任意個にマッチする部分とその1回以上の繰り返しにマッチする部分で、全体がマッチしたら合成数である。
  • 1