Bell numbers: Difference between revisions

add RPL
(Initial FutureBasic task solution added)
(add RPL)
Line 4,005:
Bell(49) = 10,726,137,154,573,358,400,342,215,518,590,002,633,917,247,281
</pre>
 
=={{header|RPL}}==
{{works with|HP|48}}
≪ → n
≪ { 1 }
'''WHILE''' 'n' DECR '''REPEAT'''
DUP DUP SIZE GET 1 →LIST
1 3 PICK SIZE '''FOR''' j
OVER j GET OVER j GET + +
'''NEXT''' SWAP DROP
'''END''' HEAD
≫ ≫ ‘<span style="color:blue">BELL</span>’ STO
 
'''Variant with a better use of the stack'''
 
Slightly faster then, although more wordy:
≪ → n
≪ { 1 } 1
'''WHILE''' 'n' DECR '''REPEAT'''
DUP 1 →LIST
1 4 PICK SIZE '''FOR''' j
3 PICK j GET ROT + SWAP OVER +
'''NEXT''' ROT DROP SWAP
'''END''' DROP HEAD
≫ ≫ ‘<span style="color:blue">BELL</span>’ STO
 
≪ {} 1 15 '''FOR''' n n <span style="color:blue">BELL</span> + '''NEXT''' ≫ EVAL
{{out}}
<pre>
1: { 1 1 2 5 15 52 203 877 4140 21147 115975 678570 4213597 27644437 190899322 }
</pre>
It makes no sense to display 10 rows of the Bell triangle on a screen limited to 22 characters and 7 lines in the best case.
 
=={{header|Ruby}}==
1,150

edits