aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--aoc-2022-dotnet/Day04/Day04.fsproj22
-rw-r--r--aoc-2022-dotnet/Day04/Program.fs28
-rw-r--r--aoc-2022-dotnet/README.md4
-rw-r--r--aoc-2022-dotnet/aoc-2022-dotnet.sln8
5 files changed, 60 insertions, 4 deletions
diff --git a/README.md b/README.md
index 5a70b77..4903ec4 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Repository storing my solutions to Advent of Code. See other people's solutions
### [2022](aoc-2022-dotnet)
![.NET](https://img.shields.io/badge/.NET-grey?logo=.NET)
-![Stars](https://img.shields.io/badge/🌟%20stars-6/50-orange)
+![Stars](https://img.shields.io/badge/🌟%20stars-8/50-orange)
[awesome]: https://github.com/Bogdanp/awesome-advent-of-code
[aoc]: https://adventofcode.com
diff --git a/aoc-2022-dotnet/Day04/Day04.fsproj b/aoc-2022-dotnet/Day04/Day04.fsproj
new file mode 100644
index 0000000..44c3fba
--- /dev/null
+++ b/aoc-2022-dotnet/Day04/Day04.fsproj
@@ -0,0 +1,22 @@
+ο»Ώ<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Include="test.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Content Include="input.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="FParsec" Version="1.1.1" />
+ </ItemGroup>
+
+</Project>
diff --git a/aoc-2022-dotnet/Day04/Program.fs b/aoc-2022-dotnet/Day04/Program.fs
new file mode 100644
index 0000000..25cc3b6
--- /dev/null
+++ b/aoc-2022-dotnet/Day04/Program.fs
@@ -0,0 +1,28 @@
+ο»Ώmodule Day04
+
+open System.IO
+open FParsec
+
+let parseLine line =
+ let prange = pint32 .>> pstring "-" .>>. pint32
+ let ppair = prange .>> pstring "," .>>. prange .>> eof
+
+ match run ppair line with
+ | Success (result, _, _) -> result
+ | _ -> failwith "Invalid line format!"
+
+let fullyOverlap ((a, b), (c, d)) =
+ (a <= c && d <= b) || (c <= a && b <= d)
+
+let overlapAtAll ((a, b), (c, d)) = a <= d && b >= c
+
+let solution pred =
+ Seq.map parseLine >> Seq.filter pred >> Seq.length
+
+let test = File.ReadLines "test.txt"
+assert (solution fullyOverlap test = 2)
+assert (solution overlapAtAll test = 4)
+
+let input = File.ReadAllLines "input.txt"
+printfn "%d" <| solution fullyOverlap input
+printfn "%d" <| solution overlapAtAll input
diff --git a/aoc-2022-dotnet/README.md b/aoc-2022-dotnet/README.md
index 922498a..5bb69a2 100644
--- a/aoc-2022-dotnet/README.md
+++ b/aoc-2022-dotnet/README.md
@@ -1,6 +1,6 @@
# Advent of Code 2022 in .NET
![.NET](https://img.shields.io/badge/.NET-grey?logo=.NET)
-![Stars](https://img.shields.io/badge/🌟%20stars-6/50-orange)
+![Stars](https://img.shields.io/badge/🌟%20stars-8/50-orange)
## Progress
| Day | Part 1 | Part 2 |
@@ -8,7 +8,7 @@
| Day 1: Calorie Counting | 🌟 | 🌟 |
| Day 2: Rock Paper Scissors | 🌟 | 🌟 |
| Day 3: Rucksack Reorganization | 🌟 | 🌟 |
-| Day 4: ??? | | |
+| Day 4: ??? | 🌟 | 🌟 |
| Day 5: ??? | | |
| Day 6: ??? | | |
| Day 7: ??? | | |
diff --git a/aoc-2022-dotnet/aoc-2022-dotnet.sln b/aoc-2022-dotnet/aoc-2022-dotnet.sln
index 44b5d4e..b89b48a 100644
--- a/aoc-2022-dotnet/aoc-2022-dotnet.sln
+++ b/aoc-2022-dotnet/aoc-2022-dotnet.sln
@@ -14,7 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day02", "Day02\Day02.fsproj", "{A5148468-D518-4678-B32C-D3C59B6290AB}"
EndProject
-Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day03", "Day03\Day03.fsproj", "{EB78C4D1-7BDD-42AF-820B-32F4102190B1}"
+Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day03", "Day03\Day03.fsproj", "{EB78C4D1-7BDD-42AF-820B-32F4102190B1}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day04", "Day04\Day04.fsproj", "{3E74A210-46A7-420E-93B4-12CCC4B51957}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -34,6 +36,10 @@ Global
{EB78C4D1-7BDD-42AF-820B-32F4102190B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB78C4D1-7BDD-42AF-820B-32F4102190B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB78C4D1-7BDD-42AF-820B-32F4102190B1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3E74A210-46A7-420E-93B4-12CCC4B51957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3E74A210-46A7-420E-93B4-12CCC4B51957}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3E74A210-46A7-420E-93B4-12CCC4B51957}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3E74A210-46A7-420E-93B4-12CCC4B51957}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE