Upside-down numbers: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl) |
(add RPL) |
||
Line 885: | Line 885: | ||
Five hundred thousandth: 729,664,644,183 |
Five hundred thousandth: 729,664,644,183 |
||
Five millionth: 82,485,246,852,682</pre> |
Five millionth: 82,485,246,852,682</pre> |
||
=={{header|RPL}}== |
|||
{{works with|Halcyon Calc|4.2.8}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ 9 SWAP 2 / CEIL ^ ≫ ''''POW92'''' STO |
|||
≪ |
|||
SWAP 1 - "" SWAP 1 4 ROLL START |
|||
9 MOD LAST / FLOOR SWAP |
|||
1 + →STR ROT + SWAP NEXT DROP |
|||
≫ ''''→STR9'''' STO |
|||
≪ → str |
|||
≪ "" str SIZE 1 FOR j |
|||
106 str j DUP SUB NUM - CHR + -1 STEP |
|||
≫ ≫ ''''UDSTR'''' STO |
|||
≪ |
|||
IF DUP 1 == THEN DROP "5" ELSE |
|||
1 WHILE OVER 1 > REPEAT |
|||
SWAP OVER '''POW92''' - SWAP 1 + END |
|||
1 - DUP '''POW92''' ROT + 1 - → series order |
|||
≪ order series 2 / CEIL '''→STR9''' DUP |
|||
IF order 2 MOD NOT THEN "5" + END |
|||
SWAP '''UDSTR''' + |
|||
≫ END |
|||
≫ ''''UPSDN'''' STO |
|||
| |
|||
'''POW92''' ''( n -- 9^ceil(n/2) ) '' |
|||
'''→STR9''' ''( n str_length -- "12..9" ) '' |
|||
n-- ; s = "" ; loop size times |
|||
n,m = divmod(n) |
|||
append "m+1" to s |
|||
return s |
|||
'''UDSTR''' ''( "str" -- "rts" )'' |
|||
s = "" ; loop for j from size(str) downto 1 |
|||
s[j] = 106 - char(ascii(str[j])) |
|||
return s |
|||
'''UPSDN''' ''( n -- "a(n)" ) '' |
|||
if n = 1 then return "5" else |
|||
series = 1 ; while n > 1 |
|||
n -= 9^ceil(series/2); series++ |
|||
series-- ; order = n + 9^ceil(series/2) + 1 |
|||
Create left part of the upside-down number, as a string |
|||
Add 5 in the middle if appropriate |
|||
Add upside-down right part |
|||
et voilà |
|||
return full string |
|||
|} |
|||
{{in}} |
|||
<pre> |
|||
≪ {} 1 50 FOR j j UPSDN+ NEXT ≫ EVAL |
|||
500 UPSDN 5000 UPSDN 50000 UPSDN 500000 UPSDN 5000000 UPSDN |
|||
5000000000 UPSDN |
|||
</pre> |
|||
{{out}} |
|||
<pre> |
|||
7: { "5" "19" "28" "37" "46" "55" "64" "73" "82" "91" "159" "258" "357" "456" "555" "654" "753" "852" "951" "1199" "1289" "1379" "1469" "1559" "1649" "1739" "1829" "1919" "2198" "2288" "2378" "2468" "2558" "2648" "2738" "2828" "2918" "3197" "3287" "3377" "3467" "3557" "3647" "3737" "3827" "3917" "4196" "4286" "4376" "4466" } |
|||
6: "494616" |
|||
5: "56546545" |
|||
4: "6441469664" |
|||
3: "729664644183" |
|||
2: "82485246852682" |
|||
1: "269222738456273888148" |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |