Wiki CgX

Parce que j'ai un cerveau, mais pas trop.

Outils pour utilisateurs

Outils du site


code:php:prime

Checker si un nombre est premier

Ca semble incroyable, avec une regexp !

<?php
 
$n = 1;
while ($n < 1000000)
    {
    if (!preg_match('/^1?$|^(11+?)\1+$/x', str_repeat('1', $n)))
        echo$n: Prime\n”;
    $n++;
    }
?>
code/php/prime.txt · Dernière modification : 21 Jun 2023 :: 13:37 de CgX