Brilliant numbers

From Rosetta Code
Revision as of 18:17, 17 April 2022 by Thundergnat (talk | contribs) (Promote. multiple implementations, no questions)
Task
Brilliant numbers
You are encouraged to solve this task according to the task description, using any language you may know.

Brilliant numbers are a subset of semiprime numbers. Specifically, they are numbers that are the product of exactly two prime numbers that both have the same number of digits when expressed in base 10.

Brilliant numbers are useful in cryptography and when testing prime factoring algorithms.


E.G.
  • 3 × 3 (9) is a brilliant number.
  • 2 × 7 (14) is a brilliant number.
  • 113 × 691 (78083) is a brilliant number.
  • 2 × 31 (62) is semiprime, but is not a brilliant number (different number of digits in the two factors).


Task
  • Find and display the first 100 brilliant numbers.
  • For the orders of magnitude 1 through 6, find and show the first brilliant number greater than or equal to the order of magnitude, and, its position in the series (or the count of brilliant numbers up to that point).


Stretch
  • Continue for larger orders of magnitude.


See also


Go

Translation of: Wren
Library: Go-rcu

<lang go>package main

import (

   "fmt"
   "math"
   "rcu"
   "sort"

)

var primes = rcu.Primes(1e8 - 1)

type res struct {

   bc   interface{}
   next int

}

func getBrilliant(digits, limit int, countOnly bool) res {

   var brilliant []int
   count := 0
   pow := 1
   next := math.MaxInt
   for k := 1; k <= digits; k++ {
       var s []int
       for _, p := range primes {
           if p >= pow*10 {
               break
           }
           if p > pow {
               s = append(s, p)
           }
       }
       for i := 0; i < len(s); i++ {
           for j := i; j < len(s); j++ {
               prod := s[i] * s[j]
               if prod < limit {
                   if countOnly {
                       count++
                   } else {
                       brilliant = append(brilliant, prod)
                   }
               } else {
                   if next > prod {
                       next = prod
                   }
                   break
               }
           }
       }
       pow *= 10
   }
   if countOnly {
       return res{count, next}
   }
   return res{brilliant, next}

}

func main() {

   fmt.Println("First 100 brilliant numbers:")
   brilliant := getBrilliant(2, 10000, false).bc.([]int)
   sort.Ints(brilliant)
   brilliant = brilliant[0:100]
   for i := 0; i < len(brilliant); i++ {
       fmt.Printf("%4d ", brilliant[i])
       if (i+1)%10 == 0 {
           fmt.Println()
       }
   }
   fmt.Println()
   for k := 1; k <= 13; k++ {
       limit := int(math.Pow(10, float64(k)))
       r := getBrilliant(k, limit, true)
       total := r.bc.(int)
       next := r.next
       climit := rcu.Commatize(limit)
       ctotal := rcu.Commatize(total + 1)
       cnext := rcu.Commatize(next)
       fmt.Printf("First >= %18s is %14s in the series: %18s\n", climit, ctotal, cnext)
   }

}</lang>

Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49 
 121  143  169  187  209  221  247  253  289  299 
 319  323  341  361  377  391  403  407  437  451 
 473  481  493  517  527  529  533  551  559  583 
 589  611  629  649  667  671  689  697  703  713 
 731  737  767  779  781  793  799  803  817  841 
 851  869  871  893  899  901  913  923  943  949 
 961  979  989 1003 1007 1027 1037 1067 1073 1079 
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241 
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369 

First >=                 10 is              4 in the series:                 10
First >=                100 is             11 in the series:                121
First >=              1,000 is             74 in the series:              1,003
First >=             10,000 is            242 in the series:             10,201
First >=            100,000 is          2,505 in the series:            100,013
First >=          1,000,000 is         10,538 in the series:          1,018,081
First >=         10,000,000 is        124,364 in the series:         10,000,043
First >=        100,000,000 is        573,929 in the series:        100,140,049
First >=      1,000,000,000 is      7,407,841 in the series:      1,000,000,081
First >=     10,000,000,000 is     35,547,995 in the series:     10,000,600,009
First >=    100,000,000,000 is    491,316,167 in the series:    100,000,000,147
First >=  1,000,000,000,000 is  2,409,600,866 in the series:  1,000,006,000,009
First >= 10,000,000,000,000 is 34,896,253,010 in the series: 10,000,000,000,073

