Jump to content

N'th: Difference between revisions

239 bytes added ,  11 months ago
m
(→‎{{header|Batch File}}: Use if...... else if)
Line 3,638:
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
===ReadableClean version===
≪ IP DUP 10 MOD OVER 100 MOD 10 / IP → units tens
≪ →STR "'" +
'''IF''' units 1 ≥ units 3 ≤ AND tens 1 ≠ AND
'''THEN''' { "st" "nd" "rd" } units GET
'''ELSE''' "th"
'''END'''
+
≫ ≫ '<span style="color:blue">NTH</span>' STO
===One-liner===
'NTH' STO
===Compact version===
This version uses a mix of arithmetic and boolean operations to determine when to apply the "st/nd/rd" exception.
≪ IP →STR LAST { "'th" "'st" "'nd" "'rd" } OVER 10 MOD DUP 4 < * ROT 100 MOD 10 / IP 1 ≠ * 1 + GET + ≫ '<span style="color:blue">NTH</span>' STO
OVER 10 MOD DUP 4 < * ROT 100 MOD 10 / IP 1 ≠ * 1 + GET +
'NTH' STO
 
≪ { } 3ROT ROLLDROT '''FOR''' j j <span style="color:blue">NTH</span> + '''NEXT'''
'<span style="color:blue">SHOW</span>' STO
0 25 <span style="color:blue">SHOW</span>
250 265 <span style="color:blue">SHOW</span>
1000 1025 <span style="color:blue">SHOW</span>
{{out}}
<pre>
1,150

edits

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