Skip to content

Commit

Permalink
Use List.append instead of List.prepend, and reverse the lists at the…
Browse files Browse the repository at this point in the history
… end
  • Loading branch information
ageron committed Oct 2, 2024
1 parent c26039f commit 5300c73
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions exercises/practice/killer-sudoku-helper/.meta/Example.roc
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ combinations = \{ sum, size, exclude ? [] } ->
else

when digits is
[] -> [[]]
[] -> []
[single] -> if single == target then [[single]] else []
[first, .. as rest] ->
if first > target then
[]
else

help (target - first) rest
|> List.map \combi -> combi |> List.prepend first
|> List.map \combi -> combi |> List.append first
|> List.concat (help target rest)
availableDigits =
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|> List.dropIf \digit -> exclude |> List.contains digit
help sum availableDigits
|> List.keepIf \combi -> List.len combi == size |> Num.toU64
|> List.map List.reverse

0 comments on commit 5300c73

Please sign in to comment.