Achilles numbers: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
(Add Factor (with syntax highlighting! How nifty.))
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 48:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program achilleNumber.s */
Line 785:
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
{{libheader|ALGOL 68-primes}}
<syntaxhighlight 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 919:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang=ARM"arm Assemblyassembly">
/* ARM assembly Raspberry PI */
/* program achilleNumber.s */
Line 1,566:
{{trans|Wren}}
{{libheader|Boost}}
<syntaxhighlight lang="cpp">#include <algorithm>
#include <chrono>
#include <cmath>
Line 1,697:
=={{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 ;
Line 1,751:
 
=={{header|FreeBASIC}}==
<syntaxhighlight 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,862:
{{trans|Wren}}
Based on Version 2, takes around 19 seconds.
<syntaxhighlight lang="go">package main
 
import (
Line 2,007:
Implementation:
 
<syntaxhighlight lang=J"j">achilles=: (*/ .>&1 * 1 = +./)@(1{__&q:)"0
strong=: achilles@(5&p:)</syntaxhighlight>
 
Task examples:
 
<syntaxhighlight lang=J"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 2,048:
 
=={{header|Julia}}==
<syntaxhighlight lang="text">using Primes
 
isAchilles(n) = (p = [x[2] for x in factor(n).pe]; all(>(1), p) && gcd(p) == 1)
Line 2,114:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">ClearAll[PowerfulNumberQ, StrongAchillesNumberQ]
PowerfulNumberQ[n_Integer] := AllTrue[FactorInteger[n][[All, 2]], GreaterEqualThan[2]]
AchillesNumberQ[n_Integer] := Module[{divs},
Line 2,161:
Borrowed, and lightly modified, code from [[Powerful_numbers]]
{{libheader|ntheory}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use feature <say current_sub>;
Line 2,218:
9 digits: 24008</pre>
Here is a translation from Wren version 2, as an alternative.
<syntaxhighlight lang="perl">use strict;
use warnings;
 
Line 2,293:
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}}
<!--<syntaxhighlight lang=Phix"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,384:
 
=={{header|Python}}==
<syntaxhighlight lang="python">from math import gcd
from sympy import factorint
Line 2,452:
=={{header|Raku}}==
Timing is going to be system / OS dependent.
<syntaxhighlight lang=perl6"raku" line>use Prime::Factor;
use Math::Root;
 
Line 2,533:
=={{header|Rust}}==
{{trans|Wren}}
<syntaxhighlight 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,679:
===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!
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
Line 2,813:
 
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.
<syntaxhighlight lang="ecmascript">import "./set" for Set
import "./seq" for Lst
import "./fmt" for Fmt
Line 2,921:
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"xpl0">func GCD(N, D); \Return the greatest common divisor of N and D
int N, D; \numerator and denominator
int R;
10,333

edits