Scaffolding

This commit is contained in:
Smaug123
2023-12-04 23:40:02 +00:00
parent c8c1cdc950
commit 65b82a3f74
7 changed files with 89 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
<Compile Include="Day2.fs" />
<Compile Include="Day3.fs" />
<Compile Include="Day4.fs" />
<Compile Include="Day5.fs" />
</ItemGroup>
</Project>

View File

@@ -1,15 +1,21 @@
namespace AdventOfCode2023
open System
open System.Collections.Generic
[<RequireQualifiedAccess>]
module Day4 =
let inline parseByte (chars : ReadOnlySpan<char>) : byte =
// Byte.Parse (chars, NumberStyles.None, NumberFormatInfo.InvariantInfo)
let mutable answer = 0uy
for c in chars do
answer <- answer * 10uy + (byte c - 48uy)
answer
let part1 (s : string) =
use lines = StringSplitEnumerator.make '\n' s
let mutable total = 0
let winningNumbers = HashSet ()
let winningNumbers = ResizeArray<byte> ()
for line in lines do
if not (line.IsWhiteSpace ()) then
@@ -30,14 +36,14 @@ module Day4 =
if split.Current.[0] = '|' then
accumulatingWinning <- false
else
winningNumbers.Add (Int32.Parse split.Current) |> ignore
winningNumbers.Add (parseByte split.Current)
split.MoveNext () |> ignore
let mutable answer = 0
while split.MoveNext () do
if not split.Current.IsEmpty then
let n = Int32.Parse split.Current
let n = parseByte split.Current
if winningNumbers.Contains n then
answer <- answer + 1
@@ -51,9 +57,8 @@ module Day4 =
let part2 (s : string) =
use lines = StringSplitEnumerator.make '\n' s
let mutable total = 0
let winningNumbers = HashSet ()
let winners = ResizeArray ()
let winningNumbers = ResizeArray<byte> ()
let winners = ResizeArray<int> ()
for line in lines do
if not (line.IsWhiteSpace ()) then
@@ -74,14 +79,14 @@ module Day4 =
if split.Current.[0] = '|' then
accumulatingWinning <- false
else
winningNumbers.Add (Int32.Parse split.Current) |> ignore
winningNumbers.Add (parseByte split.Current)
split.MoveNext () |> ignore
let mutable answer = 0
while split.MoveNext () do
if not split.Current.IsEmpty then
let n = Int32.Parse split.Current
let n = parseByte split.Current
if winningNumbers.Contains n then
answer <- answer + 1

View File

@@ -0,0 +1,16 @@
namespace AdventOfCode2023
open System
open System.Collections.Generic
[<RequireQualifiedAccess>]
module Day5 =
let part1 (s : string) =
use lines = StringSplitEnumerator.make '\n' s
0
let part2 (s : string) =
use lines = StringSplitEnumerator.make '\n' s
0