Jump to content

Achilles numbers: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 48:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<langsyntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program achilleNumber.s */
Line 764:
/***************************************************/
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
<pre>
First 50 Achilles Numbers:
Line 785:
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
{{libheader|ALGOL 68-primes}}
<langsyntaxhighlight lang=algol68>BEGIN # find Achilles Numbers: numbers whose prime factors p appear at least #
# twice (i.e. if p is a prime factor, so is p^2) and cannot be #
# expressed as m^k for any integer m, k > 1 #
Line 901:
OD
END
END</langsyntaxhighlight>
{{out}}
<pre>First 50 Achilles Numbers:
Line 919:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<langsyntaxhighlight lang=ARM Assembly>
/* ARM assembly Raspberry PI */
/* program achilleNumber.s */
Line 1,546:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
<pre>
First 50 Achilles Numbers:
Line 1,566:
{{trans|Wren}}
{{libheader|Boost}}
<langsyntaxhighlight lang=cpp>#include <algorithm>
#include <chrono>
#include <cmath>
Line 1,658:
std::chrono::duration<double> duration(end - start);
std::cout << "\nElapsed time: " << duration.count() << " seconds\n";
}</langsyntaxhighlight>
 
{{out}}
Line 1,697:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang=freebasic>Function GCD(n As Uinteger, d As Uinteger) As Uinteger
Return Iif(d = 0, n, GCD(d, n Mod d))
End Function
Line 1,784:
Print i; " digits:"; num
Next i
Sleep</langsyntaxhighlight>
{{out}}
<pre>First 50 Achilles numbers:
Line 1,808:
{{trans|Wren}}
Based on Version 2, takes around 19 seconds.
<langsyntaxhighlight lang=go>package main
 
import (
Line 1,917:
fmt.Printf("%2d digits: %d\n", d, ac)
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,953:
Implementation:
 
<langsyntaxhighlight lang=J>achilles=: (*/ .>&1 * 1 = +./)@(1{__&q:)"0
strong=: achilles@(5&p:)</langsyntaxhighlight>
 
Task examples:
 
<langsyntaxhighlight lang=J> 5 10$(#~ achilles) 1+i.10000 NB. first 50 achilles numbers
72 108 200 288 392 432 500 648 675 800
864 968 972 1125 1152 1323 1352 1372 1568 1800
Line 1,977:
192
+/achilles (+i.)/1 9*10^<:6
664</langsyntaxhighlight>
 
Explanation of the code:
Line 2,030:
 
teststrongachilles()
</langsyntaxhighlight>{{out}}
<pre>
First 50 Achilles numbers:
Line 2,060:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>ClearAll[PowerfulNumberQ, StrongAchillesNumberQ]
PowerfulNumberQ[n_Integer] := AllTrue[FactorInteger[n][[All, 2]], GreaterEqualThan[2]]
AchillesNumberQ[n_Integer] := Module[{divs},
Line 2,091:
]][[2, 1]]
 
Tally[IntegerLength /@ Select[Range[9999999], AchillesNumberQ]] // Grid</langsyntaxhighlight>
{{out}}
<pre>{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}
Line 2,107:
Borrowed, and lightly modified, code from [[Powerful_numbers]]
{{libheader|ntheory}}
<langsyntaxhighlight lang=perl>use strict;
use warnings;
use feature <say current_sub>;
Line 2,140:
my $c; $l == length and $c++ for @achilles;
say "$l digits: $c";
}</langsyntaxhighlight>
{{out}}
<pre>First 50 Achilles numbers:
Line 2,164:
9 digits: 24008</pre>
Here is a translation from Wren version 2, as an alternative.
<langsyntaxhighlight lang=perl>use strict;
use warnings;
 
Line 2,232:
for my $d (2..$maxDigits) {
printf "%2d digits: %d\n", $d, scalar getAchilles($d-1, $d)
}</langsyntaxhighlight>
Output is the same.
 
Line 2,239:
You can run this online [http://phix.x10.mx/p2js/achilles.htm here], though [slightly outdated and] you should expect a blank screen for about 9s.
{{trans|Wren}}
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- [join_by(fmt)]</span>
Line 2,300:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,330:
 
=={{header|Python}}==
<langsyntaxhighlight lang=python>from math import gcd
from sympy import factorint
Line 2,367:
 
test_strong_Achilles(50, 100)
</langsyntaxhighlight>{{out}}
<pre>
First 50 Achilles numbers:
Line 2,398:
=={{header|Raku}}==
Timing is going to be system / OS dependent.
<langsyntaxhighlight lang=perl6>use Prime::Factor;
use Math::Root;
 
Line 2,443:
say "$_ digits: " ~ +$achilles{$_} // 0 for 2..9;
 
printf "\n%.1f total elapsed seconds\n", now - INIT now;</langsyntaxhighlight>
{{out}}
<pre>First 50 Achilles numbers:
Line 2,479:
=={{header|Rust}}==
{{trans|Wren}}
<langsyntaxhighlight lang=rust>fn perfect_powers(n: u128) -> Vec<u128> {
let mut powers = Vec::<u128>::new();
let sqrt = (n as f64).sqrt() as u128;
Line 2,583:
let duration = t0.elapsed();
println!("\nElapsed time: {} milliseconds", duration.as_millis());
}</langsyntaxhighlight>
 
{{out}}
Line 2,625:
===Version 1 (Brute force)===
This finds the number of 6 digit Achilles numbers in 2.5 seconds, 7 digits in 51 seconds but 8 digits needs a whopping 21 minutes!
<langsyntaxhighlight lang=ecmascript>import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
Line 2,729:
System.print("%(i) digits: %(count)")
pow = pow * 10
}</langsyntaxhighlight>
 
{{out}}
Line 2,759:
 
Ridiculously fast compared to the previous method: 12 digits can now be reached in 1.03 seconds, 13 digits in 3.7 seconds, 14 digits in 12.2 seconds and 15 digits in 69 seconds.
<langsyntaxhighlight lang=ecmascript>import "./set" for Set
import "./seq" for Lst
import "./fmt" for Fmt
Line 2,833:
var ac = getAchilles.call(d-1, d).count
Fmt.print("$2d digits: $d", d, ac)
}</langsyntaxhighlight>
 
{{out}}
Line 2,867:
 
=={{header|XPL0}}==
<langsyntaxhighlight lang=XPL0>func GCD(N, D); \Return the greatest common divisor of N and D
int N, D; \numerator and denominator
int R;
Line 2,956:
IntOut(0, Cnt); CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
10,327

edits

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