diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2022-12-07 14:23:47 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2022-12-07 14:23:47 +0100 |
commit | 8d9513e9df67c5ec0abc2d94152f350274233643 (patch) | |
tree | 926d8e378c7534baddf76800971762b1a2c2cea0 /aoc-2022-dotnet/Day05 | |
parent | bea11616e6b3c26b14534feb87317619009236d1 (diff) | |
download | gleam_aoc2020-8d9513e9df67c5ec0abc2d94152f350274233643.tar.gz gleam_aoc2020-8d9513e9df67c5ec0abc2d94152f350274233643.zip |
Refactor earlier solutions
Diffstat (limited to 'aoc-2022-dotnet/Day05')
-rw-r--r-- | aoc-2022-dotnet/Day05/Day05.fsproj | 4 | ||||
-rw-r--r-- | aoc-2022-dotnet/Day05/Program.fs | 17 |
2 files changed, 10 insertions, 11 deletions
diff --git a/aoc-2022-dotnet/Day05/Day05.fsproj b/aoc-2022-dotnet/Day05/Day05.fsproj index 44c3fba..358ef88 100644 --- a/aoc-2022-dotnet/Day05/Day05.fsproj +++ b/aoc-2022-dotnet/Day05/Day05.fsproj @@ -19,4 +19,8 @@ <PackageReference Include="FParsec" Version="1.1.1" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Common\Common.fsproj" /> + </ItemGroup> + </Project> diff --git a/aoc-2022-dotnet/Day05/Program.fs b/aoc-2022-dotnet/Day05/Program.fs index e15f53d..f471a31 100644 --- a/aoc-2022-dotnet/Day05/Program.fs +++ b/aoc-2022-dotnet/Day05/Program.fs @@ -1,4 +1,6 @@ -open System +module Day05 + +open System open System.IO open FParsec @@ -9,10 +11,7 @@ type Move = let dec n = n - 1 let pPart str = pstring str >>. pint32 let pMove = tuple3 (pPart "move ") (pPart " from " |>> dec) (pPart " to " |>> dec) - - match run pMove str with - | Success (result, _, _) -> Move result - | _ -> failwith "Invalid move format!" + Common.parse pMove str |> Move static member execute order stacks (Move (n, fi, ti)) = List.mapi @@ -33,12 +32,8 @@ let parseStacks str = let pCrateLine = sepBy pCrate (pchar ' ') .>> skipNewline let pHeader = many pCrateLine - let parsed = - match run pHeader str with - | Success (result, _, _) -> result - | _ -> failwith "Invalid header format!" - - parsed + str + |> Common.parse pHeader |> List.transpose |> List.map (List.choose id) |