Prime numbers which contain 123: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 496:
 
Found 451 such primes under 1,000,000.
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
import Data.List ( isInfixOf )
 
isPrime :: Int -> Bool
isPrime n
|n < 2 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Int
root = floor $ sqrt $ fromIntegral n
condition :: Int -> Bool
condition n = isPrime n && isInfixOf "123" ( show n )
 
solution :: [Int]
solution = filter condition [2..99999]</syntaxhighlight>
{{out}}
<pre>
[1123,1231,1237,8123,11239,12301,12323,12329,12343,12347,12373,12377,12379,12391,17123,20123,22123,28123,29123,31123,31231,31237,34123,37123,40123,41231,41233,44123,47123,49123,50123,51239,56123,59123,61231,64123,65123,70123,71233,71237,76123,81233,81239,89123,91237,98123]
</pre>
 
260

edits