Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
70
Task/Brilliant-numbers/FutureBasic/brilliant-numbers.basic
Normal file
70
Task/Brilliant-numbers/FutureBasic/brilliant-numbers.basic
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#build Optimization 3
|
||||
#build Architecture "Apple Silicon"
|
||||
// #build Architecture "Intel"
|
||||
// #build Architecture "Universal"
|
||||
|
||||
local fn isPrime( v as Uint64 ) as bool
|
||||
if v < 2 then exit fn = NO
|
||||
select 0
|
||||
if ( ( v - 2 ) == 0 || ( v - 3 ) == 0 ) then exit fn = YES
|
||||
if ( ( v % 2 ) == 0 || ( v % 3 ) == 0 ) then exit fn = NO
|
||||
end select
|
||||
|
||||
Uint64 f = 5
|
||||
while f*f <= v
|
||||
if v mod f == 0 then exit fn = no
|
||||
f += 2
|
||||
if v mod f == 0 then exit fn = no
|
||||
f += 4
|
||||
wend
|
||||
end fn = yes
|
||||
|
||||
local fn FirstPrimeFactor( n as UInt64 ) as UInt64
|
||||
UInt64 i
|
||||
if n mod 2 == 0 then exit fn = 2
|
||||
if n mod 3 == 0 then exit fn = 3
|
||||
i = 5
|
||||
while i*i <= n
|
||||
if n mod i == 0 then exit fn = i
|
||||
i += 2
|
||||
if n mod i == 0 then exit fn = i
|
||||
i += 4
|
||||
wend
|
||||
end fn = n
|
||||
|
||||
local fn DoBrilliants( expoLimit as UInt64 ) as CFMutableStringRef
|
||||
UInt64 count = 0, n = 0, ff, sf, expo = 0
|
||||
CFMutableStringRef mutStr = fn MutableStringWithString( @"\nFirst 100 brilliant numbers:\n" )
|
||||
|
||||
do
|
||||
ff = fn FirstPrimeFactor( n )
|
||||
sf = n/ff
|
||||
if fn IsPrime( sf ) && len( str(ff) ) == len( str(sf) )
|
||||
MutableStringAppendFormat( mutStr, @"%7u\b", n )
|
||||
count++
|
||||
if count mod 10 == 0 then MutableStringAppendFormat( mutStr, @"\n" )
|
||||
end if
|
||||
n++
|
||||
until count == 100
|
||||
|
||||
MutableStringAppendFormat( mutStr, @"\n" ) : count = 0 : n = 0
|
||||
|
||||
while ( expo != expoLimit )
|
||||
ff = fn FirstPrimeFactor( n )
|
||||
sf = n/ff
|
||||
if fn IsPrime( sf ) && len( str(ff) ) = len( str(sf) )
|
||||
count++
|
||||
if ( n >= 10^expo )
|
||||
MutableStringAppendFormat( mutStr, @"%10u (%6d * %-6d) => 10^%d is brilliant at Position No. %d\n", n, ff, sf, expo, count )
|
||||
expo++
|
||||
end if
|
||||
end if
|
||||
n++
|
||||
wend
|
||||
end fn = mutStr
|
||||
|
||||
CFTimeInterval t : t = fn CACurrentMediaTime
|
||||
CFStringRef brilliants : brilliants = fn DoBrilliants( 7 )
|
||||
printf @"%@\n\t\tTime = %.f milliseconds", brilliants, (fn CACurrentMediaTime - t) * 1000
|
||||
|
||||
HandleEvents
|
||||
65
Task/Brilliant-numbers/SETL/brilliant-numbers.setl
Normal file
65
Task/Brilliant-numbers/SETL/brilliant-numbers.setl
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
program brilliant_numbers;
|
||||
init bs := brilliant(4);
|
||||
|
||||
print('First 100 brilliant numbers:');
|
||||
loop for n in bs(1..100) do
|
||||
nprint(lpad(str n, 6));
|
||||
if (c +:= 1) mod 10 = 0 then
|
||||
print;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
loop doing o +:= 1; while exists n = bs(i) | n >= 10**o do
|
||||
print('First brilliant number >= ' + lpad(str(10**o), 10) +
|
||||
': ' + lpad(str n, 10) + ' at position ' + lpad(str i,6));
|
||||
end loop;
|
||||
|
||||
proc brilliant(orders);
|
||||
primes := sieve(10**orders);
|
||||
groups := group_by_digit_count(primes);
|
||||
|
||||
b := [];
|
||||
loop for group in groups do
|
||||
loop for i in [1..#group] do
|
||||
loop for j in [1..i] do
|
||||
b with:= group(i) * group(j);
|
||||
end loop;
|
||||
end loop;
|
||||
end loop;
|
||||
return [x : x in {x : x in b}];
|
||||
end proc;
|
||||
|
||||
proc group_by_digit_count(nums);
|
||||
magn := 10;
|
||||
groups := [];
|
||||
group := [];
|
||||
loop for n in nums do
|
||||
if n>=magn then
|
||||
magn *:= 10;
|
||||
groups with:= group;
|
||||
group := [];
|
||||
end if;
|
||||
group with:= n;
|
||||
end loop;
|
||||
if group /= [] then
|
||||
groups with:= group;
|
||||
end if;
|
||||
return groups;
|
||||
end proc;
|
||||
|
||||
proc sieve(n);
|
||||
ps := [True] * n;
|
||||
p := 2;
|
||||
loop while p*p <= n do
|
||||
if ps(p) then
|
||||
c := p*p;
|
||||
loop while c<=n do
|
||||
ps(c) := False;
|
||||
c +:= p;
|
||||
end loop;
|
||||
end if;
|
||||
p +:= 1;
|
||||
end loop;
|
||||
return [i : i in [2..n] | ps(i)];
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue