summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--AoC2022.fsproj10
-rw-r--r--Program.fs14
-rw-r--r--solutions/day1.fs19
4 files changed, 47 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d3592bd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.vscode
+bin/
+obj/
+inputs/
\ No newline at end of file
diff --git a/AoC2022.fsproj b/AoC2022.fsproj
new file mode 100644
index 0000000..ab87952
--- /dev/null
+++ b/AoC2022.fsproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net6.0</TargetFramework>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="solutions/day1.fs" />
+    <Compile Include="Program.fs" />
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/Program.fs b/Program.fs
new file mode 100644
index 0000000..a16ec03
--- /dev/null
+++ b/Program.fs
@@ -0,0 +1,14 @@
+open Solutions
+exception NotImplementedYet of string
+
+let args = System.Environment.GetCommandLineArgs()
+
+assert (Array.length args = 3)
+
+let day, part = int args[1], int args[2]
+
+match (day, part) with
+| (1, 1) -> Day1.part1 () |> printf "%A\n"
+| (1, 2) -> Day1.part2 () |> printf "%A\n"
+| _ -> raise (NotImplementedYet("not implemented yet"))
+|> printf "%A\n"
\ No newline at end of file
diff --git a/solutions/day1.fs b/solutions/day1.fs
new file mode 100644
index 0000000..0b2c519
--- /dev/null
+++ b/solutions/day1.fs
@@ -0,0 +1,19 @@
+namespace Solutions
+
+module Day1 =
+    open System.IO
+
+    let lines = File.ReadLines("inputs/day1.txt")
+    let totalWeights = seq {
+        let mutable subseq = 0
+
+        for line in lines do
+        if line.Equals("") then
+            yield subseq
+            subseq <- 0
+        else
+            subseq <- subseq + int line
+    }
+
+    let part1 () = totalWeights |> Seq.max
+    let part2 () = totalWeights |> Seq.sortDescending |> Seq.take 3 |> Seq.sum
#n218'>218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339