This commit is contained in:
Patrick Stevens
2022-12-13 20:18:01 +00:00
committed by GitHub
parent 39e18bec4b
commit 068755efd3
22 changed files with 829 additions and 134 deletions

View File

@@ -1,6 +1,7 @@
namespace AdventOfCode2022
open System
open System.Globalization
[<RequireQualifiedAccess>]
module Day4 =
@@ -10,6 +11,9 @@ module Day4 =
let inline overlaps (a, b) (c, d) : bool = b >= c && a <= d
let inline private parseInt (c : ReadOnlySpan<char>) : int =
Int32.Parse (c, NumberStyles.AllowTrailingWhite)
let parse (s : ReadOnlySpan<char>) : (int * int) * (int * int) =
let commaIndex = s.IndexOf ','
let firstElf = s.Slice (0, commaIndex)
@@ -20,7 +24,7 @@ module Day4 =
let secondDashIndex = secondElf.IndexOf '-'
let secondElf1 = secondElf.Slice (0, secondDashIndex)
let secondElf2 = secondElf.Slice (secondDashIndex + 1)
(Int32.Parse firstElf1, Int32.Parse firstElf2), (Int32.Parse secondElf1, Int32.Parse secondElf2)
(parseInt firstElf1, parseInt firstElf2), (parseInt secondElf1, parseInt secondElf2)
let part1 (lines : StringSplitEnumerator) : int =
let mutable count = 0