Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Disarium_numbers

View file

@ -0,0 +1,31 @@
A '''Disarium number''' is an integer where the sum of each digit raised to the power of its position in the number, is equal to the number.
;E.G.
'''135''' is a '''Disarium number''':
<span style=font-size:125%;font-weight:bold;padding-left:3em;> 1<sup>1</sup> + 3<sup>2</sup> + 5<sup>3</sup> == 1 + 9 + 125 == 135</span>
There are a finite number of '''Disarium numbers'''.
;Task
* Find and display the first 18 '''Disarium numbers'''.
;Stretch
* Find and display all 20 '''Disarium numbers'''.
;See also
;* [https://www.geeksforgeeks.org/disarium-number/ Geeks for Geeks - Disarium numbers]
;* [[oeis:A032799|OEIS:A032799 - Numbers n such that n equals the sum of its digits raised to the consecutive powers (1,2,3,...)]]
;* [[Narcissistic_decimal_number|Related task: Narcissistic decimal number]]
;* [[Own_digits_power_sum|Related task: Own digits power sum]] <span style=font-size:75%;;padding-left:1em;>''Which seems to be the same task as Narcissistic decimal number...''</span>
<br>

View file

@ -0,0 +1,22 @@
F is_disarium(n)
V digitos = String(n).len
V suma = 0
V x = n
L x != 0
suma += (x % 10) ^ digitos
digitos--
x I/= 10
I suma == n
R 1B
E
R 0B
V limite = 19
V cont = 0
V n = 0
print(The first limite Disarium numbers are:)
L cont < limite
I is_disarium(n)
print(n, end' )
cont++
n++

View file

@ -0,0 +1,37 @@
begin comment find some Disarium numbers
- numbers whose digit position-power sums are equal to the
number, e.g. 135 = 1^1 + 3^2 + 5^3;
integer array power [ 1 : 9, 0 : 9 ];
integer count, powerOfTen, length, n, d;
comment compute the nth powers of 0-9;
for d := 0 step 1 until 9 do power[ 1, d ] := d;
for n := 2 step 1 until 9 do begin
power[ n, 0 ] := 0;
for d := 1 step 1 until 9 do power[ n, d ] := power[ n - 1, d ] * d
end n;
comment print the first few Disarium numbers;
count := 0;
powerOfTen := 10;
length := 1;
n := -1;
for n := n + 1 while count < 19 do begin
integer v, dps, p;
if n = powerOfTen then begin
comment the number of digfits just increased;
powerOfTen := powerOfTen * 10;
length := length + 1
end;
comment form the digit power sum;
v := n;
dps := 0;
for p := length step -1 until 1 do begin
dps := dps + power[ p, v - ( ( v % 10 ) * 10 ) ];
v := v % 10
end p;
if dps = n then begin
comment n is Disarium;
count := count + 1;
outinteger( 1, n )
end
end n
end

View file

@ -0,0 +1,36 @@
BEGIN # find some Disarium numbers - numbers whose digit position-power sums #
# are equal to the number, e.g. 135 = 1^1 + 3^2 + 5^3 #
# compute the nth powers of 0-9 #
[ 1 : 9, 0 : 9 ]INT power;
FOR d FROM 0 TO 9 DO power[ 1, d ] := d OD;
FOR n FROM 2 TO 9 DO
power[ n, 0 ] := 0;
FOR d TO 9 DO
power[ n, d ] := power[ n - 1, d ] * d
OD
OD;
# print the first few Disarium numbers #
INT max disarium = 19;
INT count := 0;
INT power of ten := 10;
INT length := 1;
FOR n FROM 0 WHILE count < max disarium DO
IF n = power of ten THEN
# the number of digits just increased #
power of ten *:= 10;
length +:= 1
FI;
# form the digit power sum #
INT v := n;
INT dps := 0;
FOR p FROM length BY -1 TO 1 DO
dps +:= power[ p, v MOD 10 ];
v OVERAB 10
OD;
IF dps = n THEN
# n is Disarium #
count +:= 1;
print( ( " ", whole( n, 0 ) ) )
FI
OD
END

View file

@ -0,0 +1,39 @@
begin % find some Disarium numbers - numbers whose digit position-power sums %
% are equal to the number, e.g. 135 = 1^1 + 3^2 + 5^3 %
integer array power ( 1 :: 9, 0 :: 9 );
integer MAX_DISARIUM;
integer count, powerOfTen, length, n;
% compute the nth powers of 0-9 %
for d := 0 until 9 do power( 1, d ) := d;
for n := 2 until 9 do begin
power( n, 0 ) := 0;
for d := 1 until 9 do power( n, d ) := power( n - 1, d ) * d
end for_n;
% print the first few Disarium numbers %
MAX_DISARIUM := 19;
count := 0;
powerOfTen := 10;
length := 1;
n := 0;
while count < MAX_DISARIUM do begin
integer v, dps;
if n = powerOfTen then begin
% the number of digits just increased %
powerOfTen := powerOfTen * 10;
length := length + 1
end if_m_eq_powerOfTen ;
% form the digit power sum %
v := n;
dps := 0;
for p := length step -1 until 1 do begin
dps := dps + power( p, v rem 10 );
v := v div 10;
end FOR_P;
if dps = n then begin
% n is Disarium %
count := count + 1;
writeon( i_w := 1, s_w := 0, " ", n )
end if_dps_eq_n ;
n := n + 1
end
end.

View file

@ -0,0 +1 @@
((/)(=(¨(+/*)))¨)0,3000000

View file

@ -0,0 +1,24 @@
# syntax: GAWK -f DISARIUM_NUMBERS.AWK
BEGIN {
stop = 19
printf("The first %d Disarium numbers:\n",stop)
while (count < stop) {
if (is_disarium(n)) {
printf("%d ",n)
count++
}
n++
}
printf("\n")
exit(0)
}
function is_disarium(n, leng,sum,x) {
x = n
leng = length(n)
while (x != 0) {
sum += (x % 10) ^ leng
leng--
x = int(x/10)
}
return((sum == n) ? 1 : 0)
}

View file

@ -0,0 +1,52 @@
;;; find some Disarium Numbers - numbers whose digit-position power sume
;;; are equal to the number, e.g.: 135 = 1^1 + 3^2 + 5^3
PROC Main()
DEFINE MAX_DISARIUM = "9999"
CARD ARRAY power( 40 ) ; table of powers up to the fourth power ( 1:4, 0:9 )
CARD n, d, powerOfTen, count, length, v, p, dps, nsub, nprev
; compute the n-th powers of 0-9
FOR d = 0 TO 9 DO power( d ) = D OD
nsub = 10
nprev = 0
FOR n = 2 TO 4 DO
power( nsub ) = 0
FOR d = 1 TO 9 DO
power( nsub + d ) = power( nprev + d ) * d
OD
nprev = nsub
nsub ==+ 10
OD
; print the Disarium numbers up to 9999 or the 18th, whichever is sooner
powerOfTen = 10
length = 1
count = 0 n = 0
WHILE n < MAX_DISARIUM AND count < 18 DO
IF n = powerOfTen THEN
; the number of digits just increased
powerOfTen ==* 10
length ==+ 1
FI
; form the digit power sum
v = n
p = length * 10;
dps = 0;
FOR d = 1 TO length DO
p ==- 10
dps ==+ power( p + ( v MOD 10 ) )
v ==/ 10
OD
IF dps = N THEN
; n is Disarium
count ==+ 1;
Put( ' )
PrintC( n )
FI
n ==+ 1
OD
RETURN

View file

@ -0,0 +1,34 @@
with Ada.Text_IO;
procedure Disarium_Numbers is
Disarium_Count : constant := 19;
function Is_Disarium (N : Natural) return Boolean is
Nn : Natural := N;
Pos : Natural := 0;
Sum : Natural := 0;
begin
while Nn /= 0 loop
Nn := Nn / 10;
Pos := Pos + 1;
end loop;
Nn := N;
while Nn /= 0 loop
Sum := Sum + (Nn mod 10) ** Pos;
Nn := Nn / 10;
Pos := Pos - 1;
end loop;
return N = Sum;
end Is_Disarium;
Count : Natural := 0;
begin
for N in 0 .. Natural'Last loop
if Is_Disarium (N) then
Count := Count + 1;
Ada.Text_IO.Put (N'Image);
end if;
exit when Count = Disarium_Count;
end loop;
end Disarium_Numbers;

View file

@ -0,0 +1,26 @@
on isDisarium(n)
set temp to n
set digitCount to 1
repeat while (temp > 9)
set temp to temp div 10
set digitCount to digitCount + 1
end repeat
set temp to n
set sum to 0
repeat with position from digitCount to 2 by -1
set sum to sum + (temp mod 10) ^ position
set temp to temp div 10
end repeat
return (sum + temp = n)
end isDisarium
local Disaria, n
set Disaria to {}
set n to 0
repeat until ((count Disaria) = 19)
if (isDisarium(n)) then set end of Disaria to n
set n to n + 1
end repeat
return Disaria

View file

@ -0,0 +1 @@
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 89, 135, 175, 518, 598, 1306, 1676, 2427, 2646798}

View file

@ -0,0 +1,18 @@
disarium?: function [x][
j: 0
psum: sum map digits x 'dig [
j: j + 1
dig ^ j
]
return psum = x
]
cnt: 0
i: 0
while [cnt < 18][
if disarium? i [
print i
cnt: cnt + 1
]
i: i + 1
]

View file

@ -0,0 +1,23 @@
function isDisarium(n)
digitos = length(string(n))
suma = 0
x = n
while x <> 0
suma += (x % 10) ^ digitos
digitos -= 1
x = x \ 10
end while
if suma = n then return True else return False
end function
limite = 19
cont = 0 : n = 0
print "The first"; limite; " Disarium numbers are:"
while cont < limite
if isDisarium(n) then
print n; " ";
cont += 1
endif
n += 1
end while
end

View file

@ -0,0 +1,17 @@
get "libhdr"
let length(n) = n < 10 -> 1,
length(n/10) + 1
let pow(b, e) = e = 0 -> 1,
b * pow(b, e-1)
let dps(n) = dpsl(n, length(n))
and dpsl(n, p) = n = 0 -> 0,
pow(n rem 10, p) + dpsl(n/10, p-1)
let disarium(n) = dps(n) = n
let start() be
for n=0 to 2500 if disarium(n)
do writef("%N*N", n)

View file

@ -0,0 +1,5 @@
Digits {𝕊 0: ; (𝕊𝕩÷10)10|𝕩}
DigitPowerSum (+´1+)Digits
Disarium =DigitPowerSum
Disarium¨/ 2500

View file

@ -0,0 +1,22 @@
define is_disarium (num) {
n = num
sum = 0
len = length(n)
while (n > 0) {
sum += (n % 10) ^ len
n = n/10
len -= 1
}
return (sum == num)
}
count = 0
i = 0
while (count < 19) {
if (is_disarium(i)) {
print i, "\n"
count += 1
}
i += 1
}
quit

View file

@ -0,0 +1,39 @@
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>
std::vector<int> decompose( int n ) {
std::vector<int> digits ;
while ( n != 0 ) {
digits.push_back( n % 10 ) ;
n /= 10 ;
}
std::reverse( digits.begin( ) , digits.end( ) ) ;
return digits ;
}
bool isDisarium( int n ) {
std::vector<int> digits( decompose( n ) ) ;
int exposum = 0 ;
for ( int i = 1 ; i < digits.size( ) + 1 ; i++ ) {
exposum += static_cast<int>( std::pow(
static_cast<double>(*(digits.begin( ) + i - 1 )) ,
static_cast<double>(i) )) ;
}
return exposum == n ;
}
int main( ) {
std::vector<int> disariums ;
int current = 0 ;
while ( disariums.size( ) != 18 ){
if ( isDisarium( current ) )
disariums.push_back( current ) ;
current++ ;
}
for ( int d : disariums )
std::cout << d << " " ;
std::cout << std::endl ;
return 0 ;
}

View file

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int power (int base, int exponent) {
int result = 1;
for (int i = 1; i <= exponent; i++) {
result *= base;
}
return result;
}
int is_disarium (int num) {
int n = num;
int sum = 0;
int len = n <= 9 ? 1 : floor(log10(n)) + 1;
while (n > 0) {
sum += power(n % 10, len);
n /= 10;
len--;
}
return num == sum;
}
int main() {
int count = 0;
int i = 0;
while (count < 19) {
if (is_disarium(i)) {
printf("%d ", i);
count++;
}
i++;
}
printf("%s\n", "\n");
}

View file

@ -0,0 +1,32 @@
is_disarium = proc (n: int) returns (bool)
digits: array[int] := array[int]$[]
number: int := n
while n > 0 do
array[int]$addl(digits, n//10)
n := n / 10
end
array[int]$set_low(digits, 1)
digit_power_sum: int := 0
for i: int in array[int]$indexes(digits) do
digit_power_sum := digit_power_sum + digits[i] ** i
end
return(digit_power_sum = number)
end is_disarium
disaria = iter (amount: int) yields (int)
n: int := 0
while amount > 0 do
if is_disarium(n) then
amount := amount - 1
yield(n)
end
n := n + 1
end
end disaria
start_up = proc ()
po: stream := stream$primary_output()
for n: int in disaria(19) do
stream$putl(po, int$unparse(n))
end
end start_up

View file

@ -0,0 +1,36 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. DISARIUM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 CANDIDATE PIC 9(9).
03 DIGITS PIC 9 OCCURS 9 TIMES, REDEFINES CANDIDATE.
03 IDX PIC 99.
03 EXPONENT PIC 99.
03 DGT-POWER PIC 9(9).
03 DGT-POWER-SUM PIC 9(9).
03 CAND-OUT PIC Z(8)9.
03 AMOUNT PIC 99 VALUE 18.
PROCEDURE DIVISION.
BEGIN.
PERFORM DISARIUM-TEST VARYING CANDIDATE FROM ZERO BY 1
UNTIL AMOUNT IS ZERO.
STOP RUN.
DISARIUM-TEST.
MOVE ZERO TO DGT-POWER-SUM.
MOVE 1 TO EXPONENT, IDX.
INSPECT CANDIDATE TALLYING IDX FOR LEADING ZEROES.
PERFORM ADD-DIGIT-POWER UNTIL IDX IS GREATER THAN 9.
IF DGT-POWER-SUM IS EQUAL TO CANDIDATE,
MOVE CANDIDATE TO CAND-OUT,
DISPLAY CAND-OUT,
SUBTRACT 1 FROM AMOUNT.
ADD-DIGIT-POWER.
COMPUTE DGT-POWER = DIGITS(IDX) ** EXPONENT.
ADD DGT-POWER TO DGT-POWER-SUM.
ADD 1 TO EXPONENT.
ADD 1 TO IDX.

View file

@ -0,0 +1,27 @@
0010 FUNC dps#(n#) CLOSED
0020 DIM digits#(10)
0030 length#:=0
0040 rest#:=n#
0050 WHILE rest#>0 DO
0060 length#:+1
0070 digits#(length#):=rest# MOD 10
0080 rest#:=rest# DIV 10
0090 ENDWHILE
0100 sum#:=0
0110 FOR i#:=1 TO length# DO
0120 sum#:+digits#(i#)^(length#-i#+1)
0130 ENDFOR i#
0140 RETURN sum#
0150 ENDFUNC dps#
0160 //
0170 amount#:=18
0180 num#:=0
0190 WHILE amount#>0 DO
0200 IF dps#(num#)=num# THEN
0210 amount#:-1
0220 PRINT num#
0230 ENDIF
0240 num#:+1
0250 ENDWHILE
0260 PRINT
0270 END

View file

@ -0,0 +1,41 @@
include "cowgol.coh";
sub pow(base: uint8, exp: uint8): (power: uint32) is
power := 1;
while exp > 0 loop
power := power * base as uint32;
exp := exp - 1;
end loop;
end sub;
sub digit_power_sum(n: uint32): (dps: uint32) is
var digits: uint8[10]; # 2**32 has 10 digits
var digit := &digits[0];
var length: uint8 := 0;
while n > 0 loop
[digit] := (n % 10) as uint8;
digit := @next digit;
length := length + 1;
n := n / 10;
end loop;
dps := 0;
var power: uint8 := 1;
while power <= length loop
digit := @prev digit;
dps := dps + pow([digit], power);
power := power + 1;
end loop;
end sub;
var amount: uint8 := 19;
var candidate: uint32 := 0;
while amount > 0 loop
if digit_power_sum(candidate) == candidate then
amount := amount - 1;
print_i32(candidate);
print_nl();
end if;
candidate := candidate + 1;
end loop;

View file

@ -0,0 +1,27 @@
import std.stdio;
import std.math;
import std.conv;
bool is_disarium(int num) {
int n = num;
int sum = 0;
ulong len = to!string(num, 10).length;
while (n > 0) {
sum += pow(n % 10, len);
n /= 10;
len--;
}
return num == sum;
}
void main() {
int i = 0;
int count = 0;
while (count < 19) {
if (is_disarium(i)) {
printf("%d ", i);
count++;
}
i++;
}
writeln(" ");
}

View file

@ -0,0 +1,25 @@
import "dart:math";
import "dart:io";
void main() {
var count = 0;
var i = 0;
while (count < 19) {
if (is_disarium(i)) {
stdout.write("$i ");
count++;
}
i++;
}
}
bool is_disarium(numb) {
var n = numb;
var len = n.toString().length;
var sum = 0;
while (n > 0) {
sum += (pow(n % 10, len)).toInt();
n = (n / 10).toInt();
len--;
}
return numb == sum;
}

View file

@ -0,0 +1,2 @@
[10/ll1+sld0<Lx] sL [d10%ll^ls+ss10/ll1-sld0<Dx] sD[lc1+sc
lnp]sP[Osslisnln0sllLx0ssclnlDxlsln=Pli1+silc18>Ix] sI0si0sclIx

View file

@ -0,0 +1,56 @@
# Macro for computing the input number length
[10 # pushes 10 to stack
/ # divides input by 10 and stores result on stack
ll # push length on stack
1+ # add one to stack (length)
# p # prints intermediate length (for debugging)
sl # saves length to register l
d # duplicates value (number) on top of stack
0 # pushes 0 to stack
<Lx # executes length macro (L) if number > 0
] sL # end of length macro, store it in L
# is Disarium macro
[d # duplicates value (number) on top of stack
10 # pushes 10 to stack
% # pushes (number % 10) to stack
ll # pushes length to stack
^ # computes (n % 10) ^ len
ls # pushes sum to stack
+ss # computes new sum and stores it in s
10/ # integer division number / 10
ll # pushes length on stack
1- # subtract 1 froml length
sl # stores new length in l
d # duplicates value (number) on top of stack
0 # pushes 0 to stack
<Dx # executes recursively disarium macro (D) if number > 0
] sD # stores disarium macro in D
# Printing and counting macro
[lc1+sc # increments disarium number counter
lnp # print number
]sP # Stores printing macro in P
# Iteration macro
[Oss # stores 0 in register s (sum)
li sn # Stores iteration variable in number register
ln # pushes number to stack
0sl # stores 0 in register l (length)
lLx # runs the length macro
0ss # inititialize sum to 0
cln # clear stack and pushes number onto it
# llp # print the length
lDx # runs the Disarium macro once
lsln # pushes sum and number
=P # runs the printing macro if numbers are equal
li # loads iteration variable
1+si # increments iteration variable
lc18 # pushes counter and 18 on stack
>Ix # runs recursively iteration macro if counter < 18
] sI # end of iteration macro, stores it in I
# Main
0si # Initiate iteration variable
0sc # Initiate disarium numbers counter
lIx # running iteration macro the first time

View file

@ -0,0 +1,69 @@
{Table to speed up calculating powers. Contains all the powers
of the digits 0..9 raised to the 0..21 power}
const PowersTable: array [0..21,0..9] of int64 = (
($01,$01,$01,$01,$01,$01,$01,$01,$01,$01),
($00,$01,$02,$03,$04,$05,$06,$07,$08,$09),
($00,$01,$04,$09,$10,$19,$24,$31,$40,$51),
($00,$01,$08,$1B,$40,$7D,$D8,$157,$200,$2D9),
($00,$01,$10,$51,$100,$271,$510,$961,$1000,$19A1),
($00,$01,$20,$F3,$400,$C35,$1E60,$41A7,$8000,$E6A9),
($00,$01,$40,$2D9,$1000,$3D09,$B640,$1CB91,$40000,$81BF1),
($00,$01,$80,$88B,$4000,$1312D,$44580,$C90F7,$200000,$48FB79),
($00,$01,$100,$19A1,$10000,$5F5E1,$19A100,$57F6C1,$1000000,$290D741),
($00,$01,$200,$4CE3,$40000,$1DCD65,$99C600,$267BF47,$8000000,$17179149),
($00,$01,$400,$E6A9,$100000,$9502F9,$39AA400,$10D63AF1,$40000000,$CFD41B91),
($00,$01,$800,$2B3FB,$400000,$2E90EDD,$159FD800,$75DB9C97,$200000000,$74E74F819),
($00,$01,$1000,$81BF1,$1000000,$E8D4A51,$81BF1000,$339014821,$1000000000,$41C21CB8E1),
($00,$01,$2000,$1853D3,$4000000,$48C27395,$30A7A6000,$168F08F8E7,$8000000000,$24FD3027FE9),
($00,$01,$4000,$48FB79,$10000000,$16BCC41E9,$123EDE4000,$9DE93ECE51,$40000000000,$14CE6B167F31),
($00,$01,$8000,$DAF26B,$40000000,$71AFD498D,$6D79358000,$45160B7A437,$200000000000,$BB41C3CA78B9),
($00,$01,$10000,$290D741,$100000000,$2386F26FC1,$290D7410000,$1E39A5057D81,$1000000000000,$6954FE21E3E81),
($00,$01,$20000,$7B285C3,$400000000,$B1A2BC2EC5,$F650B860000,$D39383266E87,$8000000000000,$3B3FCEF3103289),
($00,$01,$40000,$17179149,$1000000000,$3782DACE9D9,$5C5E45240000,$5C908960D05B1,$40000000000000,$2153E468B91C6D1),
($00,$01,$80000,$4546B3DB,$4000000000,$1158E460913D,$22A359ED80000,$287F3C1A5B27D7,$200000000000000,$12BF307AE81FFD59),
($00,$01,$100000,$CFD41B91,$10000000000,$56BC75E2D631,$CFD41B9100000,$11B7AA4B87E16E1,$1000000000000000,$A8B8B452291FE821),
($00,$01,$200000,$26F7C52B3,$40000000000,$1B1AE4D6E2EF5,$4DEF8A56600000,$7C05A810B72A027,$8000000000000000,$EE7E56E3721F2929));
function GetPower(X,Y: integer): int64;
{Extract power from table}
begin
Result:=PowersTable[Y,X];
end;
function IsDisarium(N: integer): boolean;
{Sum all powers of the digits raised to position power}
var S: string;
var I,J: integer;
var Sum: int64;
begin
Sum:=0;
S:=IntToStr(N);
for I:=1 to Length(S) do
begin
Sum:=Sum+GetPower(byte(S[I])-$30,I);
end;
Result:=Sum=N;
end;
procedure ShowDisariumNumbers(Memo: TMemo);
{Show Disarium numbers up to specified limit}
{Processes about 5 million numbers per second}
var I,Cnt: int64;
begin
Cnt:=0;
I:=0;
while I<High(int64) do
begin
if IsDisarium(I) then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+': '+IntToStr(I));
if Cnt>=19 then break;
end;
Inc(I);
end;
end;

View file

@ -0,0 +1,37 @@
proc nonrec pow(byte base, exp) word:
word p;
p := 1;
while exp>0 do
p := p*base;
exp := exp-1
od;
p
corp
proc nonrec disarium(word n) bool:
[5]byte digits;
short i, len;
word input_n, dps;
dps := 0;
i := 0;
input_n := n;
while n > 0 do
digits[i] := n % 10;
n := n / 10;
i := i + 1
od;
len := i;
for i from 0 upto len-1 do
dps := dps + pow(digits[i], len-i)
od;
dps = input_n
corp
proc nonrec main() void:
word n;
for n from 0 upto 2500 do
if disarium(n) then writeln(n:5) fi
od
corp

View file

@ -0,0 +1,17 @@
01.10 F N=0,2500;D 2
01.20 Q
02.10 D 3
02.20 I (N-S)2.4,2.3,2.4
02.30 T %5,N,!
02.40 R
03.10 S Z=N;S L=0
03.20 G 3.7
03.30 S K=FITR(Z/10)
03.40 S L=L+1
03.50 S D(L)=Z-K*10
03.60 S Z=K
03.70 I (-Z)3.3
03.80 S S=0
03.90 F I=1,L;S S=S+D(L-I+1)^I

View file

@ -0,0 +1,9 @@
USING: io kernel lists lists.lazy math.ranges math.text.utils
math.vectors prettyprint sequences ;
: disarium? ( n -- ? )
dup 1 digit-groups dup length 1 [a,b] v^ sum = ;
: disarium ( -- list ) 0 lfrom [ disarium? ] lfilter ;
19 disarium ltake [ pprint bl ] leach nl

View file

@ -0,0 +1,19 @@
: pow 1 swap 0 ?do over * loop nip ;
: len 1 swap begin dup 10 >= while 10 / swap 1+ swap repeat drop ;
: dps 0 swap dup len
begin dup while
swap 10 /mod swap
2 pick pow
3 roll +
rot 1- rot
swap
repeat
2drop
;
: disarium dup dps = ;
: disaria 2700000 0 ?do i disarium if i . cr then loop ;
disaria
bye

View file

@ -0,0 +1,184 @@
program disarium;
//compile with fpc -O3 -Xs
{$IFDEF WINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}
{$IFDEF FPC}
{$Mode Delphi}
uses
sysutils;
{$ELSE}
uses
system.SysUtils;
{$ENDIF}
const
MAX_BASE = 16;
cDigits : array[0..MAX_BASE-1] of char =
('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
MAX_DIGIT_CNT = 31;
type
tDgt_cnt= 0..MAX_DIGIT_CNT-1;
tdgtPows = array[tDgt_cnt,0..MAX_BASE] of Uint64;
tdgtMaxSumPot = array[tDgt_cnt] of Uint64;
tmyDigits = record
dgtPot : array[tDgt_cnt] of Uint64;
dgtSumPot : array[tDgt_cnt] of Uint64;
dgtNumber : UInt64;
digit : array[0..31] of byte;
dgtMaxLen : tDgt_cnt;
end;
const
UPPER_LIMIT = 100*1000*1002;
var
{$Align 32}
dgtPows :tdgtPows;
procedure InitMyPots(var mp :tdgtPows;base:int32);
var
pot,dgt:Uint32;
p : Uint64;
begin
fillchar(mp,SizeOf(mp),#0);
For dgt := 0 to BASE do
begin
p := dgt;
For pot in tDgt_cnt do
begin
mp[pot,dgt] := p;
p := p*dgt;
end;
end;
p := 0;
end;
procedure Out_Digits(var md:tmyDigits);
var
i : Int32;
Begin
with md do
begin
write('dgtNumber ',dgtNumber,' = ',dgtSumPot[0],' in Base ');
For i := dgtMaxLen-1 downto 0 do
write(cDigits[digit[i]]);
writeln;
end;
end;
procedure IncByOne(var md:tmyDigits;Base: Int32);inline;
var
PotSum : Uint64;
potBase: nativeInt;
dg,pot,idx : Int32;
Begin
with md do
begin
//first digit seperate
pot := dgtMaxLen-1;
dg := digit[0]+1;
if dg < BASE then
begin
inc(dgtNumber);
digit[0]:= dg;
dgtPot[0] := dgtPows[pot,dg];
dgtSumPot[0] := dgtSumPot[1] + dgtPot[0];
EXIT;
end;
dec(dgtNumber,Base-1);
digit[0]:= 0;
dgtPot[0]:= 0;
dgtSumPot[0] := dgtSumPot[1];
potbase := Base;
idx := 1;
dec(pot);
while pot >= 0 do
Begin
dg := digit[idx]+1;
if dg < BASE then
begin
inc(dgtNumber,potbase);
digit[idx]:= dg;
dgtPot[idx]:= dgtPows[pot,dg];
PotSum := dgtSumPot[idx+1];
//update sum
while idx>=0 do
begin
inc(PotSum,dgtPot[idx]);
dgtSumPot[idx] := PotSum;
dec(idx);
end;
EXIT;
end;
dec(dgtNumber,(dg-1)*PotBase);
potbase *= Base;
digit[idx]:= 0;
dgtPot[idx] := 0;
dec(pot);
inc(idx);
end;
For pot := idx downto 0 do
Begin
dgtPot[idx] :=0;
dgtSumPot[pot] := 1;
end;
digit[idx] := 1;
dgtPot[idx] :=1;
dgtMaxLen := idx+1;
dgtNumber := potbase;
end;
end;
procedure OneRun(var s: tmyDigits;base:UInt32;Limit:Int64);
var
i : int64;
cnt : Int32;
begin
Writeln('Base = ',base);
InitMyPots(dgtPows,base);
fillchar(s,SizeOf(s),#0);
s.dgtMaxLen := 1;
i := 0;
cnt := 0;
repeat
if s.dgtSumPot[0] = s.dgtNumber then
Begin
Out_Digits(s);
inc(cnt);
end;
IncByOne(s,base);
inc(i);
until (i>=Limit);
writeln ( i,' increments and found ',cnt);
end;
var
{$Align 32}
s : tmyDigits;
T0: TDateTime;
base: nativeInt;
Begin
base := 10;
T0 := time;
OneRun(s,base,2646799);
T0 := (time-T0)*86400;
writeln(T0:8:3,' s');
writeln;
base := 11;
T0 := time;
OneRun(s,base,100173172);
T0 := (time-T0)*86400;
writeln(T0:8:3,' s');
writeln;
{$IFDEF WINDOWS}
readln;
{$ENDIF}
end.

View file

@ -0,0 +1,23 @@
#define limite 19
Function isDisarium(n As Integer) As Boolean
Dim As Integer digitos = Len(Str(n))
Dim As Integer suma = 0, x = n
While x <> 0
suma += (x Mod 10) ^ digitos
digitos -= 1
x \= 10
Wend
Return Iif(suma = n, True, False)
End Function
Dim As Integer cont = 0, n = 0, i
Print "The first"; limite; " Disarium numbers are:"
Do While cont < limite
If isDisarium(n) Then
Print n; " ";
cont += 1
End If
n += 1
Loop
Sleep

View file

@ -0,0 +1,17 @@
long c = 0, n = 0, t, i
CFStringRef s
while ( c < 18 )
s = fn StringWithFormat(@"%ld",n)
t = 0
for i = 0 to len(s) - 1
t += intVal(mid(s,i,1))^(i+1)
next
if ( t == n )
print n
c++
end if
n++
wend
HandleEvents

View file

@ -0,0 +1,158 @@
package main
import (
"fmt"
"strconv"
)
const DMAX = 20 // maximum digits
const LIMIT = 20 // maximum number of disariums to find
func main() {
// Pre-calculated exponential and power serials
EXP := make([][]uint64, 1+DMAX)
POW := make([][]uint64, 1+DMAX)
EXP[0] = make([]uint64, 11)
EXP[1] = make([]uint64, 11)
POW[0] = make([]uint64, 11)
POW[1] = make([]uint64, 11)
for i := uint64(1); i <= 10; i++ {
EXP[1][i] = i
}
for i := uint64(1); i <= 9; i++ {
POW[1][i] = i
}
POW[1][10] = 9
for i := 2; i <= DMAX; i++ {
EXP[i] = make([]uint64, 11)
POW[i] = make([]uint64, 11)
}
for i := 1; i < DMAX; i++ {
for j := 0; j <= 9; j++ {
EXP[i+1][j] = EXP[i][j] * 10
POW[i+1][j] = POW[i][j] * uint64(j)
}
EXP[i+1][10] = EXP[i][10] * 10
POW[i+1][10] = POW[i][10] + POW[i+1][9]
}
// Digits of candidate and values of known low bits
DIGITS := make([]int, 1+DMAX) // Digits form
Exp := make([]uint64, 1+DMAX) // Number form
Pow := make([]uint64, 1+DMAX) // Powers form
var exp, pow, min, max uint64
start := 1
final := DMAX
count := 0
for digit := start; digit <= final; digit++ {
fmt.Println("# of digits:", digit)
level := 1
DIGITS[0] = 0
for {
// Check limits derived from already known low bit values
// to find the most possible candidates
for 0 < level && level < digit {
// Reset path to try next if checking in level is done
if DIGITS[level] > 9 {
DIGITS[level] = 0
level--
DIGITS[level]++
continue
}
// Update known low bit values
Exp[level] = Exp[level-1] + EXP[level][DIGITS[level]]
Pow[level] = Pow[level-1] + POW[digit+1-level][DIGITS[level]]
// Max possible value
pow = Pow[level] + POW[digit-level][10]
if pow < EXP[digit][1] { // Try next since upper limit is invalidly low
DIGITS[level]++
continue
}
max = pow % EXP[level][10]
pow -= max
if max < Exp[level] {
pow -= EXP[level][10]
}
max = pow + Exp[level]
if max < EXP[digit][1] { // Try next since upper limit is invalidly low
DIGITS[level]++
continue
}
// Min possible value
exp = Exp[level] + EXP[digit][1]
pow = Pow[level] + 1
if exp > max || max < pow { // Try next since upper limit is invalidly low
DIGITS[level]++
continue
}
if pow > exp {
min = pow % EXP[level][10]
pow -= min
if min > Exp[level] {
pow += EXP[level][10]
}
min = pow + Exp[level]
} else {
min = exp
}
// Check limits existence
if max < min {
DIGITS[level]++ // Try next number since current limits invalid
} else {
level++ // Go for further level checking since limits available
}
}
// All checking is done, escape from the main check loop
if level < 1 {
break
}
// Finally check last bit of the most possible candidates
// Update known low bit values
Exp[level] = Exp[level-1] + EXP[level][DIGITS[level]]
Pow[level] = Pow[level-1] + POW[digit+1-level][DIGITS[level]]
// Loop to check all last bits of candidates
for DIGITS[level] < 10 {
// Print out new Disarium number
if Exp[level] == Pow[level] {
s := ""
for i := DMAX; i > 0; i-- {
s += fmt.Sprintf("%d", DIGITS[i])
}
n, _ := strconv.ParseUint(s, 10, 64)
fmt.Println(n)
count++
if count == LIMIT {
fmt.Println("\nFound the first", LIMIT, "Disarium numbers.")
return
}
}
// Go to followed last bit candidate
DIGITS[level]++
Exp[level] += EXP[level][1]
Pow[level]++
}
// Reset to try next path
DIGITS[level] = 0
level--
DIGITS[level]++
}
fmt.Println()
}
}

View file

@ -0,0 +1,10 @@
module Disarium
where
import Data.Char ( digitToInt)
isDisarium :: Int -> Bool
isDisarium n = (sum $ map (\(c , i ) -> (digitToInt c ) ^ i )
$ zip ( show n ) [1 , 2 ..]) == n
solution :: [Int]
solution = take 18 $ filter isDisarium [0, 1 ..]

View file

@ -0,0 +1,4 @@
digits=: 10 #.inv ]
disarium=: (= (+/ .^ #\)@digits)"0
I.disarium i.1e4
0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427

View file

@ -0,0 +1,29 @@
import java.lang.Math;
public class DisariumNumbers {
public static boolean is_disarium(int num) {
int n = num;
int len = Integer.toString(n).length();
int sum = 0;
int i = 1;
while (n > 0) {
sum += Math.pow(n % 10, len - i + 1);
n /= 10;
i ++;
}
return sum == num;
}
public static void main(String[] args) {
int i = 0;
int count = 0;
while (count <= 18) {
if (is_disarium(i)) {
System.out.printf("%d ", i);
count++;
}
i++;
}
System.out.printf("%s", "\n");
}
}

View file

@ -0,0 +1,20 @@
function is_disarium (num) {
let n = num
let len = n.toString().length
let sum = 0
while (n > 0) {
sum += (n % 10) ** len
n = parseInt(n / 10, 10)
len--
}
return num == sum
}
let count = 0
let i = 1
while (count < 18) {
if (is_disarium(i)) {
process.stdout.write(i + " ")
count++
}
i++
}

View file

@ -0,0 +1,18 @@
# To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($in;$b): reduce range(0;$b) as $i (1; . * $in);
# $n is assumed to be a non-negative integer
def is_disarium:
. as $n
| {$n, sum: 0, len: (tostring|length) }
| until (.n == 0;
.sum += power(.n % 10; .len)
| .n = (.n/10 | floor)
| .len -= 1 )
| .sum == $n ;
# Emit a stream ...
def disariums:
range(0; infinite) | select(is_disarium);
limit(19; disariums)

View file

@ -0,0 +1,13 @@
isdisarium(n) = sum(last(p)^first(p) for p in enumerate(reverse(digits(n)))) == n
function disariums(numberwanted)
n, ret = 0, Int[]
while length(ret) < numberwanted
isdisarium(n) && push!(ret, n)
n += 1
end
return ret
end
println(disariums(19))
@time disariums(19)

View file

@ -0,0 +1,29 @@
fun power(n: Int, exp: Int): Int {
return when {
exp > 1 -> n * power(n, exp-1)
exp == 1 -> n
else -> 1
}
}
fun is_disarium(num: Int): Boolean {
val n = num.toString()
var sum = 0
for (i in 1..n.length) {
sum += power (n[i-1] - '0', i)
}
return sum == num
}
fun main() {
var i = 0
var count = 0
while (count < 19) {
if (is_disarium(i)) {
print("$i ")
count++
}
i++
}
println("")
}

View file

@ -0,0 +1,17 @@
function isDisarium (x)
local str, sum, digit = tostring(x), 0
for pos = 1, #str do
digit = tonumber(str:sub(pos, pos))
sum = sum + (digit ^ pos)
end
return sum == x
end
local count, n = 0, 0
while count < 19 do
if isDisarium(n) then
count = count + 1
io.write(n .. " ")
end
n = n + 1
end

View file

@ -0,0 +1,42 @@
NORMAL MODE IS INTEGER
VECTOR VALUES FMT = $ I7*$
AMOUNT = 19
THROUGH TEST, FOR CAND=0, 1, AMOUNT.E.0
WHENEVER DISARI.(CAND)
PRINT FORMAT FMT,CAND
AMOUNT = AMOUNT-1
END OF CONDITIONAL
TEST CONTINUE
INTERNAL FUNCTION(N)
ENTRY TO LENGTH.
L = 0
THROUGH COUNT, FOR NN=N, 0, NN.E.0
L = L+1
COUNT NN = NN/10
FUNCTION RETURN L
END OF FUNCTION
INTERNAL FUNCTION(BASE,EXP)
ENTRY TO RAISE.
R = 1
THROUGH MUL, FOR E=EXP, -1, E.E.0
MUL R = R*BASE
FUNCTION RETURN R
END OF FUNCTION
INTERNAL FUNCTION(N)
ENTRY TO DISARI.
L = LENGTH.(N)
POWSUM = 0
THROUGH DGTLP, FOR NN=N, 0, NN.E.0
NX = NN/10
DG = NN-NX*10
POWSUM = POWSUM+RAISE.(DG,L)
L = L-1
DGTLP NN = NX
FUNCTION RETURN POWSUM.E.N
END OF FUNCTION
END OF PROGRAM

View file

@ -0,0 +1,16 @@
ClearAll[DisariumQ]
DisariumQ[n_Integer] := Module[{digs},
digs = IntegerDigits[n];
digs = digs^Range[Length[digs]];
Total[digs] == n
]
i = 0;
Reap[Do[
If[DisariumQ[n],
i++;
Sow[n]
];
If[i == 19, Break[]]
,
{n, 0, \[Infinity]}
]][[2, 1]]

View file

@ -0,0 +1,18 @@
main :: [sys_message]
main = [Stdout (show (take 18 disaria)), Stdout "\n"]
disaria :: [num]
disaria = filter disarium [0..]
disarium :: num->bool
disarium n = n = sum (zipWith (^) (digits n) [1..])
digits :: num->[num]
digits 0 = [0]
digits n = reverse (digits' n)
where digits' 0 = []
digits' n = (n mod 10) : digits' (n div 10)
zipWith :: (* -> ** -> ***) -> [*] -> [**] -> [***]
zipWith f x y = map f' (zip2 x y)
where f' (x,y) = f x y

View file

@ -0,0 +1,51 @@
MODULE DisariumNumbers;
FROM InOut IMPORT WriteLn, WriteCard;
CONST Max = 2500;
VAR n: CARDINAL;
PROCEDURE cpow(base, power: CARDINAL): CARDINAL;
VAR i, result: CARDINAL;
BEGIN
result := 1;
FOR i := 1 TO power DO
result := result * base
END;
RETURN result
END cpow;
PROCEDURE length(n: CARDINAL): CARDINAL;
VAR len: CARDINAL;
BEGIN
len := 1;
WHILE n > 10 DO
INC(len);
n := n DIV 10
END;
RETURN len
END length;
PROCEDURE digitpowersum(n: CARDINAL): CARDINAL;
VAR powsum, exp: CARDINAL;
BEGIN
powsum := 0;
FOR exp := length(n) TO 1 BY -1 DO
powsum := powsum + cpow(n MOD 10, exp);
n := n DIV 10
END;
RETURN powsum
END digitpowersum;
PROCEDURE disarium(n: CARDINAL): BOOLEAN;
BEGIN
RETURN digitpowersum(n) = n
END disarium;
BEGIN
FOR n := 0 TO Max DO
IF disarium(n) THEN
WriteCard(n, 5);
WriteLn
END
END
END DisariumNumbers.

View file

@ -0,0 +1,18 @@
import strutils
import math
proc is_disarium(num: int): bool =
let n = intToStr(num)
var sum = 0
for i in 0..len(n)-1:
sum += int((int(n[i])-48) ^ (i+1))
return sum == num
var i = 0
var count = 0
while count < 19:
if is_disarium(i):
stdout.write i, " "
count += 1
i += 1
echo ""

View file

@ -0,0 +1,17 @@
(* speed-optimized exponentiation; doesn't support exponents < 2 *)
let rec pow b n =
if n land 1 = 0
then if n = 2 then b * b else pow (b * b) (n lsr 1)
else if n = 3 then b * b * b else b * pow (b * b) (n lsr 1)
let is_disarium n =
let rec aux x f =
if x < 10
then f 2 x
else aux (x / 10) (fun l y -> f (succ l) (y + pow (x mod 10) l))
in
n = aux n Fun.(const id)
let () =
Seq.(ints 0 |> filter is_disarium |> take 19 |> iter (Printf.printf " %u%!"))
|> print_newline

View file

@ -0,0 +1,70 @@
100H: /* FIND SOME DISARIUM NUMBERS - NUMBERS WHOSE DIGIT POSITION-POWER */
/* SUMS ARE EQUAL TO THE NUMBER, E.G. 135 = 1^1 + 3^2 + 5^3 */
/* CP/M BDOS SYSTEM CALL, IGNORE THE RETURN VALUE */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
/* TABLE OF POWERS UP TO THE FOURTH POWER - AS WE ARE ONLY FINDING THE */
/* DISARIUM NUMBERS UP TO 9999 */
DECLARE POWER( 40 /* ( 1 : 4, 0 : 9 ) */ ) ADDRESS;
DECLARE MAX$DISARIUM LITERALLY '9999';
DECLARE ( N, D, POWER$OF$TEN, COUNT, LENGTH, V, P, DPS, NSUB, NPREV )
ADDRESS;
/* COMPUTE THE NTH POWERS OF 0-9 */
DO D = 0 TO 9; POWER( D ) = D; END;
NSUB = 10;
NPREV = 0;
DO N = 2 TO 4;
POWER( NSUB ) = 0;
DO D = 1 TO 9;
POWER( NSUB + D ) = POWER( NPREV + D ) * D;
END;
NPREV = NSUB;
NSUB = NSUB + 10;
END;
/* PRINT THE DISARIUM NUMBERS UPTO 9999 OR THE 18TH, WHICHEVER IS SOONER */
POWER$OF$TEN = 10;
LENGTH = 1;
COUNT, N = 0;
DO WHILE( N < MAX$DISARIUM AND COUNT < 18 );
IF N = POWER$OF$TEN THEN DO;
/* THE NUMBER OF DIGITS JUST INCREASED */
POWER$OF$TEN = POWER$OF$TEN * 10;
LENGTH = LENGTH + 1;
END;
/* FORM THE DIGIT POWER SUM */
V = N;
P = LENGTH * 10;
DPS = 0;
DO D = 1 TO LENGTH;
P = P - 10;
DPS = DPS + POWER( P + ( V MOD 10 ) );
V = V / 10;
END;
IF DPS = N THEN DO;
/* N IS DISARIUM */
COUNT = COUNT + 1;
CALL PR$CHAR( ' ' );
CALL PR$NUMBER( N );
END;
N = N + 1;
END;
EOF

View file

@ -0,0 +1,11 @@
use strict;
use warnings;
my ($n,@D) = (0, 0);
while (++$n) {
my($m,$sum);
map { $sum += $_ ** ++$m } split '', $n;
push @D, $n if $n == $sum;
last if 19 == @D;
}
print "@D\n";

View file

@ -0,0 +1,18 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">19</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 19 Disarium numbers are:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">limit</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">dsum</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">digits</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">dsum</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]-</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">dsum</span><span style="color: #0000FF;">=</span><span style="color: #000000;">n</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--

View file

@ -0,0 +1,131 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #000080;font-style:italic;">-- translation of https://github.com/rgxgr/Disarium-Numbers/blob/master/Disarium.c</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">DMAX</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">64</span><span style="color: #0000FF;">?</span><span style="color: #000000;">20</span><span style="color: #0000FF;">:</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">// Pre-calculated exponential & power serials</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">exps</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">DMAX</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">pows</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">DMAX</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">}}</span>
<span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">9</span><span style="color: #0000FF;">}}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">DMAX</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">10</span>
<span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]*(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">10</span>
<span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">10</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000080;font-style:italic;">// Digits of candidate and values of known low bits</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">digits</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">DMAX</span><span style="color: #0000FF;">),</span> <span style="color: #000080;font-style:italic;">// Digits form</span>
<span style="color: #000000;">expl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">DMAX</span><span style="color: #0000FF;">),</span> <span style="color: #000080;font-style:italic;">// Number form</span>
<span style="color: #000000;">powl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">DMAX</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">// Powers form</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (exclude console setup from timings [if pw.exe])</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">expn</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">powr</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">minn</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">maxx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">(),</span> <span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t0</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">digit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">DMAX</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Searching %d digits (started at %s):\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)});</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">level</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #000080;font-style:italic;">// Check limits derived from already known low bit values
// to find the most possible candidates</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">1</span><span style="color: #0000FF;"><</span><span style="color: #000000;">level</span> <span style="color: #008080;">and</span> <span style="color: #000000;">level</span><span style="color: #0000FF;"><</span><span style="color: #000000;">digit</span> <span style="color: #008080;">do</span>
<span style="color: #000080;font-style:italic;">// Reset path to try next if checking in level is done</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">dl</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">dl</span><span style="color: #0000FF;">></span><span style="color: #000000;">10</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">;</span>
<span style="color: #000000;">level</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">else</span>
<span style="color: #000080;font-style:italic;">// Update known low bit values</span>
<span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">][</span><span style="color: #000000;">dl</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">-</span><span style="color: #000000;">level</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">][</span><span style="color: #000000;">dl</span><span style="color: #0000FF;">]</span>
<span style="color: #000080;font-style:italic;">// Max possible value</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">-</span><span style="color: #000000;">level</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">ed2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">powr</span><span style="color: #0000FF;"><</span><span style="color: #000000;">ed2</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">// Try next since upper limit is invalidly low</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">else</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">el11</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">][</span><span style="color: #000000;">11</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">el</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">maxx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powr</span><span style="color: #0000FF;">,</span><span style="color: #000000;">el11</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">maxx</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">maxx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">el</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">el11</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">maxx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powr</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">el</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">maxx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">ed2</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">// Try next since upper limit is invalidly low</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">else</span>
<span style="color: #000080;font-style:italic;">// Min possible value</span>
<span style="color: #000000;">expn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">el</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">ed2</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">expn</span><span style="color: #0000FF;">></span><span style="color: #000000;">maxx</span> <span style="color: #008080;">or</span> <span style="color: #000000;">maxx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">powr</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">// Try next since upper limit is invalidly low</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">else</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">powr</span><span style="color: #0000FF;">></span><span style="color: #000000;">expn</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">minn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powr</span><span style="color: #0000FF;">,</span><span style="color: #000000;">el11</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">minn</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">minn</span><span style="color: #0000FF;">></span><span style="color: #000000;">el</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">powr</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">el11</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">minn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powr</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">el</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">minn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">expn</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">// Check limits existence</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">maxx</span><span style="color: #0000FF;"><</span><span style="color: #000000;">minn</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span><span style="color: #000000;">1</span> <span style="color: #000080;font-style:italic;">// Try next number since current limits invalid</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">level</span> <span style="color: #0000FF;">+=</span><span style="color: #000000;">1</span> <span style="color: #000080;font-style:italic;">// Go for further level checking since limits available</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()></span><span style="color: #000000;">t1</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"working:%v... (%s)"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)})</span>
<span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000080;font-style:italic;">// All checking is done, escape from the main check loop</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">level</span><span style="color: #0000FF;"><</span><span style="color: #000000;">2</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">// Final check last bit of the most possible candidates
// Update known low bit values</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">dlx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]+</span><span style="color: #000000;">1</span>
<span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">][</span><span style="color: #000000;">dlx</span><span style="color: #0000FF;">];</span>
<span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">pows</span><span style="color: #0000FF;">[</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">-</span><span style="color: #000000;">level</span><span style="color: #0000FF;">][</span><span style="color: #000000;">dlx</span><span style="color: #0000FF;">];</span>
<span style="color: #000080;font-style:italic;">// Loop to check all last bit of candidates</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]<</span><span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #000080;font-style:italic;">// Print out new disarium number</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ld</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">trim_tail</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">),</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">ld</span><span style="color: #0000FF;">],</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">),</span><span style="color: #008000;">""</span><span style="color: #0000FF;">))})</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">// Go to followed last bit candidate</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">expl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">exps</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">powl</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000080;font-style:italic;">// Reset to try next path</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">;</span>
<span style="color: #000000;">level</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">level</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d disarium numbers found (%s)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)})</span>
<!--

View file

@ -0,0 +1,26 @@
main =>
Limit = 19,
D = [],
N = 0,
printf("The first %d Disarium numbers are:\n",Limit),
while (D.len < Limit)
if disarium_number(N) then
D := D ++ [N]
end,
N := N + 1,
if N mod 10_000_000 == 0 then
println(test=N)
end
end,
println(D).
disarium_number(N) =>
Sum = 0,
Digits = N.to_string.len,
X = N,
while (X != 0, Sum <= N)
Sum := Sum + (X mod 10) ** Digits,
Digits := Digits - 1,
X := X div 10
end,
Sum == N.

View file

@ -0,0 +1,36 @@
import sat.
% import cp.
main =>
D = [],
Limit = 19,
Base = 10,
foreach(Len in 1..20, D.len < Limit)
Nums = disarium_number_cp(Len,Base),
if Nums.len > 0 then
foreach(Num in Nums)
B = to_radix_string(Num,Base),
D := D ++ [B]
end
end
end,
printf("The first %d Disarius numbers in base %d:\n",D.len, Base),
println(D[1..Limit]),
nl.
% Find all Disarium of a certain length
disarium_number_cp(Len,Base) = findall(N,disarium_number_cp(Len,Base,N)).sort.
% Find a Disarium number of a certain length
disarium_number_cp(Len,Base,N) =>
X = new_list(Len),
X :: 0..Base-1,
N :: Base**(Len-1)-1..Base**Len-1,
N #= sum([X[I]**I : I in 1..Len]),
to_num(X,Base,N), % convert X <=> N
solve($[],X++[N]).
% Converts a number Num to/from a list of integer List given a base Base
to_num(List, Base, Num) =>
Len = length(List),
Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).

View file

@ -0,0 +1,31 @@
Procedure isDisarium(n.i)
digitos.i = Len(Str(n))
suma.i = 0
x.i = n
While x <> 0
r.i = (x % 10)
suma + Pow(r, digitos)
digitos - 1
x / 10
Wend
If suma = n
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
OpenConsole()
limite.i = 19
cont.i = 0
n.i = 0
PrintN("The first" + Str(limite) + " Disarium numbers are:")
While cont < limite
If isDisarium(n)
Print(Str(n) + #TAB$)
cont + 1
EndIf
n + 1
Wend
Input()
CloseConsole()

View file

@ -0,0 +1,25 @@
#!/usr/bin/python
def isDisarium(n):
digitos = len(str(n))
suma = 0
x = n
while x != 0:
suma += (x % 10) ** digitos
digitos -= 1
x //= 10
if suma == n:
return True
else:
return False
if __name__ == '__main__':
limite = 19
cont = 0
n = 0
print("The first",limite,"Disarium numbers are:")
while cont < limite:
if isDisarium(n):
print(n, end = " ")
cont += 1
n += 1

View file

@ -0,0 +1,19 @@
[ [ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] ] is digits ( n --> [ )
[ 0 over digits
witheach
[ i^ 1+ ** + ] = ] is disarium ( n --> b )
[ temp put [] 0
[ dup disarium if
[ dup dip join ]
1+
over size
temp share = until ]
drop ] is disariums ( n --> [ )
19 disariums echo

View file

@ -0,0 +1,4 @@
my $disarium = (^).hyper.map: { $_ if $_ == sum .polymod(10 xx *).reverse Z** 1..* };
put $disarium[^18];
put $disarium[18];

View file

@ -0,0 +1,25 @@
i = 0
count = 0
while count < 19
if is_disarium(i)
see "" + i + " "
count++
ok
i++
end
see nl
func pow (base, exp)
result = 1
for i = 0 to exp - 1
result *= base
next
return result
func is_disarium (num)
n = "" + num
sum = 0
for i = 1 to len(n)
sum += pow (n[i] % 10, i)
next
return sum = num

View file

@ -0,0 +1,8 @@
disariums = Enumerator.new do |y|
(0..).each do |n|
i = 0
y << n if n.digits.reverse.sum{|d| d ** (i+=1) } == n
end
end
puts disariums.take(19).to_a.join(" ")

View file

@ -0,0 +1,21 @@
function isDisarium(n)
digitos = len(str$(n))
suma = 0 : x = n
while x <> 0
r = (x mod 10)
suma = suma + (r ^ digitos)
digitos = digitos - 1
x = int(x / 10)
wend
if suma = n then isDisarium = 1 else isDisarium = 0
end function
limite = 18 : cont = 0 : n = 0
print "The first"; limite; " Disarium numbers are:"
while cont < limite
if isDisarium(n) = 1 then
print n; " ";
cont = cont + 1
end if
n = n + 1
wend

View file

@ -0,0 +1,34 @@
fn power(n: i32, exp: i32) -> i32 {
let mut result = 1;
for _i in 0..exp {
result *= n;
}
return result;
}
fn is_disarium(num: i32) -> bool {
let mut n = num;
let mut sum = 0;
let mut i = 1;
let len = num.to_string().len();
while n > 0 {
sum += power(n % 10, len as i32 - i + 1);
n /= 10;
i += 1
}
return sum == num;
}
fn main() {
let mut i = 0;
let mut count = 0;
while count <= 18 {
if is_disarium(i) {
print!("{} ", i);
count += 1;
}
i += 1;
}
println!("{}", " ")
}

View file

@ -0,0 +1,28 @@
object Disarium extends App {
def power(base: Int, exp: Int): Int = {
var result = 1
for (i <- 1 to exp) {
result *= base
}
return result
}
def is_disarium(num: Int): Boolean = {
val digits = num.toString.split("")
var sum = 0
for (i <- 0 to (digits.size - 1)) {
sum += power(digits(i).toInt, i + 1)
}
return num == sum
}
var i = 0
var count = 0
while (count < 19) {
if (is_disarium(i)) {
count += 1
printf("%d ", i)
}
i += 1
}
println("")
}

View file

@ -0,0 +1,5 @@
func is_disarium(n) {
n.digits.flip.sum_kv{|k,d| d**(k+1) } == n
}
say 18.by(is_disarium)

View file

@ -0,0 +1,22 @@
proc is_disarium {num} {
set n num
set sum 0
set i 1
set ch 1
foreach char [split $num {}] {
scan $char %d ch
set sum [ expr ($sum + $ch ** $i)]
incr i
}
return [ expr $num == $sum ? 1 : 0]
}
set i 0
set count 0
while { $count < 19 } {
if [ is_disarium $i ] {
puts -nonewline "${i} "
incr count
}
incr i
}
puts ""

View file

@ -0,0 +1,25 @@
FUNCTION isDisarium(n)
LET digitos = LEN(str$(n))
LET suma = 0
LET x = n
DO WHILE x <> 0
LET r = REMAINDER(x, 10)
LET suma = suma + (r ^ digitos)
LET digitos = digitos - 1
LET x = INT(x / 10)
LOOP
IF suma = n THEN LET isDisarium = 1 ELSE LET isDisarium = 0
END FUNCTION
LET limite = 18
LET cont = 0
LET n = 0
PRINT "The first"; limite; " Disarium numbers are:"
DO WHILE cont < limite
IF isDisarium(n) = 1 THEN
PRINT n; " ";
LET cont = cont + 1
END IF
LET n = n + 1
LOOP
END

View file

@ -0,0 +1,145 @@
import strconv
const dmax = 20 // maximum digits
const limit = 20 // maximum number of disariums to find
fn main() {
// Pre-calculated exponential and power serials
mut exp1 := [][]u64{len: 1+dmax, init: []u64{len: 11}}
mut pow1 := [][]u64{len: 1+dmax, init: []u64{len: 11}}
for i := u64(1); i <= 10; i++ {
exp1[1][i] = i
}
for i := u64(1); i <= 9; i++ {
pow1[1][i] = i
}
pow1[1][10] = 9
for i := 1; i < dmax; i++ {
for j := 0; j <= 9; j++ {
exp1[i+1][j] = exp1[i][j] * 10
pow1[i+1][j] = pow1[i][j] * u64(j)
}
exp1[i+1][10] = exp1[i][10] * 10
pow1[i+1][10] = pow1[i][10] + pow1[i+1][9]
}
// Digits of candidate and values of known low bits
mut digits := []int{len: 1+dmax} // Digits form
mut exp2 := []u64{len: 1+dmax} // Number form
mut pow2 := []u64{len: 1+dmax} // pow2ers form
mut exp, mut pow, mut min, mut max := u64(0),u64(0),u64(0),u64(0)
start := 1
final := dmax
mut count := 0
for digit := start; digit <= final; digit++ {
println("# of digits: $digit")
mut level := 1
digits[0] = 0
for {
// Check limits derived from already known low bit values
// to find the most possible candidates
for 0 < level && level < digit {
// Reset path to try next if checking in level is done
if digits[level] > 9 {
digits[level] = 0
level--
digits[level]++
continue
}
// Update known low bit values
exp2[level] = exp2[level-1] + exp1[level][digits[level]]
pow2[level] = pow2[level-1] + pow1[digit+1-level][digits[level]]
// Max possible value
pow = pow2[level] + pow1[digit-level][10]
if pow < exp1[digit][1] { // Try next since upper limit is invalidly low
digits[level]++
continue
}
max = pow % exp1[level][10]
pow -= max
if max < exp2[level] {
pow -= exp1[level][10]
}
max = pow + exp2[level]
if max < exp1[digit][1] { // Try next since upper limit is invalidly low
digits[level]++
continue
}
// Min possible value
exp = exp2[level] + exp1[digit][1]
pow = pow2[level] + 1
if exp > max || max < pow { // Try next since upper limit is invalidly low
digits[level]++
continue
}
if pow > exp {
min = pow % exp1[level][10]
pow -= min
if min > exp2[level] {
pow += exp1[level][10]
}
min = pow + exp2[level]
} else {
min = exp
}
// Check limits existence
if max < min {
digits[level]++ // Try next number since current limits invalid
} else {
level++ // Go for further level checking since limits available
}
}
// All checking is done, escape from the main check loop
if level < 1 {
break
}
// Finally check last bit of the most possible candidates
// Update known low bit values
exp2[level] = exp2[level-1] + exp1[level][digits[level]]
pow2[level] = pow2[level-1] + pow1[digit+1-level][digits[level]]
// Loop to check all last bits of candidates
for digits[level] < 10 {
// Print out new Disarium number
if exp2[level] == pow2[level] {
mut s := ""
for i := dmax; i > 0; i-- {
s += "${digits[i]}"
}
n, _ := strconv.common_parse_uint2(s, 10, 64)
println(n)
count++
if count == limit {
println("\nFound the first $limit Disarium numbers.")
return
}
}
// Go to followed last bit candidate
digits[level]++
exp2[level] += exp1[level][1]
pow2[level]++
}
// Reset to try next path
digits[level] = 0
level--
digits[level]++
}
println('')
}
}

View file

@ -0,0 +1,33 @@
1000 N=1
1010 D=0
1020 :N*10+D)=D
1030 D=D+1
1040 #=D<10*1020
1050 N=2
1060 :N*10)=0
1070 D=1
1080 :N*10+D)=:N-1*10+D)*D
1090 D=D+1
1100 #=D<10*1080
1120 N=N+1
1130 #=N<5*1060
2000 C=0
2010 T=10
2020 L=1
2030 N=0
2040 #=N=T=0*2070
2050 T=T*10
2060 L=L+1
2070 V=N
2080 P=L
2090 S=0
2100 V=V/10
2110 S=S+:P*10+%
2120 P=P-1
2130 #=V>1*(S-1<N)*2100
2140 #=S=N=0*2180
2150 C=C+1
2160 $=32
2170 ?=N
2180 N=N+1
2190 #=C<18*2040

View file

@ -0,0 +1,18 @@
import "./math" for Int
var limit = 19
var count = 0
var disarium = []
var n = 0
while (count < limit) {
var sum = 0
var digits = Int.digits(n)
for (i in 0...digits.count) sum = sum + digits[i].pow(i+1)
if (sum == n) {
disarium.add(n)
count = count + 1
}
n = n + 1
}
System.print("The first 19 Disarium numbers are:")
System.print(disarium)

View file

@ -0,0 +1,136 @@
var DMAX = 7 // maxmimum digits
var LIMIT = 19 // maximum number of Disariums to find
// Pre-calculated exponential and power serials
var EXP = List.filled(1 + DMAX, null)
var POW = List.filled(1 + DMAX, null)
EXP[0] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
EXP[1] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
POW[0] = List.filled(11, 0)
POW[1] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9]
for (i in 2..DMAX) {
EXP[i] = List.filled(11, 0)
POW[i] = List.filled(11, 0)
}
for (i in 1...DMAX) {
for (j in 0..9) {
EXP[i+1][j] = EXP[i][j] * 10
POW[i+1][j] = POW[i][j] * j
}
EXP[i+1][10] = EXP[i][10] * 10
POW[i+1][10] = POW[i][10] + POW[i+1][9]
}
// Digits of candidate and values of known low bits
var DIGITS = List.filled(1 + DMAX, 0) // Digits form
var Exp = List.filled(1 + DMAX, 0) // Number form
var Pow = List.filled(1 + DMAX, 0) // Powers form
var exp
var pow
var min
var max
var start = 1
var final = DMAX
var count = 0
for (digit in start..final) {
System.print("# of digits: %(digit)")
var level = 1
DIGITS[0] = 0
while (true) {
// Check limits derived from already known low bit values
// to find the most possible candidates
while (0 < level && level < digit) {
// Reset path to try next if checking in level is done
if (DIGITS[level] > 9) {
DIGITS[level] = 0
level = level - 1
DIGITS[level] = DIGITS[level] + 1
continue
}
// Update known low bit values
Exp[level] = Exp[level - 1] + EXP[level][DIGITS[level]]
Pow[level] = Pow[level - 1] + POW[digit + 1 - level][DIGITS[level]]
// Max possible value
pow = Pow[level] + POW[digit - level][10]
if (pow < EXP[digit][1]) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
max = pow % EXP[level][10]
pow = pow - max
if (max < Exp[level]) pow = pow - EXP[level][10]
max = pow + Exp[level]
if (max < EXP[digit][1]) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
// Min possible value
exp = Exp[level] + EXP[digit][1]
pow = Pow[level] + 1
if (exp > max || max < pow) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
if (pow > exp ) {
min = pow % EXP[level][10]
pow = pow - min
if (min > Exp[level]) {
pow = pow + EXP[level][10]
}
min = pow + Exp[level]
} else {
min = exp
}
// Check limits existence
if (max < min) {
DIGITS[level] = DIGITS[level] + 1 // Try next number since current limits invalid
} else {
level= level + 1 // Go for further level checking since limits available
}
}
// All checking is done, escape from the main check loop
if (level < 1) break
// Finally check last bit of the most possible candidates
// Update known low bit values
Exp[level] = Exp[level - 1] + EXP[level][DIGITS[level]]
Pow[level] = Pow[level - 1] + POW[digit + 1 - level][DIGITS[level]]
// Loop to check all last bits of candidates
while (DIGITS[level] < 10) {
// Print out new Disarium number
if (Exp[level] == Pow[level]) {
var s = ""
for (i in DMAX...0) s = s + DIGITS[i].toString
System.print(Num.fromString(s))
count = count + 1
if (count == LIMIT) {
System.print("\nFound the first %(LIMIT) Disarium numbers.")
return
}
}
// Go to followed last bit candidate
DIGITS[level] = DIGITS[level] + 1
Exp[level] = Exp[level] + EXP[level][1]
Pow[level] = Pow[level] + 1
}
// Reset to try next path
DIGITS[level] = 0
level = level - 1
DIGITS[level] = DIGITS[level] + 1
}
System.print()
}

View file

@ -0,0 +1,162 @@
import "./i64" for U64
var DMAX = 20 // maxmimum digits
var LIMIT = 20 // maximum number of disariums to find
// Pre-calculated exponential and power serials
var EXP = List.filled(1 + DMAX, null)
var POW = List.filled(1 + DMAX, null)
EXP[0] = List.filled(11, null)
EXP[1] = List.filled(11, null)
POW[0] = List.filled(11, null)
POW[1] = List.filled(11, null)
for (i in 0..9) EXP[0][i] = U64.zero
EXP[0][10] = U64.one
for (i in 0..10) EXP[1][i] = U64.from(i)
for (i in 0..10) POW[0][i] = U64.zero
for (i in 0..9) POW[1][i] = U64.from(i)
POW[1][10] = U64.from(9)
for (i in 2..DMAX) {
EXP[i] = List.filled(11, null)
POW[i] = List.filled(11, null)
for (j in 0..10) {
EXP[i][j] = U64.zero
POW[i][j] = U64.zero
}
}
for (i in 1...DMAX) {
for (j in 0..9) {
EXP[i+1][j] = EXP[i][j] * 10
POW[i+1][j] = POW[i][j] * j
}
EXP[i+1][10] = EXP[i][10] * 10
POW[i+1][10] = POW[i][10] + POW[i+1][9]
}
// Digits of candidate and values of known low bits
var DIGITS = List.filled(1 + DMAX, 0) // Digits form
var Exp = List.filled(1 + DMAX, null) // Number form
var Pow = List.filled(1 + DMAX, null) // Powers form
for (i in 0..DMAX) {
Exp[i] = U64.zero
Pow[i] = U64.zero
}
var exp = U64.new()
var pow = U64.new()
var min = U64.new()
var max = U64.new()
var start = 1
var final = DMAX
var count = 0
for (digit in start..final) {
System.print("# of digits: %(digit)")
var level = 1
DIGITS[0] = 0
while (true) {
// Check limits derived from already known low bit values
// to find the most possible candidates
while (0 < level && level < digit) {
// Reset path to try next if checking in level is done
if (DIGITS[level] > 9) {
DIGITS[level] = 0
level = level - 1
DIGITS[level] = DIGITS[level] + 1
continue
}
// Update known low bit values
Exp[level].add(Exp[level - 1], EXP[level][DIGITS[level]])
Pow[level].add(Pow[level - 1], POW[digit + 1 - level][DIGITS[level]])
// Max possible value
pow.add(Pow[level], POW[digit - level][10])
if (pow < EXP[digit][1]) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
max.rem(pow, EXP[level][10])
pow.sub(max)
if (max < Exp[level]) pow.sub(EXP[level][10])
max.add(pow, Exp[level])
if (max < EXP[digit][1]) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
// Min possible value
exp.add(Exp[level], EXP[digit][1])
pow.add(Pow[level], 1)
if (exp > max || max < pow) { // Try next since upper limit is invalidly low
DIGITS[level] = DIGITS[level] + 1
continue
}
if (pow > exp ) {
min.rem(pow, EXP[level][10])
pow.sub(min)
if (min > Exp[level]) {
pow.add(EXP[level][10])
}
min.add(pow, Exp[level])
} else {
min.set(exp)
}
// Check limits existence
if (max < min) {
DIGITS[level] = DIGITS[level] + 1 // Try next number since current limits invalid
} else {
level = level + 1 // Go for further level checking since limits available
}
}
// All checking is done, escape from the main check loop
if (level < 1) break
// Final check last bit of the most possible candidates
// Update known low bit values
Exp[level].add(Exp[level - 1], EXP[level][DIGITS[level]])
Pow[level].add(Pow[level - 1], POW[digit + 1 - level][DIGITS[level]])
// Loop to check all last bit of candidates
while (DIGITS[level] < 10) {
// Print out new disarium number
if (Exp[level] == Pow[level]) {
var s = ""
for (i in DMAX...0) s = s + DIGITS[i].toString
s = s.trimStart("0")
if (s == "") s = "0"
System.print(s)
count = count + 1
if (count == LIMIT) {
if (LIMIT < 20) {
System.print("\nFound the first %(LIMIT) Disarium numbers.")
} else {
System.print("\nFound all 20 Disarium numbers.")
}
return
}
}
// Go to followed last bit candidate
DIGITS[level] = DIGITS[level] + 1
Exp[level].add(Exp[level], EXP[level][1])
Pow[level].inc
}
// Reset to try next path
DIGITS[level] = 0
level = level - 1
DIGITS[level] = DIGITS[level] + 1
}
System.print()
}

View file

@ -0,0 +1,27 @@
func Disarium(N); \Return 'true' if N is a Disarium number
int N, N0, D(10), A(10), I, J, Sum;
[N0:= N;
for J:= 0 to 10-1 do A(J):= 1;
I:= 0;
repeat N:= N/10;
D(I):= rem(0);
I:= I+1;
for J:= 0 to I-1 do
A(J):= A(J) * D(J);
until N = 0;
Sum:= 0;
for J:= 0 to I-1 do
Sum:= Sum + A(J);
return Sum = N0;
];
int Cnt, N;
[Cnt:= 0; N:= 0;
loop [if Disarium(N) then
[IntOut(0, N); ChOut(0, ^ );
Cnt:= Cnt+1;
if Cnt >= 19 then quit;
];
N:= N+1;
];
]

View file

@ -0,0 +1,22 @@
limite = 18 : cont = 0 : n = 0
print "The first", limite, " Disarium numbers are:"
while cont < limite
if isDisarium(n) then
print n, " ";
cont = cont + 1
fi
n = n + 1
wend
end
sub isDisarium(n)
digitos = len(str$(n))
suma = 0 : x = n
while x <> 0
r = mod(x, 10)
suma = suma + (r ^ digitos)
digitos = digitos - 1
x = int(x / 10)
wend
if suma = n then return True else return False : fi
end sub