Brilliant numbers: Difference between revisions

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

edits