Solve hanging lantern problem: Difference between revisions

→‎{{header|J}}: remove J from Basic implementations
(→‎{{header|J}}: remove J from Basic implementations)
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>
 
If we wanted to impose even more overhead, we could insist that the numbers be read from a file where tabs, spaces and newlines are all treated equivalently. For that, we must specify the file name and implement some parsing:
 
<lang J>yetmoreoverhead=: {{
pedantic ({.~ 1+{.) _ ". rplc&(TAB,' ',LF,' ') fread y
}}</lang>
 
Examples of this approach are left as an exercise for the user.
 
==={{header|QBasic}}===
6,951

edits