Enum
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -10,19 +10,19 @@ open System
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day16 =
|
||||
|
||||
[<Struct>]
|
||||
type Direction =
|
||||
| Left
|
||||
| Right
|
||||
| Up
|
||||
| Down
|
||||
| Left = 0
|
||||
| Right = 1
|
||||
| Up = 2
|
||||
| Down = 3
|
||||
|
||||
let inline dirToInt (d : Direction) =
|
||||
match d with
|
||||
| Left -> 0us
|
||||
| Right -> 1us
|
||||
| Up -> 2us
|
||||
| Down -> 3us
|
||||
| Direction.Left -> 0us
|
||||
| Direction.Right -> 1us
|
||||
| Direction.Up -> 2us
|
||||
| Direction.Down -> 3us
|
||||
| _ -> failwith "Bad"
|
||||
|
||||
let inline storeDirectionAndPos (numCols : int) (col : int) (row : int) (direction : Direction) : uint16 =
|
||||
4us * uint16 (col + numCols * row) + dirToInt direction
|
||||
@@ -39,20 +39,11 @@ module Day16 =
|
||||
|
||||
let inline getRow (numCols : int) (input : uint16) = (input / 4us) / uint16 numCols |> int
|
||||
|
||||
let maxEncoded (numCols : int) (numRows : int) : uint16 =
|
||||
let inline maxEncoded (numCols : int) (numRows : int) : uint16 =
|
||||
4us * uint16 ((numCols - 1) + numCols * (numRows - 1)) + 3us
|
||||
|
||||
let inline getAt (numCols : int) (s : string) (row : int) (col : int) = s.[row * (numCols + 1) + col]
|
||||
|
||||
let printArr (arr : Arr2D<bool>) =
|
||||
for row = 0 to arr.Height - 1 do
|
||||
for col = 0 to arr.Width - 1 do
|
||||
if Arr2D.get arr col row then printf "#" else printf "."
|
||||
|
||||
printfn ""
|
||||
|
||||
printfn ""
|
||||
|
||||
let advance (arr : Arr2D<_>) (going : ResizeArray<_>) (s : string) (nextUp : uint16) =
|
||||
let numCols = arr.Width
|
||||
let numLines = arr.Height
|
||||
@@ -170,6 +161,7 @@ module Day16 =
|
||||
if col > 0 then
|
||||
going.Add (storeDirectionAndPos numCols (col - 1) row Direction.Left)
|
||||
| c -> failwith $"Unrecognised char: %c{c}"
|
||||
| _ -> failwith "bad"
|
||||
|
||||
let part1 (s : string) =
|
||||
let numLines = s.AsSpan().Count '\n'
|
||||
@@ -193,9 +185,7 @@ module Day16 =
|
||||
#endif
|
||||
let going = ResizeArray ()
|
||||
|
||||
going.Add (
|
||||
storeDirectionAndPos numCols LanguagePrimitives.GenericZero LanguagePrimitives.GenericZero Direction.Right
|
||||
)
|
||||
going.Add (storeDirectionAndPos numCols 0 0 Direction.Right)
|
||||
|
||||
let seen = Array.zeroCreate (int (maxEncoded numCols numLines) + 1)
|
||||
|
||||
@@ -238,7 +228,7 @@ module Day16 =
|
||||
going.Clear ()
|
||||
Array.Clear seen
|
||||
Array.Clear buf
|
||||
going.Add (storeDirectionAndPos numCols start LanguagePrimitives.GenericZero Direction.Down)
|
||||
going.Add (storeDirectionAndPos numCols start 0 Direction.Down)
|
||||
|
||||
while going.Count > 0 do
|
||||
let nextUp = going.[going.Count - 1]
|
||||
@@ -273,7 +263,7 @@ module Day16 =
|
||||
going.Clear ()
|
||||
Array.Clear seen
|
||||
Array.Clear buf
|
||||
going.Add (storeDirectionAndPos numCols LanguagePrimitives.GenericZero start Direction.Right)
|
||||
going.Add (storeDirectionAndPos numCols 0 start Direction.Right)
|
||||
|
||||
while going.Count > 0 do
|
||||
let nextUp = going.[going.Count - 1]
|
||||
|
Reference in New Issue
Block a user