Solve hanging lantern problem: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: Add implementation.)
(→‎{{header|Julia}}: Correct treatment of duplicate column sizes; see talk page.)
Line 47: Line 47:


=={{header|Julia}}==
=={{header|Julia}}==
{{incorrect|Julia|Columns with the same number of lanterns should be distinct; see talk page.}}
<lang ruby>""" rosettacode.org /wiki/Lantern_Problem """
<lang ruby>""" rosettacode.org /wiki/Lantern_Problem """


Line 55: Line 54:
inputs = [parse(Int, i) for i in split(readline(), r"\s+")]
inputs = [parse(Int, i) for i in split(readline(), r"\s+")]
n = popfirst!(inputs)
n = popfirst!(inputs)
takedownways = unique(permutations(reduce(vcat, [fill(n, n) for n in inputs])))
takedownways = unique(permutations(reduce(vcat, [fill(i,inputs[i]) for i in 1:length(inputs)])))
println("\nThere are ", length(takedownways), " ways to take these ", n, " columns down:")
println("\nThere are ", length(takedownways), " ways to take these ", n, " columns down:")
for way in takedownways
for way in takedownways