Solve hanging lantern problem: Difference between revisions
Content added Content deleted
(→{{header|APL}}: Add implementation.) |
(→{{header|APL}}: Credit source of formula, add more examples, use iota.) |
||
Line 47: | Line 47: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{trans|Pascal} |
|||
<lang apl>lanterns ← { (!+/⍵) ÷ ×/!⍵ }</lang> |
<lang apl>lanterns ← { (!+/⍵) ÷ ×/!⍵ }</lang> |
||
{{Out}} |
{{Out}} |
||
Line 53: | Line 54: | ||
lanterns 1 3 3 |
lanterns 1 3 3 |
||
140 |
140 |
||
⚫ | |||
⚫ | |||
⚫ | |||
Of course, for the simple sequences from 1, we can use iota to generate them instead of typing them out: |
|||
<pre> |
|||
lanterns ⍳4 ⍝ same as lanterns 1 2 3 4 |
|||
12600 |
|||
⚫ | |||
37837800</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |