Solve hanging lantern problem: Difference between revisions

→‎{{header|Raku}}: Add implementation.
(→‎{{header|Julia}}: Mark incorrect per discussion comment)
(→‎{{header|Raku}}: Add implementation.)
Line 229:
print(getLantern(a))
</lang>
 
=={{header|Raku}}==
{{trans|Julia}}
Rather than take the number of columns as an explicit argument, this program infers the number from the size of the array of columns passed in. Also, the verbose output (optional task) gives the sequence of column numbers from which to take the bottommost lantern at each step, rather than numbering each lantern individually.
 
<lang raku>unit sub MAIN(*@columns, :v(:$verbose)=False);
 
my @sequences = @columns
. pairs
. map({ (.key+1) xx .value })
. flat
. permutations
. map( *.join(',') )
. unique;
 
say +@sequences;
if ($verbose) {
say "[$_]" for @sequences;
}</lang>
 
{{Out}}
<pre>$ raku lanterns.raku 1 2 3
60
$ raku lanterns.raku --verbose 1 2 3
60
[1,2,2,3,3,3]
[1,2,3,2,3,3]
[1,2,3,3,2,3]
[1,2,3,3,3,2]
[1,3,2,2,3,3]
[1,3,2,3,2,3]
...
[3,3,2,2,3,1]
[3,3,2,3,1,2]
[3,3,2,3,2,1]
[3,3,3,1,2,2]
[3,3,3,2,1,2]
[3,3,3,2,2,1]</pre>
 
=={{header|VBA}}==
1,481

edits