Brazilian numbers: Difference between revisions
Content added Content deleted
Line 1,173: | Line 1,173: | ||
The 100,000th Brazilian number: 110468 |
The 100,000th Brazilian number: 110468 |
||
</pre> |
</pre> |
||
=={{header|EasyLang}}== |
|||
proc sameDigits n b . r . |
|||
r = 1 |
|||
f = n mod b |
|||
repeat |
|||
n = n div b |
|||
until n = 0 |
|||
if n mod b <> f |
|||
r = 0 |
|||
break 1 |
|||
. |
|||
. |
|||
. |
|||
proc isBrazilian7 n . r . |
|||
# n >= 7 |
|||
r = 0 |
|||
if n mod 2 = 0 |
|||
r = 1 |
|||
break 1 |
|||
. |
|||
for b = 2 to n - 2 |
|||
call sameDigits n b h |
|||
if h = 1 |
|||
r = 1 |
|||
break 2 |
|||
. |
|||
. |
|||
. |
|||
proc isPrime4 n . r . |
|||
# n >= 4 |
|||
r = 0 |
|||
if n mod 2 = 0 or n mod 3 = 0 |
|||
break 1 |
|||
. |
|||
d = 5 |
|||
while d * d <= n |
|||
if n mod d = 0 |
|||
break 2 |
|||
. |
|||
d += 2 |
|||
if n mod d = 0 |
|||
break 2 |
|||
. |
|||
d += 4 |
|||
. |
|||
r = 1 |
|||
. |
|||
for kind$ in [ "" "odd" "prime" ] |
|||
print "First 20 " & kind$ & " Brazilian numbers:" |
|||
n = 7 |
|||
cnt = 1 |
|||
while cnt <= 20 |
|||
call isBrazilian7 n r |
|||
if r = 1 |
|||
write n & " " |
|||
cnt += 1 |
|||
. |
|||
if kind$ = "" |
|||
n += 1 |
|||
elif kind$ = "odd" |
|||
n += 2 |
|||
else |
|||
repeat |
|||
n += 2 |
|||
call isPrime4 n r |
|||
until r = 1 |
|||
. |
|||
. |
|||
. |
|||
print "" |
|||
. |
|||
<syntaxhighlight lang="easylang"> |
|||
</syntaxhighlight> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
===The functions=== |
===The functions=== |
||
Line 1,218: | Line 1,293: | ||
</pre> |
</pre> |
||
So up to 100,000 ~10% of numbers are non-Brazilian. The millionth Brazilian is 1084566 so less than 10% are non-Brazilian. Large non-Brazilians seem to be rare. |
So up to 100,000 ~10% of numbers are non-Brazilian. The millionth Brazilian is 1084566 so less than 10% are non-Brazilian. Large non-Brazilians seem to be rare. |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 development release 2019-07-10}} |
{{works with|Factor|0.99 development release 2019-07-10}} |