Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
64
Task/Factorions/Ada/factorions.adb
Normal file
64
Task/Factorions/Ada/factorions.adb
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Factorions is
|
||||
subtype Factorial_Domain is Natural range 0 .. 11;
|
||||
subtype Log_Base is Positive range 2 .. Positive'Last;
|
||||
type Result_Table is array (Factorial_Domain) of Positive;
|
||||
|
||||
Factorial : Result_Table;
|
||||
Search_Limit : Positive := 1_500_000;
|
||||
|
||||
procedure Precompute_Factorials is
|
||||
begin
|
||||
Factorial (0) := 1;
|
||||
|
||||
for I in 1 .. Factorial'Last loop
|
||||
Factorial (I) := I * Factorial (I - 1);
|
||||
end loop;
|
||||
end Precompute_Factorials;
|
||||
|
||||
function Floor_Log (Number : Positive; Base : Log_Base) return Natural is
|
||||
Remaining : Natural := Number;
|
||||
Floor_Log : Natural := 0;
|
||||
begin
|
||||
while Remaining > Base loop
|
||||
Remaining := Remaining / Base;
|
||||
Floor_Log := Floor_Log + 1;
|
||||
end loop;
|
||||
|
||||
return Floor_Log;
|
||||
end Floor_Log;
|
||||
|
||||
function Digit (Number, Index : Natural; Base : Log_Base) return Natural is
|
||||
begin
|
||||
return (Number / (Base ** Index)) mod Base;
|
||||
end Digit;
|
||||
|
||||
function Is_Factorion (Number : Positive; Base : Log_Base) return Boolean is
|
||||
Digit_Sum : Natural := 0;
|
||||
begin
|
||||
for I in 0 .. Floor_Log (Number, Base) loop
|
||||
Digit_Sum := Digit_Sum + Factorial (Digit (Number, I, Base));
|
||||
end loop;
|
||||
|
||||
return Digit_Sum = Number;
|
||||
end Is_Factorion;
|
||||
|
||||
procedure Show_Factorions (Base : Log_Base) is
|
||||
begin
|
||||
Ada.Text_IO.Put_Line ("Search Base " & Base'Image);
|
||||
for I in 1 .. Search_Limit loop
|
||||
if Is_Factorion (I, Base) then
|
||||
Ada.Text_IO.Put_Line (I'Image);
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line ("Done Base " & Base'Image);
|
||||
end Show_Factorions;
|
||||
|
||||
begin
|
||||
Precompute_Factorials;
|
||||
Show_Factorions (9);
|
||||
Show_Factorions (10);
|
||||
Show_Factorions (11);
|
||||
Show_Factorions (12);
|
||||
end Factorions;
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
len fact[] 12
|
||||
arrbase fact[] 0
|
||||
#
|
||||
fact[0] = 1
|
||||
for n = 1 to 11
|
||||
|
|
|
|||
52
Task/Factorions/Fortran/factorions.f
Normal file
52
Task/Factorions/Fortran/factorions.f
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
! Factorions
|
||||
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 25.10
|
||||
! GNU gfortran (Ubuntu 15.2.0-4ubuntu4) 15.2.0 on Kubuntu 25.10
|
||||
! VSI Fortran x86-64 V8.7-001 on OpenVMS V9.2-3
|
||||
program Factorions
|
||||
integer, parameter :: minBase=9, maxBase = 12 ! minumum and maximum base used in this little program
|
||||
integer, parameter :: factLim=1499999 ! Maximum factorial Number for all bases that are used here
|
||||
integer, dimension(0:maxBase-1) :: fact ! Stored factorials for numbers 0...12
|
||||
|
||||
integer :: ii, jj, base
|
||||
|
||||
! Prepare cached factorial function
|
||||
fact = 1
|
||||
do ii=1, maxBase-1
|
||||
do jj= 2, ii
|
||||
fact(ii) = fact(ii) * jj
|
||||
enddo
|
||||
end do
|
||||
|
||||
!
|
||||
! Brute force: for all bases, for all numbers 1...max tes each number and print if its a factorion.
|
||||
!
|
||||
do base=minBase, maxBase
|
||||
write (*, '("The factorions in base ", i0, " are:")') base
|
||||
do ii=1, factLim
|
||||
if (isFactorion (ii, base)) write (*, '(1x,i0)', advance='no') ii
|
||||
enddo
|
||||
write (*,'(/)')
|
||||
end do
|
||||
|
||||
contains
|
||||
|
||||
!
|
||||
! Separate digits d of number n in base b, sum up d!, and compare result with n.
|
||||
!
|
||||
function isFactorion (n,b) result (YN)
|
||||
integer, intent (in) :: n, b
|
||||
logical :: YN
|
||||
integer :: dig, nn, facts_sum
|
||||
|
||||
nn = N
|
||||
facts_sum = 0
|
||||
do while (nn .ne. 0)
|
||||
dig = mod (nn, b)
|
||||
nn = nn / b
|
||||
|
||||
facts_sum = facts_sum + fact(dig)
|
||||
enddo
|
||||
yn = facts_sum .eq. n
|
||||
|
||||
end function isFactorion
|
||||
end program Factorions
|
||||
25
Task/Factorions/JavaScript/factorions.js
Normal file
25
Task/Factorions/JavaScript/factorions.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
function factorial(n) {
|
||||
if (n <= 1) {
|
||||
return 1;
|
||||
}
|
||||
let a = [...Array(n + 1).keys()];
|
||||
a.shift();
|
||||
return a.reduce((x, y) => x * y);
|
||||
}
|
||||
|
||||
function fact_digsum(n, b) {
|
||||
if (n > b - 1) {
|
||||
return factorial(n % b) + fact_digsum(Math.floor(n / b), b);
|
||||
}
|
||||
return factorial(n);
|
||||
}
|
||||
|
||||
for (let i = 9; i <= 12; i++) {
|
||||
console.log(`Factorions in base ${i}:`);
|
||||
for (let j = 1; j < 1499999; j++) {
|
||||
if (j == fact_digsum(j, i)) {
|
||||
console.log(j);
|
||||
}
|
||||
}
|
||||
console.log();
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
fact_digsum <- function(n, b){
|
||||
if(n>b-1){
|
||||
fact_digsum <- function(n, b) {
|
||||
if(n > b-1) {
|
||||
factorial(n%%b)+fact_digsum(n%/%b, b)
|
||||
} else factorial(n)
|
||||
}
|
||||
|
||||
for(i in 9:12){
|
||||
for(i in 9:12) {
|
||||
cat("\nFactorions in base ", i, ":\n", sep="")
|
||||
for(j in 1:1499999){
|
||||
if(j==fact_digsum(j, i)) cat(j, "")
|
||||
for(j in 1:1499999) {
|
||||
if(j == fact_digsum(j, i)) cat(j, "")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
Task/Factorions/VBScript/factorions.vbs
Normal file
23
Task/Factorions/VBScript/factorions.vbs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
' Factorions - VBScript - PG - 26/04/2020
|
||||
Dim fact()
|
||||
nn1=9 : nn2=12
|
||||
lim=1499999
|
||||
ReDim fact(nn2)
|
||||
fact(0)=1
|
||||
For i=1 To nn2
|
||||
fact(i)=fact(i-1)*i
|
||||
Next
|
||||
For base=nn1 To nn2
|
||||
list=""
|
||||
For i=1 To lim
|
||||
s=0
|
||||
t=i
|
||||
Do While t<>0
|
||||
d=t Mod base
|
||||
s=s+fact(d)
|
||||
t=t\base
|
||||
Loop
|
||||
If s=i Then list=list &" "& i
|
||||
Next
|
||||
Wscript.Echo "the factorions for base "& right(" "& base,2) &" are: "& list
|
||||
Next
|
||||
7
Task/Factorions/Vyxal/factorions.vyxal
Normal file
7
Task/Factorions/Vyxal/factorions.vyxal
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
λ2|→B:←Bτƛ¡}∑$_-¬}£ # check whether factorion
|
||||
⟨9|10|11|12⟩(`Base `₴n:₴\:,→b
|
||||
1500000 (
|
||||
n 1000 ≠[
|
||||
←b n¥†[n,]]
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue