Skip to content

Commit 89aeda4

Browse files
committed
day25
1 parent 85eb189 commit 89aeda4

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

day25/Program.fs

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
module Program = let [<EntryPoint>] main _ = 0
1+
open Xunit
2+
open FsUnit.Xunit
3+
4+
let part1 (schematics: char[][] list) =
5+
let h, w = schematics[0].Length, (schematics[0][0]).Length
6+
7+
let locks =
8+
schematics
9+
|> List.filter (fun s -> s[0] |> Array.forall ((=) '#'))
10+
|> List.map (fun s ->
11+
[ 0 .. (w - 1) ]
12+
|> List.map (fun j -> [ 0 .. (h - 1) ] |> List.sumBy (fun i -> if s[i][j] = '.' then 0 else 1)))
13+
14+
let keys =
15+
schematics
16+
|> List.filter (fun s -> s[0] |> Array.forall ((=) '.'))
17+
|> List.map (fun s ->
18+
[ 0 .. (w - 1) ]
19+
|> List.map (fun j -> [ 0 .. (h - 1) ] |> List.sumBy (fun i -> if s[i][j] = '.' then 0 else 1)))
20+
21+
List.allPairs locks keys
22+
|> List.filter (fun (lock, key) -> List.zip lock key |> List.forall (fun (lock, key) -> lock + key <= h))
23+
|> List.length
24+
25+
let parse (input: string) =
26+
input.Split("\n\n")
27+
|> Array.map (fun section -> section.Split("\n") |> Array.map (fun line -> line.ToCharArray()))
28+
|> Array.toList
29+
30+
module Example =
31+
let input =
32+
"#####
33+
.####
34+
.####
35+
.####
36+
.#.#.
37+
.#...
38+
.....
39+
40+
#####
41+
##.##
42+
.#.##
43+
...##
44+
...#.
45+
...#.
46+
.....
47+
48+
.....
49+
#....
50+
#....
51+
#...#
52+
#.#.#
53+
#.###
54+
#####
55+
56+
.....
57+
.....
58+
#.#..
59+
###..
60+
###.#
61+
###.#
62+
#####
63+
64+
.....
65+
.....
66+
.....
67+
#....
68+
#.#..
69+
#.#.#
70+
#####"
71+
72+
[<Fact>]
73+
let testPart1 () = parse input |> part1 |> should equal 3
74+
75+
[<EntryPoint>]
76+
let main _ =
77+
let input = stdin.ReadToEnd().TrimEnd()
78+
let schematics = parse input
79+
80+
schematics |> part1 |> printfn "Part 1: %d"
81+
82+
0

day25/Tests.fs

Lines changed: 0 additions & 8 deletions
This file was deleted.

day25/day25.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<Compile Include="Tests.fs" />
1312
<Compile Include="Program.fs" />
1413
</ItemGroup>
1514

0 commit comments

Comments
 (0)