Trabb Pardo–Knuth algorithm: Difference between revisions

add RPL - idiomatic
m (add RPL)
(add RPL - idiomatic)
Line 3,781:
'''FUNC''' ''( x -- sqrt(abs(x))+x^3 )''
'''TPK''' ''( -- report )''
ask for 11 numbers to be read into a sequence S
reverse sequence S
Line 3,817:
1: "Too large!"
</pre>
 
===Idiomatic===
{| class="wikitable"
! RPL code
! Comment
|-
|
≪ "Push 11 numbers in stack, then CONT"
HALT 11 →LIST → s
≪ DROP 11 1
'''FOR''' j s j GET
'''FUNC'''
DUP 400 >
"Too large!"
ROT '''IFTE'''
-1 '''STEP'''
≫ ≫ ''''TPK'''' STO
|
'''TPK''' ''( -- report )''
ask for 11 numbers to be read into a sequence S
reverse sequence S
for each item in sequence S
call a function to do an operation
if result overflows
alert user
else print result
|}
 
=={{header|Ruby}}==
1,151

edits