Compare commits
4 Commits
woodpekcer
...
61c3f1c79a
Author | SHA1 | Date | |
---|---|---|---|
|
61c3f1c79a | ||
|
cc5a0cec0d | ||
|
d2760ba051 | ||
|
148ea496c8 |
@@ -3,17 +3,6 @@ steps:
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
|
||||
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=true || echo 'First publish failed'"
|
||||
- "nix develop --command sh -c 'patchelf --set-interpreter $LINKER_PATH /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc'"
|
||||
- "ls -al /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "chmod a+x /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "ls -al /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "whoami"
|
||||
- "cp -r AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/obj /tmp/obj"
|
||||
- "nix develop --command sh -c 'ls -la $LINKER_PATH'"
|
||||
- "nix develop --command sh -c 'strace /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc /tmp/obj/Release/net8.0/linux-x64/native/AdventOfCode2023.FSharp.ilc.rsp'"
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=true"
|
||||
# Lint
|
||||
- "nix flake check"
|
||||
# Test
|
||||
@@ -23,8 +12,8 @@ steps:
|
||||
- nix develop --command dotnet tool restore
|
||||
- nix develop --command dotnet fantomas --check .
|
||||
# TODO: if https://github.com/dotnet/sdk/issues/37295 ever gets fixed, remove the PublishAot=false
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=false -p:SelfContained=true"
|
||||
- '$(find . -type f -name AdventOfCode2023.FSharp | grep Release | grep publish) "$(pwd)/AdventOfCode2023.FSharp/Test/samples"'
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=false"
|
||||
- nix develop --command sh -c "$(find . -type f -name AdventOfCode2023.FSharp | grep Release | grep publish) AdventOfCode2023.FSharp/Test/samples"
|
||||
|
||||
when:
|
||||
- event: "push"
|
||||
|
@@ -7,9 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Arr2D.fs" />
|
||||
<Compile Include="ResizeArray.fs" />
|
||||
<Compile Include="EfficientString.fs" />
|
||||
<Compile Include="Arithmetic.fs" />
|
||||
<Compile Include="Day1.fs" />
|
||||
<Compile Include="Day2.fs" />
|
||||
<Compile Include="Day3.fs" />
|
||||
@@ -17,7 +15,6 @@
|
||||
<Compile Include="Day5.fs" />
|
||||
<Compile Include="Day6.fs" />
|
||||
<Compile Include="Day7.fs" />
|
||||
<Compile Include="Day8.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -1,67 +0,0 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Arithmetic =
|
||||
|
||||
[<Struct>]
|
||||
type EuclidResult<'a> =
|
||||
{
|
||||
Hcf : 'a
|
||||
A : 'a
|
||||
B : 'a
|
||||
}
|
||||
|
||||
/// Compute floor(sqrt(i)).
|
||||
let inline sqrt (i : ^a) =
|
||||
if i <= LanguagePrimitives.GenericOne then
|
||||
i
|
||||
else
|
||||
let rec go start =
|
||||
let next = start + LanguagePrimitives.GenericOne
|
||||
let sqr = next * next
|
||||
|
||||
if sqr < LanguagePrimitives.GenericZero then
|
||||
// Overflow attempted, so the sqrt is between start and next
|
||||
start
|
||||
elif i < sqr then
|
||||
start
|
||||
elif i = sqr then
|
||||
next
|
||||
else
|
||||
go next
|
||||
|
||||
go LanguagePrimitives.GenericOne
|
||||
|
||||
/// Find Hcf, A, B s.t. A * a + B * b = Hcf, and Hcf is the highest common factor of a and b.
|
||||
let inline euclideanAlgorithm (a : ^a) (b : ^a) : EuclidResult< ^a > =
|
||||
let rec go rMin1 r sMin1 s tMin1 t =
|
||||
if r = LanguagePrimitives.GenericZero then
|
||||
{
|
||||
Hcf = rMin1
|
||||
A = sMin1
|
||||
B = tMin1
|
||||
}
|
||||
else
|
||||
let newQ = rMin1 / r
|
||||
go r (rMin1 - newQ * r) s (sMin1 - newQ * s) t (tMin1 - newQ * t)
|
||||
|
||||
let maxA = max a b
|
||||
let minB = min a b
|
||||
|
||||
let result =
|
||||
go
|
||||
maxA
|
||||
minB
|
||||
LanguagePrimitives.GenericOne
|
||||
LanguagePrimitives.GenericZero
|
||||
LanguagePrimitives.GenericZero
|
||||
LanguagePrimitives.GenericOne
|
||||
|
||||
if a = maxA then
|
||||
result
|
||||
else
|
||||
{
|
||||
Hcf = result.Hcf
|
||||
A = result.B
|
||||
B = result.A
|
||||
}
|
@@ -1,12 +1,9 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
open System
|
||||
open System.Globalization
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day2 =
|
||||
let inline parseInt (s : ReadOnlySpan<char>) : int =
|
||||
Int32.Parse (s, NumberStyles.None, CultureInfo.InvariantCulture)
|
||||
|
||||
let part1 (s : string) =
|
||||
use lines = StringSplitEnumerator.make '\n' s
|
||||
@@ -21,20 +18,20 @@ module Day2 =
|
||||
while isOk && words.MoveNext () do
|
||||
match words.Current.[0] with
|
||||
| 'b' ->
|
||||
if parseInt prevWord > 14 then
|
||||
if Int32.Parse prevWord > 14 then
|
||||
isOk <- false
|
||||
| 'r' ->
|
||||
if parseInt prevWord > 12 then
|
||||
if Int32.Parse prevWord > 12 then
|
||||
isOk <- false
|
||||
| 'g' ->
|
||||
if parseInt prevWord > 13 then
|
||||
if Int32.Parse prevWord > 13 then
|
||||
isOk <- false
|
||||
| _ -> ()
|
||||
|
||||
prevWord <- words.Current
|
||||
|
||||
if isOk then
|
||||
answer <- answer + parseInt (line.Slice (5, line.IndexOf ':' - 5))
|
||||
answer <- answer + Int32.Parse (line.Slice (5, line.IndexOf ':' - 5))
|
||||
|
||||
answer
|
||||
|
||||
@@ -52,9 +49,9 @@ module Day2 =
|
||||
|
||||
while words.MoveNext () do
|
||||
match words.Current.[0] with
|
||||
| 'b' -> blues <- max blues (parseInt prevWord)
|
||||
| 'r' -> reds <- max reds (parseInt prevWord)
|
||||
| 'g' -> greens <- max greens (parseInt prevWord)
|
||||
| 'b' -> blues <- max blues (Int32.Parse prevWord)
|
||||
| 'r' -> reds <- max reds (Int32.Parse prevWord)
|
||||
| 'g' -> greens <- max greens (Int32.Parse prevWord)
|
||||
| _ -> ()
|
||||
|
||||
prevWord <- words.Current
|
||||
|
@@ -1,17 +1,16 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
open System
|
||||
open System.Globalization
|
||||
open AdventOfCode2023.ResizeArray
|
||||
open System.Collections.Generic
|
||||
|
||||
type Hand =
|
||||
| Five = 6
|
||||
| Four = 5
|
||||
| FullHouse = 4
|
||||
| Three = 3
|
||||
| TwoPairs = 2
|
||||
| Pair = 1
|
||||
| High = 0
|
||||
| Five = 10
|
||||
| Four = 9
|
||||
| FullHouse = 8
|
||||
| Three = 7
|
||||
| TwoPairs = 6
|
||||
| Pair = 5
|
||||
| High = 4
|
||||
|
||||
type HandContents =
|
||||
{
|
||||
@@ -25,16 +24,13 @@ type HandContents =
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day7 =
|
||||
|
||||
[<Literal>]
|
||||
let joker = 0uy
|
||||
|
||||
let inline toByte (adjustJoker : bool) (c : char) : byte =
|
||||
if c <= '9' then byte c - byte '1'
|
||||
elif c = 'T' then 9uy
|
||||
elif c = 'J' then (if adjustJoker then joker else 10uy)
|
||||
elif c = 'Q' then 11uy
|
||||
elif c = 'K' then 12uy
|
||||
elif c = 'A' then 13uy
|
||||
if c <= '9' then byte c - byte '0'
|
||||
elif c = 'T' then 10uy
|
||||
elif c = 'J' then (if adjustJoker then 1uy else 11uy)
|
||||
elif c = 'Q' then 12uy
|
||||
elif c = 'K' then 13uy
|
||||
elif c = 'A' then 14uy
|
||||
else failwithf "could not parse: %c" c
|
||||
|
||||
let inline private updateState (tallies : ResizeArray<_>) newNum =
|
||||
@@ -48,32 +44,12 @@ module Day7 =
|
||||
if not isAdded then
|
||||
tallies.Add (newNum, 1)
|
||||
|
||||
type RankedHand = uint32
|
||||
|
||||
[<Literal>]
|
||||
let fourteen = 14ul
|
||||
|
||||
[<Literal>]
|
||||
let fourteenFive = fourteen * fourteen * fourteen * fourteen * fourteen
|
||||
|
||||
[<Literal>]
|
||||
let fourteenFour = fourteen * fourteen * fourteen * fourteen
|
||||
|
||||
[<Literal>]
|
||||
let fourteenThree = fourteen * fourteen * fourteen
|
||||
|
||||
[<Literal>]
|
||||
let fourteenTwo = fourteen * fourteen
|
||||
|
||||
let toInt (hand : Hand) (contents : HandContents) : RankedHand =
|
||||
uint32 hand * fourteenFive
|
||||
+ uint32 contents.First * fourteenFour
|
||||
+ uint32 contents.Second * fourteenThree
|
||||
+ uint32 contents.Third * fourteenTwo
|
||||
+ uint32 contents.Fourth * fourteen
|
||||
+ uint32 contents.Fifth
|
||||
|
||||
let parseHand (tallyBuffer : ResizeArray<_>) (adjustJoker : bool) (s : ReadOnlySpan<char>) : RankedHand =
|
||||
let inline parseHand
|
||||
(tallyBuffer : ResizeArray<_>)
|
||||
(adjustJoker : bool)
|
||||
(s : ReadOnlySpan<char>)
|
||||
: Hand * HandContents
|
||||
=
|
||||
let contents =
|
||||
{
|
||||
First = toByte adjustJoker s.[0]
|
||||
@@ -94,18 +70,17 @@ module Day7 =
|
||||
if not adjustJoker then
|
||||
0, -1
|
||||
else
|
||||
let mutable jokerCount = 0
|
||||
let mutable jokerPos = 0
|
||||
let mutable count = 0
|
||||
let mutable jokerPos = -1
|
||||
|
||||
while jokerPos < tallyBuffer.Count && jokerCount = 0 do
|
||||
let card, tally = tallyBuffer.[jokerPos]
|
||||
for i = 0 to tallyBuffer.Count - 1 do
|
||||
let card, tally = tallyBuffer.[i]
|
||||
|
||||
if card = joker then
|
||||
jokerCount <- tally
|
||||
else
|
||||
jokerPos <- jokerPos + 1
|
||||
if card = 1uy then
|
||||
count <- tally
|
||||
jokerPos <- i
|
||||
|
||||
jokerCount, jokerPos
|
||||
count, jokerPos
|
||||
|
||||
let hand =
|
||||
if jokerCount > 0 then
|
||||
@@ -160,56 +135,70 @@ module Day7 =
|
||||
else
|
||||
Hand.High
|
||||
|
||||
toInt hand contents
|
||||
hand, contents
|
||||
|
||||
type RankedHandAndBid = uint32
|
||||
|
||||
[<Literal>]
|
||||
let bidSeparator = 1001ul
|
||||
|
||||
let inline toRankedHandAndBid (r : RankedHand) (bid : uint32) : RankedHandAndBid = bidSeparator * r + bid
|
||||
|
||||
let inline getBid (r : RankedHandAndBid) : uint32 = uint32 (r % bidSeparator)
|
||||
|
||||
let parse (adjustJoker : bool) (s : string) : ResizeArray<RankedHandAndBid> =
|
||||
let parse (adjustJoker : bool) (s : string) : ResizeArray<Hand * HandContents * int> =
|
||||
use mutable lines = StringSplitEnumerator.make '\n' s
|
||||
let result = ResizeArray.create 4
|
||||
let tallies = ResizeArray.create 5
|
||||
let result = ResizeArray ()
|
||||
let tallies = ResizeArray 5
|
||||
|
||||
while lines.MoveNext () do
|
||||
if not lines.Current.IsEmpty then
|
||||
use mutable line = StringSplitEnumerator.make' ' ' lines.Current
|
||||
line.MoveNext () |> ignore
|
||||
let rankedHand = parseHand tallies adjustJoker line.Current
|
||||
let hand, contents = parseHand tallies adjustJoker line.Current
|
||||
line.MoveNext () |> ignore
|
||||
let bid = Int32.Parse line.Current
|
||||
|
||||
let bid =
|
||||
UInt32.Parse (line.Current, NumberStyles.Integer, CultureInfo.InvariantCulture)
|
||||
|
||||
result.Add (toRankedHandAndBid rankedHand bid)
|
||||
result.Add (hand, contents, bid)
|
||||
|
||||
result
|
||||
|
||||
let part1 (s : string) =
|
||||
let arr = parse false s
|
||||
let compArrBasic (a : HandContents) (b : HandContents) =
|
||||
if a.First > b.First then 1
|
||||
elif a.First < b.First then -1
|
||||
elif a.Second > b.Second then 1
|
||||
elif a.Second < b.Second then -1
|
||||
elif a.Third > b.Third then 1
|
||||
elif a.Third < b.Third then -1
|
||||
elif a.Fourth > b.Fourth then 1
|
||||
elif a.Fourth < b.Fourth then -1
|
||||
elif a.Fifth > b.Fifth then 1
|
||||
elif a.Fifth < b.Fifth then -1
|
||||
else 0
|
||||
|
||||
arr.Sort ()
|
||||
let compBasic : IComparer<Hand * HandContents * int> =
|
||||
{ new IComparer<_> with
|
||||
member _.Compare ((aHand, aContents, _), (bHand, bContents, _)) =
|
||||
match compare aHand bHand with
|
||||
| 0 -> compArrBasic aContents bContents
|
||||
| x -> x
|
||||
}
|
||||
|
||||
let mutable answer = 0ul
|
||||
let part1 (s : string) : int =
|
||||
let parsed = parse false s
|
||||
|
||||
for i = 0 to arr.Count - 1 do
|
||||
answer <- answer + getBid arr.[i] * (uint32 i + 1ul)
|
||||
parsed.Sort compBasic
|
||||
|
||||
let mutable answer = 0
|
||||
let mutable pos = 1
|
||||
|
||||
for _, _, bid in parsed do
|
||||
answer <- answer + bid * pos
|
||||
pos <- pos + 1
|
||||
|
||||
answer
|
||||
|
||||
let part2 (s : string) =
|
||||
let arr = parse true s
|
||||
let parsed = parse true s
|
||||
|
||||
arr.Sort ()
|
||||
parsed.Sort compBasic
|
||||
|
||||
let mutable answer = 0ul
|
||||
let mutable answer = 0
|
||||
let mutable pos = 1
|
||||
|
||||
for i = 0 to arr.Count - 1 do
|
||||
answer <- answer + getBid arr.[i] * (uint32 i + 1ul)
|
||||
for _, _, bid in parsed do
|
||||
answer <- answer + bid * pos
|
||||
pos <- pos + 1
|
||||
|
||||
answer
|
||||
|
@@ -1,110 +0,0 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
open System
|
||||
open System.Collections.Generic
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day8 =
|
||||
|
||||
type Instructions =
|
||||
{
|
||||
/// "true" is 'R'
|
||||
Steps : bool array
|
||||
|
||||
Nodes : Dictionary<string, string * string>
|
||||
}
|
||||
|
||||
let parse (s : string) =
|
||||
use mutable lines = StringSplitEnumerator.make '\n' s
|
||||
|
||||
lines.MoveNext () |> ignore
|
||||
|
||||
let stepsLine = lines.Current.TrimEnd ()
|
||||
let steps = Array.zeroCreate stepsLine.Length
|
||||
|
||||
for i = 0 to stepsLine.Length - 1 do
|
||||
steps.[i] <- (stepsLine.[i] = 'R')
|
||||
|
||||
let dict = Dictionary ()
|
||||
|
||||
while lines.MoveNext () do
|
||||
if not lines.Current.IsEmpty then
|
||||
use mutable line = StringSplitEnumerator.make' ' ' lines.Current
|
||||
line.MoveNext () |> ignore
|
||||
let key = line.Current.ToString ()
|
||||
line.MoveNext () |> ignore
|
||||
line.MoveNext () |> ignore
|
||||
let v1 = line.Current.Slice(1, line.Current.Length - 2).ToString ()
|
||||
line.MoveNext () |> ignore
|
||||
let v2 = line.Current.Slice(0, line.Current.Length - 1).ToString ()
|
||||
dict.[key] <- (v1, v2)
|
||||
|
||||
{
|
||||
Steps = steps
|
||||
Nodes = dict
|
||||
}
|
||||
|
||||
let part1 (s : string) =
|
||||
let data = parse s
|
||||
let mutable i = 0
|
||||
let mutable currentNode = "AAA"
|
||||
let mutable answer = 0
|
||||
|
||||
while currentNode <> "ZZZ" do
|
||||
let instruction = data.Nodes.[currentNode]
|
||||
|
||||
if data.Steps.[i] then
|
||||
// "true" is R
|
||||
currentNode <- snd instruction
|
||||
else
|
||||
currentNode <- fst instruction
|
||||
|
||||
i <- (i + 1) % data.Steps.Length
|
||||
answer <- answer + 1
|
||||
|
||||
answer
|
||||
|
||||
let inline lcm (periods : ^T[]) =
|
||||
let mutable lcm = periods.[0]
|
||||
let mutable i = 1
|
||||
|
||||
while i < periods.Length do
|
||||
let euclid = Arithmetic.euclideanAlgorithm lcm periods.[i]
|
||||
lcm <- (lcm * periods.[i]) / euclid.Hcf
|
||||
i <- i + 1
|
||||
|
||||
lcm
|
||||
|
||||
let part2 (s : string) =
|
||||
let data = parse s
|
||||
|
||||
let startingNodes = ResizeArray ()
|
||||
|
||||
for key in data.Nodes.Keys do
|
||||
if key.[key.Length - 1] = 'A' then
|
||||
startingNodes.Add key
|
||||
|
||||
let periods =
|
||||
Array.init
|
||||
startingNodes.Count
|
||||
(fun startNode ->
|
||||
let mutable i = 0
|
||||
let mutable currentNode = startingNodes.[startNode]
|
||||
let mutable answer = 0ul
|
||||
|
||||
while currentNode.[currentNode.Length - 1] <> 'Z' do
|
||||
let instruction = data.Nodes.[currentNode]
|
||||
|
||||
if data.Steps.[i] then
|
||||
// "true" is R
|
||||
currentNode <- snd instruction
|
||||
else
|
||||
currentNode <- fst instruction
|
||||
|
||||
i <- (i + 1) % data.Steps.Length
|
||||
answer <- answer + 1ul
|
||||
|
||||
uint64 answer
|
||||
)
|
||||
|
||||
lcm periods
|
@@ -1,40 +0,0 @@
|
||||
namespace AdventOfCode2023.ResizeArray
|
||||
|
||||
open System
|
||||
|
||||
type ResizeArray<'T> =
|
||||
private
|
||||
{
|
||||
mutable Array : 'T array
|
||||
mutable Length : int
|
||||
}
|
||||
|
||||
member this.Count = this.Length
|
||||
member this.Clear () = this.Length <- 0
|
||||
|
||||
member this.Add (t : 'T) =
|
||||
if this.Length < this.Array.Length then
|
||||
this.Array.[this.Length] <- t
|
||||
else
|
||||
let newLength = this.Length * 2
|
||||
let newArray = Array.zeroCreate<'T> newLength
|
||||
Array.blit this.Array 0 newArray 0 this.Length
|
||||
newArray.[this.Length] <- t
|
||||
this.Array <- newArray
|
||||
|
||||
this.Length <- this.Length + 1
|
||||
|
||||
member this.Item
|
||||
with get (i : int) = this.Array.[i]
|
||||
and set (i : int) (t : 'T) = this.Array.[i] <- t
|
||||
|
||||
member this.Sort () =
|
||||
Span(this.Array).Slice(0, this.Count).Sort ()
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module ResizeArray =
|
||||
let create<'T> (capacity : int) =
|
||||
{
|
||||
Array = Array.zeroCreate<'T> capacity
|
||||
Length = 0
|
||||
}
|
@@ -23,29 +23,22 @@ module Program =
|
||||
|
||||
let sw = Stopwatch.StartNew ()
|
||||
|
||||
Console.WriteLine "=====Day 1====="
|
||||
printfn "=====Day 1====="
|
||||
|
||||
do
|
||||
sw.Restart ()
|
||||
|
||||
let input =
|
||||
try
|
||||
Path.Combine (dir.FullName, "day1part1.txt") |> File.ReadAllText
|
||||
with :? FileNotFoundException ->
|
||||
Path.Combine (dir.FullName, "day1.txt") |> File.ReadAllText
|
||||
|
||||
let input = Path.Combine (dir.FullName, "day1.txt") |> File.ReadAllText
|
||||
let part1 = Day1.part1 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part1.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
sw.Restart ()
|
||||
let input = Path.Combine (dir.FullName, "day1.txt") |> File.ReadAllText
|
||||
let part2 = Day1.part2 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 2====="
|
||||
printfn "=====Day 2====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day2.txt") |> File.ReadAllText
|
||||
@@ -60,7 +53,7 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 3====="
|
||||
printfn "=====Day 3====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day3.txt") |> File.ReadAllBytes
|
||||
@@ -98,7 +91,7 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 4====="
|
||||
printfn "=====Day 4====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day4.txt") |> File.ReadAllText
|
||||
@@ -113,7 +106,7 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 5====="
|
||||
printfn "=====Day 5====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day5.txt") |> File.ReadAllText
|
||||
@@ -128,7 +121,7 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 6====="
|
||||
printfn "=====Day 6====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day6.txt") |> File.ReadAllText
|
||||
@@ -143,7 +136,7 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 7====="
|
||||
printfn "=====Day 7====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day7.txt") |> File.ReadAllText
|
||||
@@ -158,27 +151,6 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 8====="
|
||||
|
||||
do
|
||||
let input =
|
||||
try
|
||||
Path.Combine (dir.FullName, "day8part1.txt") |> File.ReadAllText
|
||||
with :? FileNotFoundException ->
|
||||
Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
||||
|
||||
sw.Restart ()
|
||||
let part1 = Day8.part1 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part1.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
sw.Restart ()
|
||||
let input = Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
||||
let part2 = Day8.part2 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
endToEnd.Stop ()
|
||||
|
||||
Console.Error.WriteLine (
|
||||
|
@@ -16,7 +16,6 @@
|
||||
<Compile Include="TestDay5.fs" />
|
||||
<Compile Include="TestDay6.fs" />
|
||||
<Compile Include="TestDay7.fs" />
|
||||
<Compile Include="TestDay8.fs" />
|
||||
<EmbeddedResource Include="samples\day1.txt" />
|
||||
<EmbeddedResource Include="samples\day1part1.txt" />
|
||||
<EmbeddedResource Include="samples\day2.txt" />
|
||||
@@ -25,8 +24,6 @@
|
||||
<EmbeddedResource Include="samples\day5.txt" />
|
||||
<EmbeddedResource Include="samples\day6.txt" />
|
||||
<EmbeddedResource Include="samples\day7.txt" />
|
||||
<EmbeddedResource Include="samples\day8part1.txt" />
|
||||
<EmbeddedResource Include="samples\day8.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -13,11 +13,11 @@ module TestDay7 =
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
sample |> Day7.part1 |> shouldEqual 6440ul
|
||||
sample |> Day7.part1 |> shouldEqual 6440
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () =
|
||||
sample |> Day7.part2 |> shouldEqual 5905ul
|
||||
sample |> Day7.part2 |> shouldEqual 5905
|
||||
|
||||
[<Test>]
|
||||
let part1Actual () =
|
||||
@@ -30,7 +30,7 @@ module TestDay7 =
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day7.part1 s |> shouldEqual 250058342ul
|
||||
Day7.part1 s |> shouldEqual 250058342
|
||||
|
||||
[<Test>]
|
||||
let part2Actual () =
|
||||
@@ -43,4 +43,4 @@ module TestDay7 =
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day7.part2 s |> shouldEqual 250506580ul
|
||||
Day7.part2 s |> shouldEqual 250506580
|
||||
|
@@ -1,57 +0,0 @@
|
||||
namespace AdventOfCode2023.Test
|
||||
|
||||
open AdventOfCode2023
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
open System.IO
|
||||
|
||||
[<TestFixture>]
|
||||
module TestDay8 =
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day8part1.txt"
|
||||
|> Day8.part1
|
||||
|> shouldEqual 2
|
||||
|
||||
[<Test>]
|
||||
let part1Sample2 () =
|
||||
"""LLR
|
||||
|
||||
AAA = (BBB, BBB)
|
||||
BBB = (AAA, ZZZ)
|
||||
ZZZ = (ZZZ, ZZZ)"""
|
||||
|> Day8.part1
|
||||
|> shouldEqual 6
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () =
|
||||
Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day8.txt"
|
||||
|> Day8.part2
|
||||
|> shouldEqual 6uL
|
||||
|
||||
[<Test>]
|
||||
let part1Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day8.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day8.part1 s |> shouldEqual 19199
|
||||
|
||||
[<Test>]
|
||||
let part2Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day8.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day8.part2 s |> shouldEqual 13663968099527uL
|
@@ -1,10 +0,0 @@
|
||||
LR
|
||||
|
||||
11A = (11B, XXX)
|
||||
11B = (XXX, 11Z)
|
||||
11Z = (11B, XXX)
|
||||
22A = (22B, XXX)
|
||||
22B = (22C, 22C)
|
||||
22C = (22Z, 22Z)
|
||||
22Z = (22B, 22B)
|
||||
XXX = (XXX, XXX)
|
@@ -1,9 +0,0 @@
|
||||
RL
|
||||
|
||||
AAA = (BBB, CCC)
|
||||
BBB = (DDD, EEE)
|
||||
CCC = (ZZZ, GGG)
|
||||
DDD = (DDD, DDD)
|
||||
EEE = (EEE, EEE)
|
||||
GGG = (GGG, GGG)
|
||||
ZZZ = (ZZZ, ZZZ)
|
21
flake.lock
generated
21
flake.lock
generated
@@ -18,26 +18,6 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-ld": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701153607,
|
||||
"narHash": "sha256-h+odOVyiGmEERMECoFOj5P7FPiMR8IPRzroFA4sKivg=",
|
||||
"owner": "Mic92",
|
||||
"repo": "nix-ld",
|
||||
"rev": "bf5aa84a713c31d95b4307e442e966d6c7fd7ae7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "Mic92",
|
||||
"repo": "nix-ld",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1701253981,
|
||||
@@ -57,7 +37,6 @@
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nix-ld": "nix-ld",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
|
13
flake.nix
13
flake.nix
@@ -3,17 +3,12 @@
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nix-ld = {
|
||||
url = "github:Mic92/nix-ld";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
nix-ld,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
@@ -30,14 +25,9 @@
|
||||
pkgs.darwin.apple_sdk.frameworks.GSS
|
||||
]
|
||||
else [];
|
||||
in let
|
||||
deps = darwinDeps ++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu];
|
||||
in {
|
||||
devShells = {
|
||||
default = pkgs.mkShell {
|
||||
HOME = "/tmp/dotnet-home";
|
||||
NUGET_PACKAGES = "/tmp/dotnet-home/.nuget/packages";
|
||||
LINKER_PATH = "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
|
||||
buildInputs = with pkgs;
|
||||
[
|
||||
(with dotnetCorePackages;
|
||||
@@ -46,7 +36,8 @@
|
||||
dotnetPackages.Nuget
|
||||
])
|
||||
]
|
||||
++ [pkgs.alejandra pkgs.patchelf pkgs.strace];
|
||||
++ darwinDeps
|
||||
++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu pkgs.alejandra];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user