Self numbers: Difference between revisions
Content added Content deleted
(Added Algol 68) |
|||
Line 12: | Line 12: | ||
;*[[oeis:A003052|OEIS: A003052 - Self numbers or Colombian numbers]] |
;*[[oeis:A003052|OEIS: A003052 - Self numbers or Colombian numbers]] |
||
;*[[wp:Self_number|Wikipedia: Self numbers]] |
;*[[wp:Self_number|Wikipedia: Self numbers]] |
||
=={{header|ALGOL 68}}== |
|||
{{Trans|Go}} |
|||
<lang algol68>BEGIN # find some self numbers numbers n such that for all there is no g such that g + sum of g's digits = n # |
|||
INT max number = 1 999 999 999 + 82; # maximum n plus g we will condifer # |
|||
# sieve the self numbers up to 1 999 999 999 # |
|||
[ 0 : max number ]BOOL self; FOR i TO UPB self DO self[ i ] := TRUE OD; |
|||
INT n := 0; |
|||
FOR s0 FROM 0 TO 1 DO |
|||
FOR d1 FROM 0 TO 9 DO |
|||
INT s1 = s0 + d1; |
|||
FOR d2 FROM 0 TO 9 DO |
|||
INT s2 = s1 + d2; |
|||
FOR d3 FROM 0 TO 9 DO |
|||
INT s3 = s2 + d3; |
|||
FOR d4 FROM 0 TO 9 DO |
|||
INT s4 = s3 + d4; |
|||
FOR d5 FROM 0 TO 9 DO |
|||
INT s5 = s4 + d5; |
|||
FOR d6 FROM 0 TO 9 DO |
|||
INT s6 = s5 + d6; |
|||
FOR d7 FROM 0 TO 9 DO |
|||
INT s7 = s6 + d7; |
|||
FOR d8 FROM 0 TO 9 DO |
|||
INT s8 = s7 + d8; |
|||
FOR d9 FROM 0 TO 9 DO |
|||
INT s9 = s8 + d9; |
|||
self[ s9 + n ] := FALSE; |
|||
n +:= 1 |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD |
|||
OD; |
|||
# show the first 50 self numbers # |
|||
INT s count := 0; |
|||
FOR i TO UPB self WHILE s count < 50 DO |
|||
IF self[ i ] THEN |
|||
print( ( " ", whole( i, -3 ) ) ); |
|||
IF ( s count +:= 1 ) MOD 18 = 0 THEN print( ( newline ) ) FI |
|||
FI |
|||
OD; |
|||
print( ( newline ) ); |
|||
# show the self numbers with power-of-10 indxes # |
|||
INT s show := 1; |
|||
s count := 0; |
|||
print( ( " nth self", newline ) ); |
|||
print( ( " n number", newline ) ); |
|||
FOR i TO UPB self DO |
|||
IF self[ i ] THEN |
|||
s count +:= 1; |
|||
IF s count = s show THEN |
|||
print( ( whole( s show, -9 ), " ", whole( i, -11 ), newline ) ); |
|||
s show *:= 10 |
|||
FI |
|||
FI |
|||
OD |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 3 5 7 9 20 31 42 53 64 75 86 97 108 110 121 132 143 |
|||
154 165 176 187 198 209 211 222 233 244 255 266 277 288 299 310 312 323 |
|||
334 345 356 367 378 389 400 411 413 424 435 446 457 468 |
|||
nth self |
|||
n number |
|||
1 1 |
|||
10 64 |
|||
100 973 |
|||
1000 10188 |
|||
10000 102225 |
|||
100000 1022675 |
|||
1000000 10227221 |
|||
10000000 102272662 |
|||
100000000 1022727208 |
|||
</pre> |
|||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
Line 123: | Line 203: | ||
selfNumbers(9.7777777792E+10) |
selfNumbers(9.7777777792E+10) |
||
--> {9.99999999997E+11}</lang> |
--> {9.99999999997E+11}</lang> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
<lang AWK> |