Jump to content

Esthetic numbers: Difference between revisions

Added Arturo implementation
(Added Arturo implementation)
Line 346:
Found 126 esthetic numbers
</pre>
 
=={{header|Arturo}}==
 
<lang rebol>esthetic?: function [n, b][
if n=0 -> return false
k: n % b
l: n / b
 
while [l>0][
j: l % b
if 1 <> abs k-j -> return false
l: l / b
k: j
]
return true
]
 
HEX: "0000000000ABCDEF"
 
getHex: function [ds][
map ds 'd [
(d < 10)? -> to :string d
-> to :string HEX\[d]
]
]
 
findEsthetics: function [base][
limDown: base * 4
limUp: base * 6
 
cnt: 0
i: 1
result: new []
while [cnt < limUp][
if esthetic? i base [
cnt: cnt + 1
if cnt >= limDown ->
'result ++ join getHex digits.base: base i
]
i: i + 1
]
print ["Base" base "->" (to :string limDown)++"th" "to" (to :string limUp)++"th" "esthetic numbers:"]
print result
print ""
]
 
loop 2..16 'bs ->
findEsthetics bs
 
print "Esthetic numbers between 1000 and 9999:"
 
loop split.every: 16 select 1000..9999 'num -> esthetic? num 10 'row [
print map to [:string] row 'item -> pad item 4
]</lang>
 
{{out}}
 
<pre>Base 2 -> 8th to 12th esthetic numbers:
10101010 101010101 1010101010 10101010101 101010101010
 
Base 3 -> 12th to 18th esthetic numbers:
1210 1212 2101 2121 10101 10121 12101
 
Base 4 -> 16th to 24th esthetic numbers:
323 1010 1012 1210 1212 1232 2101 2121 2123
 
Base 5 -> 20th to 30th esthetic numbers:
323 343 432 434 1010 1012 1210 1212 1232 1234 2101
 
Base 6 -> 24th to 36th esthetic numbers:
343 345 432 434 454 543 545 1010 1012 1210 1212 1232 1234
 
Base 7 -> 28th to 42th esthetic numbers:
345 432 434 454 456 543 545 565 654 656 1010 1012 1210 1212 1232
 
Base 8 -> 32th to 48th esthetic numbers:
432 434 454 456 543 545 565 567 654 656 676 765 767 1010 1012 1210 1212
 
Base 9 -> 36th to 54th esthetic numbers:
434 454 456 543 545 565 567 654 656 676 678 765 767 787 876 878 1010 1012 1210
 
Base 10 -> 40th to 60th esthetic numbers:
454 456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 987 989 1010 1012
 
Base 11 -> 44th to 66th esthetic numbers:
456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 A98 A9A 1010
 
Base 12 -> 48th to 72th esthetic numbers:
543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB A98 A9A ABA BA9 BAB
 
Base 13 -> 52th to 78th esthetic numbers:
545 565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB A98 A9A ABA ABC BA9 BAB BCB CBA
 
Base 14 -> 56th to 84th esthetic numbers:
565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC
 
Base 15 -> 60th to 90th esthetic numbers:
567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC CDE DCB DCD
 
Base 16 -> 64th to 96th esthetic numbers:
654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC CDE DCB DCD DED DEF EDC
 
Esthetic numbers between 1000 and 9999:
1010 1012 1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212 3232
3234 3432 3434 3454 3456 4321 4323 4343 4345 4543 4545 4565 4567 5432 5434 5454
5456 5654 5656 5676 5678 6543 6545 6565 6567 6765 6767 6787 6789 7654 7656 7676
7678 7876 7878 7898 8765 8767 8787 8789 8987 8989 9876 9878 9898</pre>
 
=={{header|C}}==
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.