This commit is contained in:
Smaug123
2023-01-15 14:16:03 +00:00
parent 44b60dda2d
commit b3c3978afa

View File

@@ -5,6 +5,7 @@ module Program =
let words = let words =
[ [
"LEAD" "LEAD"
"READ"
"BEAD" "BEAD"
"BEAR" "BEAR"
"BEAT" "BEAT"
@@ -15,7 +16,6 @@ module Program =
"CULT" "CULT"
"CURT" "CURT"
"CART" "CART"
"CARD"
"CARE" "CARE"
"DARE" "DARE"
"DANE" "DANE"
@@ -56,7 +56,7 @@ module Program =
(instructions : (string * int) list) (instructions : (string * int) list)
: _ list : _ list
= =
//if not (restrict board) then [] else if not (restrict board) then [] else
match instructions with match instructions with
| [] -> [board, BondSet.directionList bonds] | [] -> [board, BondSet.directionList bonds]
| (word, i) :: rest -> | (word, i) :: rest ->
@@ -160,13 +160,39 @@ module Program =
) )
munged munged
) )
|> List.distinct
printfn "Before filtering, %i options" after.Length printfn "Before filtering, %i options" after.Length
after.[7000] |> List.iter print
let filtered = let after =
after after
|> List.filter (fun positions -> |> List.sortBy (fun l ->
let (endX, endY) = fst (List.last positions) let (x, y), _ = List.last l
endY = 0 && (abs endX = 1) abs x + abs y
) )
printfn "%i total options" filtered.Length
if after.Length = 0 then 1 else
let l = after.[1]
let positions = l |> List.map fst
let minX = positions |> List.map fst |> List.min
let maxX = positions |> List.map fst |> List.max
let minY = positions |> List.map snd |> List.min
let maxY = positions |> List.map snd |> List.max
let arr = Array2D.zeroCreate (maxY - minY + 1) (maxX - minX + 1)
let mutable i = 0
for x, y in positions do
if i >= instructions.Length then
arr.[y - minY, x - minX] <- ValueSome 'M'
else
arr.[y - minY, x - minX] <- ValueSome words.[i].[snd instructions.[i] - 1]
i <- i + 1
for row in maxY .. -1 .. minY do
for col in minX..maxX do
match arr.[row - minY, col - minX] with
| ValueNone -> printf "."
| ValueSome c -> printf "O"
printfn ""
0 0