Jump to content

Achilles numbers: Difference between revisions

Add Factor (with syntax highlighting! How nifty.)
m (syntax highlighting fixup automation)
(Add Factor (with syntax highlighting! How nifty.))
Line 1,695:
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang=factor>USING: assocs combinators.short-circuit formatting grouping io
kernel lists lists.lazy math math.functions math.primes.factors
prettyprint ranges sequences ;
 
: achilles? ( n -- ? )
group-factors values {
[ [ 1 > ] all? ]
[ unclip-slice [ simple-gcd ] reduce 1 = ]
} 1&& ;
 
: achilles ( -- list )
2 lfrom [ achilles? ] lfilter ;
 
: strong-achilles ( -- list )
achilles [ totient achilles? ] lfilter ;
 
: show ( n list -- ) ltake list>array 10 group simple-table. ;
 
: <order-of-magnitude> ( n -- range )
1 - 10^ dup 10 * [a..b) ;
 
"First 50 Achilles numbers:" print
50 achilles show nl
 
"First 30 strong Achilles numbers:" print
30 strong-achilles show nl
 
"Number of Achilles numbers with" print
{ 2 3 4 5 } [
dup <order-of-magnitude> [ achilles? ] count
"%d digits: %d\n" printf
] each</syntaxhighlight>
{{out}}
<pre>
First 50 Achilles numbers:
72 108 200 288 392 432 500 648 675 800
864 968 972 1125 1152 1323 1352 1372 1568 1800
1944 2000 2312 2592 2700 2888 3087 3200 3267 3456
3528 3872 3888 4000 4232 4500 4563 4608 5000 5292
5324 5400 5408 5488 6075 6125 6272 6728 6912 7200
 
First 30 strong Achilles numbers:
500 864 1944 2000 2592 3456 5000 10125 10368 12348
12500 16875 19652 19773 30375 31104 32000 33275 37044 40500
49392 50000 52488 55296 61731 64827 67500 69984 78608 80000
 
Number of Achilles numbers with
2 digits: 1
3 digits: 12
4 digits: 47
5 digits: 192
</pre>
 
=={{header|FreeBASIC}}==
1,808

edits

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