Solve hanging lantern problem: Difference between revisions
J
m (→{{header|APL}}) |
(J) |
||
Line 170:
[ 1 2 3 4 ] = 12600
[ 1 2 3 4 5 ] = 37837800</pre>
==={{header|J}}===
Translation of [[#APL|APL]]:
<lang J>lanterns=: {{ (!+/y) % */!y }}<</lang>
Example use:
<lang J> lanterns 1 2 3
60
lanterns 1 3 3
140
</lang>
Also, a pedantic version where we must manually count how many values we are providing the computer:
<lang J>pedantic=: {{
assert. ({. = #@}.) y
lanterns }.y
}}</lang>
And, in the spirit of providing unnecessary but perhaps pleasant (for some) overhead, we'll throw in an unnecessary comma between this count and the relevant values:
<lang J> pedantic 3, 1 2 3
60
pedantic 3, 1 3 3
140</lang>
==={{header|QBasic}}===
|