Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Narcissistic is
|
||||
|
||||
function Is_Narcissistic(N: Natural) return Boolean is
|
||||
Decimals: Natural := 1;
|
||||
M: Natural := N;
|
||||
Sum: Natural := 0;
|
||||
begin
|
||||
while M >= 10 loop
|
||||
M := M / 10;
|
||||
Decimals := Decimals + 1;
|
||||
end loop;
|
||||
M := N;
|
||||
while M >= 1 loop
|
||||
Sum := Sum + (M mod 10) ** Decimals;
|
||||
M := M/10;
|
||||
end loop;
|
||||
return Sum=N;
|
||||
end Is_Narcissistic;
|
||||
|
||||
Count, Current: Natural := 0;
|
||||
|
||||
begin
|
||||
while Count < 25 loop
|
||||
if Is_Narcissistic(Current) then
|
||||
Ada.Text_IO.Put(Integer'Image(Current));
|
||||
Count := Count + 1;
|
||||
end if;
|
||||
Current := Current + 1;
|
||||
end loop;
|
||||
end Narcissistic;
|
||||
|
|
@ -15,8 +15,8 @@ narcissistic?: function [n][
|
|||
n = sum map split.every:2 to :string n 'p -> getPair p sdigs
|
||||
]
|
||||
|
||||
i: new 0
|
||||
counter: new 0
|
||||
i: 0
|
||||
counter: 0
|
||||
while [counter < 25][
|
||||
if narcissistic? i [
|
||||
print i
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
PROGRAM-ID. NARCISSIST-NUMS.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
|
||||
01 num-length PIC 9(2) value 0.
|
||||
01 in-sum PIC 9(9) value 0.
|
||||
01 counter PIC 9(9) value 0.
|
||||
01 current-number PIC 9(9) value 0.
|
||||
01 narcissist PIC Z(9).
|
||||
01 temp PIC 9(9) value 0.
|
||||
01 modulo PIC 9(9) value 0.
|
||||
01 answer PIC 9 .
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
MAIN-PROCEDURE.
|
||||
DISPLAY "the first 20 narcissist numbers:" .
|
||||
|
||||
MOVE 20 TO counter.
|
||||
PERFORM UNTIL counter=0
|
||||
|
||||
PERFORM 000-NARCISSIST-PARA
|
||||
|
||||
IF answer = 1
|
||||
SUBTRACT 1 from counter
|
||||
GIVING counter
|
||||
MOVE current-number TO narcissist
|
||||
DISPLAY narcissist
|
||||
END-IF
|
||||
|
||||
ADD 1 TO current-number
|
||||
|
||||
END-PERFORM
|
||||
|
||||
STOP RUN.
|
||||
|
||||
000-NARCISSIST-PARA.
|
||||
|
||||
MOVE ZERO TO in-sum.
|
||||
MOVE current-number TO temp.
|
||||
COMPUTE num-length =1+ FUNCTION Log10(temp)
|
||||
|
||||
PERFORM UNTIL temp=0
|
||||
|
||||
DIVIDE temp BY 10 GIVING temp
|
||||
REMAINDER modulo
|
||||
|
||||
COMPUTE modulo=modulo**num-length
|
||||
ADD modulo to in-sum GIVING in-sum
|
||||
|
||||
END-PERFORM.
|
||||
|
||||
IF current-number=in-sum
|
||||
MOVE 1 TO answer
|
||||
ELSE MOVE 0 TO answer
|
||||
END-IF.
|
||||
|
||||
END PROGRAM NARCISSIST-NUMS.
|
||||
|
|
@ -1,13 +1,33 @@
|
|||
while cnt < 25
|
||||
s$ = n
|
||||
ln = len s$
|
||||
s = 0
|
||||
for i to ln
|
||||
s += pow number substr s$ i 1 ln
|
||||
.
|
||||
if s = n
|
||||
print s
|
||||
cnt += 1
|
||||
.
|
||||
n += 1
|
||||
len d[] 20
|
||||
fastfunc pown n p .
|
||||
r = 1
|
||||
for i = 1 to p : r *= n
|
||||
return r
|
||||
.
|
||||
fastfunc narcis n .
|
||||
h = n
|
||||
while h > 0
|
||||
i += 1
|
||||
d[i] = h mod 10
|
||||
h = h div 10
|
||||
.
|
||||
for j = 1 to i
|
||||
s += pown d[j] i
|
||||
.
|
||||
if s = n : return 1
|
||||
return 0
|
||||
.
|
||||
fastfunc next n .
|
||||
repeat
|
||||
n += 1
|
||||
until narcis n = 1
|
||||
.
|
||||
return n
|
||||
.
|
||||
n = -1
|
||||
while cnt < 25
|
||||
n = next n
|
||||
write n & " "
|
||||
cnt += 1
|
||||
.
|
||||
print ""
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
function Test-Narcissistic ([int]$Number)
|
||||
{
|
||||
if ($Number -lt 0) {return $false}
|
||||
|
||||
$total = 0
|
||||
$digits = $Number.ToString().ToCharArray()
|
||||
|
||||
foreach ($digit in $digits)
|
||||
{
|
||||
$total += [Math]::Pow([Char]::GetNumericValue($digit), $digits.Count)
|
||||
}
|
||||
|
||||
$total -eq $Number
|
||||
}
|
||||
|
||||
|
||||
[int[]]$narcissisticNumbers = @()
|
||||
[int]$i = 0
|
||||
|
||||
while ($narcissisticNumbers.Count -lt 25)
|
||||
{
|
||||
if (Test-Narcissistic -Number $i)
|
||||
{
|
||||
$narcissisticNumbers += $i
|
||||
}
|
||||
|
||||
$i++
|
||||
}
|
||||
|
||||
$narcissisticNumbers | Format-Wide {"{0,7}" -f $_} -Column 5 -Force
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
Function Narcissist(n)
|
||||
i = 0
|
||||
j = 0
|
||||
Do Until j = n
|
||||
sum = 0
|
||||
For k = 1 To Len(i)
|
||||
sum = sum + CInt(Mid(i,k,1)) ^ Len(i)
|
||||
Next
|
||||
If i = sum Then
|
||||
Narcissist = Narcissist & i & ", "
|
||||
j = j + 1
|
||||
End If
|
||||
i = i + 1
|
||||
Loop
|
||||
End Function
|
||||
|
||||
WScript.StdOut.Write Narcissist(25)
|
||||
Loading…
Add table
Add a link
Reference in a new issue