J

<lang J>oprimes=: {{ NB. all primes of order y

 p:(+i.)/-/\ p:inv +/\1 9*10^y

}}

obrill=: {{ NB. all brilliant numbers of order y primes

 ~.,*/~oprimes y

}}

brillseq=: {{ NB. sequences of brilliant numbers up through order y-1 primes

 /:~;obrill each i.y

}}</lang>

Task examples:

<lang 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
319  323  341  361  377  391  403  407  437  451
473  481  493  517  527  529  533  551  559  583
589  611  629  649  667  671  689  697  703  713
731  737  767  779  781  793  799  803  817  841
851  869  871  893  899  901  913  923  943  949
961  979  989 1003 1007 1027 1037 1067 1073 1079

1081 1121 1139 1147 1157 1159 1189 1207 1219 1241 1247 1261 1271 1273 1333 1343 1349 1357 1363 1369 NB. order, index, value

  (brillseq 4) (],.(I. 10^]) ([,.{) [) 1 2 3 4 5 6

1 3 10 2 10 121 3 73 1003 4 241 10201 5 2504 100013 6 10537 1018081</lang>

Stretch goal (results are order, index, value): <lang J> (brillseq 4) (],.(I. 10^]) ([,.{) [) ,7 7 124363 10000043

  (brillseq 5) (],.(I. 10^]) ([,.{) [) 8 9

8 573928 100140049 9 7407840 1000000081</lang>

Julia

<lang julia> using Primes

function isbrilliant(n)

   p = factor(n).pe
   return (length(p) == 1 && p[1][2] == 2) ||
      length(p) == 2 && ndigits(p[1][1]) == ndigits(p[2][1]) && p[1][2] == p[2][2] == 1

end

function testbrilliants()

   println("First 100 brilliant numbers:")
   foreach(p -> print(lpad(p[2], 5), p[1] % 20 == 0 ? "\n" : ""),
      enumerate(filter(isbrilliant, 1:1370)))
   bcount, results, positions = 0, zeros(Int, 9), zeros(Int, 9)
   for n in 1:10^10
       if isbrilliant(n)
           bcount += 1
           for i in 1:9
               if n >= 10^i && results[i] == 0
                   results[i] = n
                   positions[i] = bcount
                   println("First >=", lpad(10^i, 12), " is", lpad(bcount, 8),
                      " in the series: $n")
               end
           end
       end
   end
   return results, positions

end

testbrilliants()

</lang>

Output:
First 100 brilliant numbers:
    4    6    9   10   14   15   21   25   35   49  121  143  169  187  209  221  247  253  289  299
  319  323  341  361  377  391  403  407  437  451  473  481  493  517  527  529  533  551  559  583
  589  611  629  649  667  671  689  697  703  713  731  737  767  779  781  793  799  803  817  841
  851  869  871  893  899  901  913  923  943  949  961  979  989 1003 1007 1027 1037 1067 1073 1079
 1081 1121 1139 1147 1157 1159 1189 1207 1219 1241 1247 1261 1271 1273 1333 1343 1349 1357 1363 1369
First >=          10 is       4 in the series: 10
First >=         100 is      11 in the series: 121
First >=        1000 is      74 in the series: 1003
First >=       10000 is     242 in the series: 10201
First >=      100000 is    2505 in the series: 100013
First >=     1000000 is   10538 in the series: 1018081
First >=    10000000 is  124364 in the series: 10000043
First >=   100000000 is  573929 in the series: 100140049
First >=  1000000000 is 7407841 in the series: 1000000081

Perl

Library: ntheory

<lang perl>use strict; use warnings; use feature 'say'; use List::AllUtils <max head firstidx uniqint>; use ntheory <primes is_semiprime forsetproduct>;

sub table { my $t = shift() * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr } sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }

my(@B,@Br); for my $oom (1..5) {

   my @P = grep { $oom == length } @{primes(10**$oom)};
   forsetproduct { is_semiprime($_[0] * $_[1]) and push @B, $_[0] * $_[1] } \@P, \@P;
   @Br = uniqint sort { $a <=> $b } @Br, @B;

}

say "First 100 brilliant numbers:\n" . table 10, head 100, @Br;

for my $oom (1..9) {

   my $key = firstidx { $_ > 10**$oom } @Br;
   printf "First >= %13s is position %9s in the series: %13s\n", comma(10**$oom), comma($key), comma $Br[$key];

}</lang>

Output:
First 100 brilliant numbers:
    4    6    9   10   14   15   21   25   35   49
  121  143  169  187  209  221  247  253  289  299
  319  323  341  361  377  391  403  407  437  451
  473  481  493  517  527  529  533  551  559  583
  589  611  629  649  667  671  689  697  703  713
  731  737  767  779  781  793  799  803  817  841
  851  869  871  893  899  901  913  923  943  949
  961  979  989 1003 1007 1027 1037 1067 1073 1079
 1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
 1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First >=            10 is position         4 in the series:            14
First >=           100 is position        10 in the series:           121
First >=         1,000 is position        73 in the series:         1,003
First >=        10,000 is position       241 in the series:        10,201
First >=       100,000 is position     2,504 in the series:       100,013
First >=     1,000,000 is position    10,537 in the series:     1,018,081
First >=    10,000,000 is position    124364 in the series:    10,000,043
First >=   100,000,000 is position    573929 in the series:   100,140,049
First >= 1,000,000,000 is position   7407841 in the series: 1,000,000,081

Faster approach

Translation of: Sidef

<lang perl>use 5.020; use strict; use warnings;

use ntheory qw(:all); use experimental qw(signatures);

sub is_briliant_number ($n) {

   is_semiprime($n) || return;
   my @f = factor($n);
   length($f[0]) == length($f[1]);

}

sub next_brilliant_number ($n) {

   ++$n while not is_briliant_number($n);
   $n;

}

sub brilliant_numbers_count ($n) {

   use integer;
   my $count = 0;
   my $len   = length(sqrtint($n));
   foreach my $k (1 .. $len - 1) {
       my $pi = prime_count(10**($k - 1), 10**$k - 1);
       $count += binomial($pi, 2) + $pi;
   }
   my $min = 10**($len - 1);
   my $max = 10**$len - 1;
   my $pi_min = prime_count($min);
   my $pi_max = prime_count($max);
   my $j  = -1;
   forprimes {
       if ($_*$_ <= $n) {
           $count += (($max <= $n/$_) ? $pi_max : prime_count($n/$_)) - $pi_min - ++$j;
       }
       else {
           lastfor;
       }
   } $min, $max;
   return $count;

}

say "First 100 brilliant numbers:";

my @nums;

for (my $k = 1 ; scalar(@nums) < 100 ; ++$k) {

   push(@nums, $k) if is_briliant_number($k);

}

while (@nums) {

   my @slice = splice(@nums, 0, 10);
   say join ' ', map { sprintf("%4s", $_) } @slice;

}

say ;

foreach my $n (1 .. 13) {

   my $v = next_brilliant_number(vecprod((10) x $n));
   printf("First brilliant number >= 10^%d is %s", $n, $v);
   printf(" at position %s\n", brilliant_numbers_count($v));

}</lang>

Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49
 121  143  169  187  209  221  247  253  289  299
 319  323  341  361  377  391  403  407  437  451
 473  481  493  517  527  529  533  551  559  583
 589  611  629  649  667  671  689  697  703  713
 731  737  767  779  781  793  799  803  817  841
 851  869  871  893  899  901  913  923  943  949
 961  979  989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First brilliant number >= 10^1 is 10 at position 4
First brilliant number >= 10^2 is 121 at position 11
First brilliant number >= 10^3 is 1003 at position 74
First brilliant number >= 10^4 is 10201 at position 242
First brilliant number >= 10^5 is 100013 at position 2505
First brilliant number >= 10^6 is 1018081 at position 10538
First brilliant number >= 10^7 is 10000043 at position 124364
First brilliant number >= 10^8 is 100140049 at position 573929
First brilliant number >= 10^9 is 1000000081 at position 7407841
First brilliant number >= 10^10 is 10000600009 at position 35547995
First brilliant number >= 10^11 is 100000000147 at position 491316167
First brilliant number >= 10^12 is 1000006000009 at position 2409600866
First brilliant number >= 10^13 is 10000000000073 at position 34896253010

Phix

Library: Phix/online

You can run this online here.

with javascript_semantics
requires("1.0.2") -- binary_search() mods
constant {klim, plim} = iff(machine_bits()=64?{13,1e7},{9,1e5}),
               primes = get_primes_le(plim-1)

function glim(sequence lp, atom pj)
    atom {limit,pi} = lp
    return pi*pj<limit
end function
 
function get_brilliant(integer digits, limit, bool countOnly=false)
    sequence brilliant = {}
    integer count = 0, start = 1
    atom pow = 10
    for k=1 to digits do
        integer finish = abs(binary_search(pow,primes))-1
        for i=start to finish do
            if countOnly then
                integer hij = abs(binary_search({limit,primes[i]},primes,i,finish,glim))
                if hij=i then exit end if
                count += hij-i
            else
                for j=i to finish do
                    atom prod = primes[i] * primes[j]
                    if prod>=limit then exit end if
                    brilliant &= prod
                end for
            end if
        end for
        start = finish+1
        pow *= 10
    end for
    return iff(countOnly?count:brilliant)
end function
 
sequence b100 = sort(get_brilliant(2,10000))[1..100],
         j100 = join_by(b100,1,10," ","\n","%4d")
printf(1,"First 100 brilliant numbers:\n%s\n",{j100})
for k=1 to klim do
    integer limit = power(10,k),
            total = get_brilliant(k, limit, true)+1,
            lo = limit+(k!=1)
    atom hi = lo*10
    if even(k) then
        hi = power(get_prime(abs(binary_search(ceil(sqrt(lo)),primes))),2)
    else
        integer lp = abs(binary_search(power(10,(k-1)/2),primes)),
                hp = abs(binary_search(power(10,(k+1)/2),primes))-1
        for i=lp to hp do
            for j=i to hp do
                atom prod = primes[i] * primes[j]
                if prod>=lo then
                    if prod<hi then
                        hi = prod
                    end if
                    exit
                end if
            end for 
        end for
    end if
    printf(1,"First >= %,18d is %,14d%s in the series: %,18d\n", {limit, total, ord(total), hi})
end for
Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49
 121  143  169  187  209  221  247  253  289  299
 319  323  341  361  377  391  403  407  437  451
 473  481  493  517  527  529  533  551  559  583
 589  611  629  649  667  671  689  697  703  713
 731  737  767  779  781  793  799  803  817  841
 851  869  871  893  899  901  913  923  943  949
 961  979  989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First >=                 10 is              4th in the series:                 10
First >=                100 is             11th in the series:                121
First >=              1,000 is             74th in the series:              1,003
First >=             10,000 is            242nd in the series:             10,201
First >=            100,000 is          2,505th in the series:            100,013
First >=          1,000,000 is         10,538th in the series:          1,018,081
First >=         10,000,000 is        124,364th in the series:         10,000,043
First >=        100,000,000 is        573,929th in the series:        100,140,049
First >=      1,000,000,000 is      7,407,841st in the series:      1,000,000,081
First >=     10,000,000,000 is     35,547,995th in the series:     10,000,600,009
First >=    100,000,000,000 is    491,316,167th in the series:    100,000,000,147
First >=  1,000,000,000,000 is  2,409,600,866th in the series:  1,000,006,000,008
First >= 10,000,000,000,000 is 34,896,253,010th in the series: 10,000,000,000,073

Obviously you don't get the last 4 lines under 32bit, or pwa/p2js.

Raku

1 through 7 are fast. 8 and 9 take a bit longer. <lang perl6>use Lingua::EN::Numbers;

  1. Find an abundance of primes to use to generate brilliants

my %primes = (2..100000).grep( &is-prime ).categorize: { .chars };

  1. Generate brilliant numbers

my @brilliant = lazy flat (1..*).map: -> $digits {

   sort flat (^%primes{$digits}).race.map: { %primes{$digits}[$_] X× (flat %primes{$digits}[$_ .. *]) }

};

  1. The task

put "First 100 brilliant numbers:\n" ~ @brilliant[^100].batch(10)».fmt("%4d").join("\n") ~ "\n" ;

for 1 .. 7 -> $oom {

   my $threshold = exp $oom, 10;
   my $key = @brilliant.first: :k, * >= $threshold;
   printf "First >= %13s is %9s in the series: %13s\n", comma($threshold), ordinal-digit(1 + $key, :u), comma @brilliant[$key];

}</lang>

Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49
 121  143  169  187  209  221  247  253  289  299
 319  323  341  361  377  391  403  407  437  451
 473  481  493  517  527  529  533  551  559  583
 589  611  629  649  667  671  689  697  703  713
 731  737  767  779  781  793  799  803  817  841
 851  869  871  893  899  901  913  923  943  949
 961  979  989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First >=            10 is       4ᵗʰ in the series:            10
First >=           100 is      11ᵗʰ in the series:           121
First >=         1,000 is      74ᵗʰ in the series:         1,003
First >=        10,000 is     242ⁿᵈ in the series:        10,201
First >=       100,000 is    2505ᵗʰ in the series:       100,013
First >=     1,000,000 is   10538ᵗʰ in the series:     1,018,081
First >=    10,000,000 is  124364ᵗʰ in the series:    10,000,043
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

Sidef

<lang ruby>func is_briliant_number(n) {

   n.is_semiprime && (n.factor.map{.len}.uniq.len == 1)

}

func brilliant_numbers_count(n) {

   var count = 0
   var len = n.isqrt.len
   for k in (1 .. len-1) {
       var pi = prime_count(10**(k-1), 10**k - 1)
       count += binomial(pi, 2)+pi
   }
   var min = (10**(len - 1))
   var max = (10**len - 1)
   each_prime(min, max, {|p|
       count += prime_count(p, max `min` idiv(n, p))
   })
   return count

}

say "First 100 brilliant numbers:"

100.by(is_briliant_number).each_slice(10, {|*a|

   say a.map { '%4s' % _}.join(' ')

})

say

for n in (1 .. 12) {

   var v = (10**n .. Inf -> first_by(is_briliant_number))
   printf("First brilliant number >= 10^%d is %s", n, v)
   printf(" at position %s\n", brilliant_numbers_count(v))

}</lang>

Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49
 121  143  169  187  209  221  247  253  289  299
 319  323  341  361  377  391  403  407  437  451
 473  481  493  517  527  529  533  551  559  583
 589  611  629  649  667  671  689  697  703  713
 731  737  767  779  781  793  799  803  817  841
 851  869  871  893  899  901  913  923  943  949
 961  979  989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First brilliant number >= 10^1 is 10 at position 4
First brilliant number >= 10^2 is 121 at position 11
First brilliant number >= 10^3 is 1003 at position 74
First brilliant number >= 10^4 is 10201 at position 242
First brilliant number >= 10^5 is 100013 at position 2505
First brilliant number >= 10^6 is 1018081 at position 10538
First brilliant number >= 10^7 is 10000043 at position 124364
First brilliant number >= 10^8 is 100140049 at position 573929
First brilliant number >= 10^9 is 1000000081 at position 7407841
First brilliant number >= 10^10 is 10000600009 at position 35547995
First brilliant number >= 10^11 is 100000000147 at position 491316167
First brilliant number >= 10^12 is 1000006000009 at position 2409600866

Wren

Library: Wren-math
Library: Wren-seq
Library: Wren-fmt

<lang ecmascript>import "./math" for Int import "./seq" for Lst import "./fmt" for Fmt

var primes = Int.primeSieve(1e7-1)

var getBrilliant = Fn.new { |digits, limit, countOnly|

   var brilliant = []
   var count = 0
   var pow = 1
   var next = Num.maxSafeInteger
   for (k in 1..digits) {
       var s = primes.where { |p| p > pow && p < pow * 10 }.toList
       for (i in 0...s.count) {
           for (j in i...s.count) {
               var prod = s[i] * s[j]
               if (prod < limit) {
                   if (countOnly) {
                       count = count + 1
                   } else {
                       brilliant.add(prod)
                   }
               } else {
                   next = next.min(prod)
                   break
               }
           }
       }
       pow = pow * 10
   }
   return countOnly ? [count, next] : [brilliant, next]

}

System.print("First 100 brilliant numbers:") var brilliant = getBrilliant.call(2, 10000, false)[0] brilliant.sort() brilliant = brilliant[0..99] for (chunk in Lst.chunks(brilliant, 10)) Fmt.print("$4d", chunk) System.print() for (k in 1..12) {

   var limit = 10.pow(k)
   var res = getBrilliant.call(k, limit, true)
   var total = res[0]
   var next = res[1]
   Fmt.print("First >= $,17d is $,15r in the series: $,17d", limit, total + 1, next)

}</lang>

Output:
First 100 brilliant numbers:
   4    6    9   10   14   15   21   25   35   49
 121  143  169  187  209  221  247  253  289  299
 319  323  341  361  377  391  403  407  437  451
 473  481  493  517  527  529  533  551  559  583
 589  611  629  649  667  671  689  697  703  713
 731  737  767  779  781  793  799  803  817  841
 851  869  871  893  899  901  913  923  943  949
 961  979  989 1003 1007 1027 1037 1067 1073 1079
1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First >=                10 is             4th in the series:                10
First >=               100 is            11th in the series:               121
First >=             1,000 is            74th in the series:             1,003
First >=            10,000 is           242nd in the series:            10,201
First >=           100,000 is         2,505th in the series:           100,013
First >=         1,000,000 is        10,538th in the series:         1,018,081
First >=        10,000,000 is       124,364th in the series:        10,000,043
First >=       100,000,000 is       573,929th in the series:       100,140,049
First >=     1,000,000,000 is     7,407,841st in the series:     1,000,000,081
First >=    10,000,000,000 is    35,547,995th in the series:    10,000,600,009
First >=   100,000,000,000 is   491,316,167th in the series:   100,000,000,147
First >= 1,000,000,000,000 is 2,409,600,866th in the series: 1,000,006,000,009

XPL0

<lang XPL0> func NumDigits(N); \Return number of digits in N int N, Cnt; [Cnt:= 0; repeat N:= N/10;

       Cnt:= Cnt+1;

until N = 0; return Cnt; ];

func Brilliant(N); \Return 'true' if N is a brilliant number int N, Limit, Cnt, F; int A(3); [Limit:= sqrt(N); Cnt:= 0; F:= 2; loop [if rem(N/F) = 0 then

               [A(Cnt):= F;
               Cnt:= Cnt+1;
               if Cnt > 2 then quit;
               N:= N/F;
               ]
       else    F:= F+1;
       if F > N then quit;
       if F > Limit then
               [A(Cnt):= N;
               Cnt:= Cnt+1;
               quit;
               ];
       ];

if Cnt # 2 then return false; return NumDigits(A(0)) = NumDigits(A(1)); ];

int Cnt, N, Mag; [Format(5, 0); Cnt:= 0; N:= 4; loop [if Brilliant(N) then

           [RlOut(0, float(N));
           Cnt:= Cnt+1;
           if Cnt >= 100 then quit;
           if rem(Cnt/10) = 0 then CrLf(0);
           ];
       N:= N+1;
       ];

CrLf(0); CrLf(0); Format(7, 0); Cnt:= 0; N:= 4; Mag:= 10; loop [if Brilliant(N) then

           [Cnt:= Cnt+1;
           if N >= Mag then
               [Text(0, "First >= ");
               RlOut(0, float(Mag));
               Text(0, " is ");
               RlOut(0, float(Cnt));
               Text(0, " in series: ");
               RlOut(0, float(N));
               CrLf(0);
               if Mag >= 1_000_000 then quit;
               Mag:= Mag*10;
               ];
           ];
       N:= N+1;
       ];

]</lang>

Output:
    4    6    9   10   14   15   21   25   35   49
  121  143  169  187  209  221  247  253  289  299
  319  323  341  361  377  391  403  407  437  451
  473  481  493  517  527  529  533  551  559  583
  589  611  629  649  667  671  689  697  703  713
  731  737  767  779  781  793  799  803  817  841
  851  869  871  893  899  901  913  923  943  949
  961  979  989 1003 1007 1027 1037 1067 1073 1079
 1081 1121 1139 1147 1157 1159 1189 1207 1219 1241
 1247 1261 1271 1273 1333 1343 1349 1357 1363 1369

First >=      10 is       4 in series:      10
First >=     100 is      11 in series:     121
First >=    1000 is      74 in series:    1003
First >=   10000 is     242 in series:   10201
First >=  100000 is    2505 in series:  100013
First >= 1000000 is   10538 in series: 1018081