Compare commits
2
Commits
31daf11e94
...
4bb3a94fb2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bb3a94fb2 | ||
|
|
94ff88dcba |
No files matched your search
@@ -2,3 +2,63 @@ bin
|
|||||||
obj
|
obj
|
||||||
.idea
|
.idea
|
||||||
*.DotSettings*
|
*.DotSettings*
|
||||||
|
bin/*
|
||||||
|
obj/*
|
||||||
|
|
||||||
|
## A streamlined .gitignore for modern .NET projects
|
||||||
|
## including temporary files, build results, and
|
||||||
|
## files generated by popular .NET tools. If you are
|
||||||
|
## developing with Visual Studio, the VS .gitignore
|
||||||
|
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||||
|
## has more thorough IDE-specific entries.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# Others
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
CodeCoverage/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
@@ -31,9 +31,22 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
||||||
|
<Content Include="Inputs\Quest03\Q03_P01.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
|
||||||
|
<Content Include="Inputs\Quest03\Q03_P02.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
|
||||||
|
<Content Include="Inputs\Quest03\Q03_P03.txt">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
|
||||||
<Compile Include="Helpers.fs" />
|
<Compile Include="Helpers.fs" />
|
||||||
<Compile Include="Quest01.fs" />
|
<Compile Include="Quest01.fs" />
|
||||||
<Compile Include="Quest02.fs" />
|
<Compile Include="Quest02.fs" />
|
||||||
|
<Compile Include="Quest03.fs" />
|
||||||
<Compile Include="Program.fs"/>
|
<Compile Include="Program.fs"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
8,55,7,42,40,45,33,31,64,60,49,66,83,78,33,23,72,15,35,11,84,30,44,66,20,66,88,7,3,51,85,54,38,88,2,37,2,56,47,40,82,79,51,18,81,69,46,52,56,5,82,73,15,76,13,11,31,43,50,89,79,85,11,44,26,6,12,49,82,28,66,36,66,22,44,39,2,39,83,15,63,82,10,73,20,64,17,25,43,72,54,47,30,15,46,87,85,17,57,6
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
88,59,145,183,26,132,49,153,120,180,134,184,132,6,29,57,137,105,166,61,105,49,10,55,149,145,165,88,56,140,78,78,167,84,82,22,21,185,63,38,65,55,140,27,109,104,156,101,156,7,145,30,127,88,145,44,113,142,14,60,77,92,147,76,74,189,104,186,100,175,118,104,94,182,7,52,110,12,132,18,123,161,148,174,150,18,66,107,179,81,178,26,136,23,92,95,10,10,34,4,134,138,107,12,27,26,76,77,31,44,113,17,54,31,71,22,63,172,145,65,138,47,119,56,50,40,162,150,56,85,65,27,4,172,113,26,59,104,86,158,67,93,134,47,178,115,3,7,24,70,53,159,170,183,165,129,92,36,104,110,120,8,2,133,60,118,181,70,132,67,180,133,185,111,107,93,10,19,154,185,29,144,79,3,14,5,15,132,179,18,77,140,68,20,109,43,36,115,77,83,49,80,189,120,6,152,16,98,144,171,83,88,165,6,52,157,102,119,158,127,138,11,48,142,21,159,55,173,45,176,9,141,109,44,36,166,143,144,138,134,86,129,106,80,41,100,56,143,125,73,94,86,51,137,29,75,107,117,110,145,161,70,180,26,45,146,123,150,28,68,6,148,40,84,134,121,113,29,148,19,174,140,147,147,94,98,18,149,59,156,22,83,40,145,180,86,44,3,118,26
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
50,3,58,65,71,94,89,50,2,76,50,1,70,27,50,60,14,59,50,49,77,99,21,50,93,50,95,56,98,50,39,50,50,34,29,50,41,85,64,75,44,53,56,65,57,5,81,18,95,28,40,68,2,61,66,88,92,72,50,74,21,35,51,50,9,69,50,50,70,32,57,85,32,78,50,78,50,50,30,54,67,95,77,50,44,50,69,58,45,41,30,50,82,94,83,50,92,82,75,7,50,73,50,90,98,5,40,50,74,2,50,96,38,50,50,50,66,77,65,58,50,69,67,34,73,12,91,31,70,5,33,2,50,50,4,50,48,59,57,93,20,38,50,50,16,54,97,16,94,76,5,94,50,11,21,64,84,50,70,73,52,50,50,26,54,50,65,22,50,65,50,50,23,40,91,67,50,50,60,37,30,59,50,25,32,84,14,99,74,91,50,88,72,77,80,37,33,50,50,62,66,61,50,9,91,50,65,86,50,50,50,8,43,50,65,21,88,50,31,50,45,50,58,29,97,64,48,52,47,18,34,87,59,13,31,14,50,58,50,90,50,50,28,50,11,39,54,50,10,1,5,28,50,42,77,50,8,50,50,50,99,17,64,50,1,22,18,45,16,41,50,50,84,50,50,7,12,80,50,14,50,22,50,93,50,50,73,50,57,50,50,59,37,50,50,79,86,50,50,50,77,50,82,97,50,75,63,86,46,27,50,50,50,57,83,85,50,50,51,50,50,50,41,37,50,50,50,38,50,50,73,63,78,50,50,68,89,50,43,50,50,50,51,60,83,32,81,65,42,15,50,56,38,50,60,35,50,65,74,50,50,50,50,50,50,9,40,53,6,92,50,68,76,34,50,50,50,50,50,87,59,38,38,75,39,13,50,46,50,50,50,45,31,50,98,67,99,22,55,37,51,88,50,21,50,26,50,50,80,39,30,38,50,50,50,50,68,72,50,50,50,50,44,50,6,50,47,23,64,50,20,84,50,50,19,17,94,90,50,50,67,40,50,50,6,72,20,26,27,50,99,50,42,50,50,50,15,50,50,50,94,44,50,44,50,3,50,98,18,50,61,50,77,50,50,5,50,19,9,48,50,32,50,19,50,50,98,50,50,50,50,50,99,50,50,50,50,78,50,17,50,50,50,6,51,50,26,90,87,50,53,50,50,51,92,50,35,58,50,82,50,2,50,73,50,34,10,50,88,56,63,50,50,53,50,10,55,2,50,73,32,12,50,73,50,40,50,74,2,39,88,26,15,51,99,50,38,84,76,69,50,21,46,49,50,90,50,28,57,50,17,50,50,50,38,50,31,50,50,6,50,50,50,50,98,35,81,50,50,50,50,50,8,31,50,50,60,50,50,50,50,50,50,60,1,99,50,8,50,63,50,50,50,97,62,8,55,50,50,50,50,50,50,26,50,66,2,50,50,50,87,94,50,92,74,11,50,50,50,50,50,41,50,50,50,30,50,50,43,50,50,68,50,18,50,49,72,72,97,99,16,50,49,50,49,50,63,50,22,41,37,50,30,50,5,50,50,62,50,50,50,25,50,4,50,50,50,53,94,50,16,50,12,57,86,51,50,50,40,76,24,66,84,28,3,12,50,37,53,36,50,16,33,50,27,50,50,67,75,22,32,82,59,51,50,50,38,50,50,79,50,36,23,50,73,30,50,82,47,24,50,50,50,50,62,93,78,93,50,19,50,50,43,28,88,29,50,67,40,26,79,75,92,50,50,68,48,42,50,87,50,47,14,45,70,99,75,34,50,47,50,59,48,65,16,68,65,63,50,85,50,65,50,50,12,3,50,50,46,14,83,50,93,56,54,12,50,50,51,73,46,80,25,50,6,50,47,50,99,6,19,34,50,77,50,50,7,50,86,24,65,50,50,50,20,58,50,57,70,51,19,96,77,50,50,65,82,34,99,93,80,15,80,19,23,50,50,2,1,79,50,43,7,95,65,17,50,70,24,19,50,82,50,32,98,50,97,25,14,48,54,99,61,50,94,50,50,50,95,50,87,61,59,13,60,48,54,92,29,50,54,63,50,22,34,52,46,50,23,10,3,72,19,76,50,50,88,4,97,59,30,68,78,46,12,35,56,75,11,96,50,51,56,33,96,52,79,85,91,50,84,91,32,50,49,95,50,6,19,27,51,35,50,71,13,8,8,50,61,83,53,50,50,15,17,1,50,36,50,49,42,52,20,50,50,54,50,24,43,12,40,46,50,62,50,71,50,50,90,50,22,50,50,16,66,50,19,50,46,50,25,58,96,88,50,92,50,42,50,20,50,92,50,93,37,50,39,2,46,92,7,35,6,3,5,65,74,19,50,37,50,49,50,31,51,3,75,31,50,50,5,32,29,50,36,50,21,22,17,11,6,14,30,38,7,50,50,50,50,77,40,43,14,37,50,70,7,67,50,50,50,99,50,31,80,50,51,3,50,80,60,50,50,70,69,50,50,50,50,50,50,46,47,50,8,24,50,50,55,1,4,50,50,50,50,50,50,50,78,41,40,34,50,94,50,50,96,50,85,50,16,50,88,79,50,52,50,50,50,55,82,95,50,73,50,2,50,66,64,95,50,50,50,75,46,50,82,28,86,83,77,50,88,50,50,50,72,88,48,22,39,50,42,66,50,43,50,32,51,50,32,11,18,47,18,50,28,13,50,79,39,50,57,50,89,23,50,84,49,71,50,50,40,80,50,92,50,76,1,63,50,41,50,18,61,17,50,78,48,36,50,50,37,8,50,4,83,50,50,88,46,31,50,74,50,50,8,50,4,97,65,36,78,63,33,84,89,11,50,46,2,34,50,85,20,41,21,55,66,92,72,50,60,72,4,98,50,92,11,85,37,50,83,68,28,50,73,67,45,50,34,32,50,50,50,27,50,20,8,50,55,50,20,44,12,50,9,50,67,37,50,50,83,42,80,41,50,50,50,8,85,50,50,46,50,56,50,50,50,7,42,50,25,29,50,50,29,77,50,96,72,31,91,79,7,33,50,16,98,29,13,36,96,29,83,84,50,50,3,78,50,67,92,50,91,30,21,6,10,50,10,95,15,50,53,50,90,84,50,50,3,27,95,79,50,39,50,50,60,99,50,17,50,43,23,50,50,31,61,67,50,61,50,34,50,50,39,65,93,79,85,50,50,35,50,70,9,12,50,50,34,10,50,8,65,95,14,50,50,26,45,22,42,28,89,50,19,94,50,50,50,51,86,5,50,50,23,43,77,91,99,39,2,52,50,50,50,50,50,16,53,50,50,69,50,69,50,64,50,31,59,50,60,50,35,50,27,50,50,28,29,1,42,50,62,86,50,79,50,92,50,50,57,5,50,50,50,13,85,67,96,88,50,78,45,50,84,50,64,50,11,50,50,78,29,81,67,50,79,50,20,26,50,78,97,50,22,17,25,94,5,88,69,10,29,98,41,50,97,92,42,60,32,80,31,77,37,10,71,50,8,50,50,94,50,49,73,5,14,3,24,12,55,8,63,50,59,88,47,79,65,23,50,99,60,72,42,39,50,71,80,35,44,50,53,61,87,50,56,60,50,58,44,50,50,50,50,50,64,50,50,38,50,50,95,50,27,46,89,50,54,50,18,22,35,24,97,72,42,87,50,94,82,57,19,50,96,50,74,59,9,50,51,50,95,78,50,92,89,50,12,97,21,50,99,86,50,50,50,99,5,72,48,50,50,45,1,46,7,4,50,43,33,54,50,35,36,79,30,4,50,86,27,50,50,50,59,30,50,59,39,85,50,50,50,50,27,42,50,50,50,99,50,33,8,37,58,50,50,50,50,50,50,25,80,28,63,43,50,50,25,50,51,34,50,29,50,7,65,97,6Line truncated
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
module EveryBodyCodes2025.Quest03
|
||||||
|
|
||||||
|
open System.Collections.Generic
|
||||||
|
open System.IO
|
||||||
|
open System.Linq
|
||||||
|
open System
|
||||||
|
open System.Runtime.CompilerServices
|
||||||
|
|
||||||
|
type Crate = int
|
||||||
|
// sorted set because only one item can be in at a time. The SortedSet is unnecessary here since the inputs are already sorted
|
||||||
|
type CrateSet = SortedSet<Crate>
|
||||||
|
let inline newCrateSet crate =
|
||||||
|
let cs = CrateSet()
|
||||||
|
cs.Add(crate) |> ignore
|
||||||
|
cs
|
||||||
|
type Extensions() =
|
||||||
|
[<Extension>]
|
||||||
|
static member inline SmallestCrate (crates:CrateSet) : Crate option = match crates.Min with | 0 -> None | x -> Some x
|
||||||
|
[<Extension>]
|
||||||
|
static member inline LargestCrate (crates:CrateSet) : Crate option = match crates.Max with | 0 -> None | x -> Some x
|
||||||
|
|
||||||
|
|
||||||
|
/// take a sorted input (not verified) and prioritize insertion into the first found list.
|
||||||
|
/// This results in cascading to the "next best fit", but this approach relies on sorted inputs.
|
||||||
|
let packEfficiently allCrates =
|
||||||
|
allCrates
|
||||||
|
|> Seq.fold (fun sortedCrates next ->
|
||||||
|
// find the first crate set that can hold the next item and put it in there
|
||||||
|
match sortedCrates with
|
||||||
|
| [] -> [newCrateSet next]
|
||||||
|
| items ->
|
||||||
|
match List.tryFind (fun (i:CrateSet) ->
|
||||||
|
match i.SmallestCrate() with
|
||||||
|
| Some c when c > next -> true
|
||||||
|
| _ -> false) items with
|
||||||
|
| None ->
|
||||||
|
let cs = newCrateSet next
|
||||||
|
items@[cs] // appending to the end is less efficient for linked lists, but ensures that the first one gets the best goodies
|
||||||
|
| Some crates ->
|
||||||
|
if not (crates.Add(next)) then failwith "failed to add" // really wrong if this happens
|
||||||
|
items
|
||||||
|
|
||||||
|
) []
|
||||||
|
|
||||||
|
|
||||||
|
let parseInput file =
|
||||||
|
File.ReadLines(file)
|
||||||
|
|> Enumerable.First
|
||||||
|
|> _.Split(",")
|
||||||
|
|> Array.map Int32.Parse
|
||||||
|
|
||||||
|
let part1Test() =
|
||||||
|
"10,5,1,10,3,8,5,2,2"
|
||||||
|
|> _.Split(",")
|
||||||
|
|> Array.map Int32.Parse
|
||||||
|
|> Enumerable.OrderDescending
|
||||||
|
|> packEfficiently
|
||||||
|
|> _.Max(_.Sum())
|
||||||
|
|
||||||
|
let part1 () =
|
||||||
|
parseInput "Inputs/Quest03/Q03_P01.txt"
|
||||||
|
|> Enumerable.OrderDescending
|
||||||
|
|> packEfficiently
|
||||||
|
|> _.Max(_.Sum())
|
||||||
|
|
||||||
|
// Part 2 I thought would be better to invert the sorting (asc vs desc) to part 1. It also adds an add filter to 20 items.
|
||||||
|
let part2Impl allCrates =
|
||||||
|
allCrates
|
||||||
|
|> Seq.fold (fun sortedCrates next ->
|
||||||
|
//smallest set of max size - sort ascending, add up until there are 20 items, then it is not eligible
|
||||||
|
match sortedCrates with
|
||||||
|
| [] ->
|
||||||
|
let cs = CrateSet()
|
||||||
|
cs.Add(next) |> ignore
|
||||||
|
[cs]
|
||||||
|
| items ->
|
||||||
|
match List.tryFind (fun (i:CrateSet) ->
|
||||||
|
if i.Count >= 20 then false
|
||||||
|
else
|
||||||
|
match i.LargestCrate() with
|
||||||
|
| Some c when c < next -> true
|
||||||
|
| _ -> false) items with
|
||||||
|
| None ->
|
||||||
|
let cs = CrateSet()
|
||||||
|
match cs.Add(next) with | true -> () | false -> failwith "failed to add"
|
||||||
|
items@[cs]
|
||||||
|
| Some crates ->
|
||||||
|
match crates.Add(next) with | true -> () | false -> failwith "failed to add"
|
||||||
|
items
|
||||||
|
) []
|
||||||
|
|
||||||
|
let part2Test() =
|
||||||
|
"4,51,13,64,57,51,82,57,16,88,89,48,32,49,49,2,84,65,49,43,9,13,2,3,75,72,63,48,61,14,40,77"
|
||||||
|
|> _.Split(",")
|
||||||
|
|> Array.map Int32.Parse
|
||||||
|
|> Enumerable.Order
|
||||||
|
|> part2Impl
|
||||||
|
|> List.filter (fun x -> x.Count = 20)
|
||||||
|
|> _.Min(_.Sum())
|
||||||
|
|
||||||
|
let part2() =
|
||||||
|
parseInput "Inputs/Quest03/Q03_P02.txt"
|
||||||
|
|> Enumerable.Order
|
||||||
|
|> part2Impl
|
||||||
|
|> List.filter (fun x -> x.Count = 20)
|
||||||
|
|> _.Min(_.Sum())
|
||||||
|
|
||||||
|
let part3() =
|
||||||
|
parseInput "Inputs/Quest03/Q03_P03.txt"
|
||||||
|
|> Enumerable.OrderDescending
|
||||||
|
|> packEfficiently
|
||||||
|
|> _.Count()
|
||||||
|
|
||||||
Reference in new issue
Block a user