Prime numbers which contain 123: Difference between revisions
m
→{{header|Julia}}: add stretch
m (→{{header|Factor}}: woops) |
m (→{{header|Julia}}: add stretch) |
||
Line 234:
<lang julia>using Primes
function containstringinbase(N, str, base, verbose = true)
arr = filter(n -> occursin(str, string(n, base=base)), primes(N))
verbose && foreach(p -> print(rpad(p[2], 6), p[1] % 12 == 0 ? "\n" : ""), enumerate(arr))
end
containstringinbase(100_000, "123", 10)
containstringinbase(1_000_000, "123", 10, false)
containstringinbase(1_000_000_000, "123", 10, false)
</lang>{{out}}
<pre>
Found 46 primes < 100000 which contain the string 123 in base 10 representation
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
Found 451 primes < 1000000 which contain the string 123 in base 10 representation.
Found 435002 primes < 1000000000 which contain the string 123 in base 10 representation.
</pre>
|