Jump to content

Brazilian numbers: Difference between revisions

no edit summary
(Added Forth solution)
No edit summary
Line 2,339:
First 20 prime Brazillion numbers:
7 13 31 43 73 127 157 211 241 307 421 463 601 757 1093 1123 1483 1723 2551 2801</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang wolfram>brazilianQ[n_Integer /; n>6 ] := AnyTrue[
Range[2, n-2],
MatchQ[IntegerDigits[n, #], {x_ ...}] &
Select[Range[100], brazilianQ, 20]
Select[Range[100], brazilianQ@# && OddQ@# &, 20]
Select[Range[10000], brazilianQ@# && PrimeQ@# &, 20]
</lang>
{{out}}
<pre>{7, 8, 10, 12, 13, 14, 15, 16, 18, 20, 21, 22, 24, 26, 27, 28, 30, 31, 32, 33}
{7, 13, 15, 21, 27, 31, 33, 35, 39, 43, 45, 51, 55, 57, 63, 65, 69, 73, 75, 77}
{7, 13, 31, 43, 73, 127, 157, 211, 241, 307, 421, 463, 601, 757, 1093, 1123, 1483, 1723, 2551, 2801}</pre>
 
=={{header|Nim}}==
Line 3,864 ⟶ 3,878:
</pre>
The point of utilizing a sieve is that it caches or memoizes the results. Since we are going through a long sequence of possible Brazilian numbers, it pays off to check the prime factoring in an efficient way, rather than one at a time.
 
=={{header|Wolfram Language}}==
<lang wolfram>brazilianQ[n_Integer /; n>6 ] := AnyTrue[
Range[2, n-2],
MatchQ[IntegerDigits[n, #], {x_ ...}] &
Select[Range[100], brazilianQ, 20]
Select[Range[100], brazilianQ@# && OddQ@# &, 20]
Select[Range[10000], brazilianQ@# && PrimeQ@# &, 20]
</lang>
{{out}}
<pre>{7, 8, 10, 12, 13, 14, 15, 16, 18, 20, 21, 22, 24, 26, 27, 28, 30, 31, 32, 33}
{7, 13, 15, 21, 27, 31, 33, 35, 39, 43, 45, 51, 55, 57, 63, 65, 69, 73, 75, 77}
{7, 13, 31, 43, 73, 127, 157, 211, 241, 307, 421, 463, 601, 757, 1093, 1123, 1483, 1723, 2551, 2801}</pre>
 
=={{header|Wren}}==
1,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.