Solve hanging lantern problem: Difference between revisions
Content added Content deleted
(→{{header|J}}: remove J from Basic implementations) |
(J entry) |
||
Line 391: | Line 391: | ||
{{out}} |
{{out}} |
||
<pre>Same as FreeBASIC entry.</pre> |
<pre>Same as FreeBASIC entry.</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|Julia}}== |
=={{header|Julia}}== |