Brilliant numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 27: | Line 27: | ||
;* [https://www.numbersaplenty.com/set/brilliant_number Numbers Aplenty - Brilliant numbers] |
;* [https://www.numbersaplenty.com/set/brilliant_number Numbers Aplenty - Brilliant numbers] |
||
;* [[oeis:A078972|OEIS:A078972 - Brilliant numbers: semiprimes whose prime factors have the same number of decimal digits]] |
;* [[oeis:A078972|OEIS:A078972 - Brilliant numbers: semiprimes whose prime factors have the same number of decimal digits]] |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{libheader|ALGOL 68-primes}} |
{{libheader|ALGOL 68-primes}} |
||
<syntaxhighlight lang=algol68>BEGIN # Find Brilliant numbers - semi-primes whose two prime factors have # |
<syntaxhighlight lang="algol68">BEGIN # Find Brilliant numbers - semi-primes whose two prime factors have # |
||
# the same number of digits # |
# the same number of digits # |
||
PR read "primes.incl.a68" PR # include prime utilities # |
PR read "primes.incl.a68" PR # include prime utilities # |
||
Line 106: | Line 103: | ||
First brilliant number >= 1000000: 1018081 at position 10538 |
First brilliant number >= 1000000: 1018081 at position 10538 |
||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
<syntaxhighlight lang=rebol>brilliant?: function [x][ |
<syntaxhighlight lang="rebol">brilliant?: function [x][ |
||
pf: factors.prime x |
pf: factors.prime x |
||
and? -> 2 = size pf |
and? -> 2 = size pf |
||
Line 164: | Line 160: | ||
First brilliant number >= 10 ^ 5 is 100013 at position 2505 |
First brilliant number >= 10 ^ 5 is 100013 at position 2505 |
||
First brilliant number >= 10 ^ 6 is 1018081 at position 10538</pre> |
First brilliant number >= 10 ^ 6 is 1018081 at position 10538</pre> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{libheader|Primesieve}} |
{{libheader|Primesieve}} |
||
<syntaxhighlight lang=cpp>#include <algorithm> |
<syntaxhighlight lang="cpp">#include <algorithm> |
||
#include <chrono> |
#include <chrono> |
||
#include <iomanip> |
#include <iomanip> |
||
Line 281: | Line 276: | ||
Elapsed time: 1.50048 seconds |
Elapsed time: 1.50048 seconds |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2022-04-03}} |
{{works with|Factor|0.99 2022-04-03}} |
||
<syntaxhighlight lang=factor>USING: assocs formatting grouping io kernel lists lists.lazy |
<syntaxhighlight lang="factor">USING: assocs formatting grouping io kernel lists lists.lazy |
||
math math.functions math.primes.factors prettyprint |
math math.functions math.primes.factors prettyprint |
||
project-euler.common sequences ; |
project-euler.common sequences ; |
||
Line 325: | Line 319: | ||
First brilliant number >= 1000000: 1018081 at position 10538 |
First brilliant number >= 1000000: 1018081 at position 10538 |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 437: | Line 430: | ||
First >= 10,000,000,000,000 is 34,896,253,010 in the series: 10,000,000,000,073 |
First >= 10,000,000,000,000 is 34,896,253,010 in the series: 10,000,000,000,073 |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<syntaxhighlight lang=haskell>import Control.Monad (join) |
<syntaxhighlight lang="haskell">import Control.Monad (join) |
||
import Data.Bifunctor (bimap) |
import Data.Bifunctor (bimap) |
||
import Data.List (intercalate, transpose) |
import Data.List (intercalate, transpose) |
||
Line 501: | Line 493: | ||
(242,10201) |
(242,10201) |
||
(2505,100013)</pre> |
(2505,100013)</pre> |
||
=={{header|J}}== |
=={{header|J}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j">oprimes=: {{ NB. all primes of order y |
||
p:(+i.)/-/\ p:inv +/\1 9*10^y |
p:(+i.)/-/\ p:inv +/\1 9*10^y |
||
}} |
}} |
||
Line 518: | Line 509: | ||
Task examples: |
Task examples: |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j"> 10 10 $brillseq 2 |
||
4 6 9 10 14 15 21 25 35 49 |
4 6 9 10 14 15 21 25 35 49 |
||
121 143 169 187 209 221 247 253 289 299 |
121 143 169 187 209 221 247 253 289 299 |
||
Line 539: | Line 530: | ||
Stretch goal (results are order, index, value): |
Stretch goal (results are order, index, value): |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="j"> (brillseq 4) (],.(I. 10^]) ([,.{) [) ,7 |
||
7 124363 10000043 |
7 124363 10000043 |
||
(brillseq 5) (],.(I. 10^]) ([,.{) [) 8 9 |
(brillseq 5) (],.(I. 10^]) ([,.{) [) 8 9 |
||
8 573928 100140049 |
8 573928 100140049 |
||
9 7407840 1000000081</syntaxhighlight> |
9 7407840 1000000081</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
Uses the PrimeGenerator class from [[Extensible prime generator#Java]]. |
Uses the PrimeGenerator class from [[Extensible prime generator#Java]]. |
||
<syntaxhighlight lang=java>import java.util.*; |
<syntaxhighlight lang="java">import java.util.*; |
||
public class BrilliantNumbers { |
public class BrilliantNumbers { |
||
Line 654: | Line 644: | ||
First brilliant number >= 10^15 is 1,000,000,000,000,003 at position 2,601,913,448,897 |
First brilliant number >= 10^15 is 1,000,000,000,000,003 at position 2,601,913,448,897 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang=julia> |
<syntaxhighlight lang="julia"> |
||
using Primes |
using Primes |
||
Line 705: | Line 694: | ||
First >= 1000000000 is 7407841 in the series: 1000000081 |
First >= 1000000000 is 7407841 in the series: 1000000081 |
||
</pre> |
</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="mathematica">ClearAll[PrimesDecade] |
||
PrimesDecade[n_Integer] := Module[{bounds}, |
PrimesDecade[n_Integer] := Module[{bounds}, |
||
bounds = {PrimePi[10^n] + 1, PrimePi[10^(n + 1) - 1]}; |
bounds = {PrimePi[10^n] + 1, PrimePi[10^(n + 1) - 1]}; |
||
Line 742: | Line 730: | ||
100140049 573929 |
100140049 573929 |
||
1000000081 7407841</pre> |
1000000081 7407841</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
<syntaxhighlight lang=perl>use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 792: | Line 779: | ||
=== Faster approach === |
=== Faster approach === |
||
{{trans|Sidef}} |
{{trans|Sidef}} |
||
<syntaxhighlight lang=perl>use 5.020; |
<syntaxhighlight lang="perl">use 5.020; |
||
use strict; |
use strict; |
||
use warnings; |
use warnings; |
||
Line 890: | Line 877: | ||
First brilliant number >= 10^13 is 10000000000073 at position 34896253010 |
First brilliant number >= 10^13 is 10000000000073 at position 34896253010 |
||
</pre> |
</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
Line 896: | Line 882: | ||
Replaced with C++ translation; much faster and now goes comfortably to 1e15 even on 32 bit. |
Replaced with C++ translation; much faster and now goes comfortably to 1e15 even on 32 bit. |
||
You can run this online [http://phix.x10.mx/p2js/brilliant.htm here]. |
You can run this online [http://phix.x10.mx/p2js/brilliant.htm here]. |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\BrilliantNumbers.exw |
-- demo\rosetta\BrilliantNumbers.exw |
||
Line 997: | Line 983: | ||
"3.3s" |
"3.3s" |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Using primesieve and numpy modules. If program is run to above 10<sup>18</sup> it overflows 64 bit integers (that's what primesieve module backend uses internally). |
Using primesieve and numpy modules. If program is run to above 10<sup>18</sup> it overflows 64 bit integers (that's what primesieve module backend uses internally). |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="python">from primesieve.numpy import primes |
||
from math import isqrt |
from math import isqrt |
||
import numpy as np |
import numpy as np |
||
Line 1,070: | Line 1,055: | ||
Above 10^16: 10000001400000049 at #13163230391313 |
Above 10^16: 10000001400000049 at #13163230391313 |
||
Above 10^17: 100000000000000831 at #201431415980419</pre> |
Above 10^17: 100000000000000831 at #201431415980419</pre> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
1 through 7 are fast. 8 and 9 take a bit longer. |
1 through 7 are fast. 8 and 9 take a bit longer. |
||
<syntaxhighlight lang=raku line>use Lingua::EN::Numbers; |
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers; |
||
# Find an abundance of primes to use to generate brilliants |
# Find an abundance of primes to use to generate brilliants |
||
Line 1,113: | Line 1,097: | ||
First >= 100,000,000 is 573929ᵗʰ in the series: 100,140,049 |
First >= 100,000,000 is 573929ᵗʰ in the series: 100,140,049 |
||
First >= 1,000,000,000 is 7407841ˢᵗ in the series: 1,000,000,081</pre> |
First >= 1,000,000,000 is 7407841ˢᵗ in the series: 1,000,000,081</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
<syntaxhighlight lang=rust>// [dependencies] |
<syntaxhighlight lang="rust">// [dependencies] |
||
// primal = "0.3" |
// primal = "0.3" |
||
// indexing = "0.4.1" |
// indexing = "0.4.1" |
||
Line 1,231: | Line 1,214: | ||
Elapsed time: 1515 milliseconds |
Elapsed time: 1515 milliseconds |
||
</pre> |
</pre> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang=ruby>func is_briliant_number(n) { |
<syntaxhighlight lang="ruby">func is_briliant_number(n) { |
||
n.is_semiprime && (n.factor.map{.len}.uniq.len == 1) |
n.is_semiprime && (n.factor.map{.len}.uniq.len == 1) |
||
} |
} |
||
Line 1,297: | Line 1,279: | ||
First brilliant number >= 10^12 is 1000006000009 at position 2409600866 |
First brilliant number >= 10^12 is 1000006000009 at position 2409600866 |
||
</pre> |
</pre> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
Magnitudes of 1 to 3 is decent, 4 and beyond becomes slow. |
Magnitudes of 1 to 3 is decent, 4 and beyond becomes slow. |
||
<syntaxhighlight lang=rebol>// Refs: |
<syntaxhighlight lang="rebol">// Refs: |
||
// https://www.geeksforgeeks.org/sieve-of-eratosthenes/?ref=leftbar-rightbar |
// https://www.geeksforgeeks.org/sieve-of-eratosthenes/?ref=leftbar-rightbar |
||
// https://developer.apple.com/documentation/swift/array/init(repeating:count:)-5zvh4 |
// https://developer.apple.com/documentation/swift/array/init(repeating:count:)-5zvh4 |
||
Line 1,418: | Line 1,399: | ||
First brilliant number >= 100000: 100013 at position 2505 |
First brilliant number >= 100000: 100013 at position 2505 |
||
First brilliant number >= 1000000: 1018081 at position 10538</pre> |
First brilliant number >= 1000000: 1018081 at position 10538</pre> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
<syntaxhighlight lang=ecmascript>import "./math" for Int |
<syntaxhighlight lang="ecmascript">import "./math" for Int |
||
import "./seq" for Lst |
import "./seq" for Lst |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
Line 1,497: | Line 1,477: | ||
First >= 1,000,000,000,000 is 2,409,600,866th in the series: 1,000,006,000,009 |
First >= 1,000,000,000,000 is 2,409,600,866th in the series: 1,000,006,000,009 |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="xpl0"> |
||
func NumDigits(N); \Return number of digits in N |
func NumDigits(N); \Return number of digits in N |
||
int N, Cnt; |
int N, Cnt; |