Advertisement
Valleri

Non-Repeating Digits Regex

Aug 13th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.28 KB | None | 0 0
  1. <?php
  2. $n = 15;
  3. $printed = false;
  4. $regex = "/^(?:([0-9])(?!.*\\1))*$/";
  5. if ($n <= 102) {
  6.     echo "no";
  7. }
  8. else {
  9.     for ($i=102; $i < $n; $i++) {
  10.         if (preg_match($regex, strval($i))) {
  11.             echo $i . PHP_EOL;
  12.             $printed = true;
  13.         }
  14.     }
  15.     if (!$printed) {
  16.         echo "no";
  17.         }
  18. }
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement