File tree Expand file tree Collapse file tree 3 files changed +82
-10
lines changed Expand file tree Collapse file tree 3 files changed +82
-10
lines changed Original file line number Diff line number Diff line change 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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 9
9
</PropertyGroup >
10
10
11
11
<ItemGroup >
12
- <Compile Include =" Tests.fs" />
13
12
<Compile Include =" Program.fs" />
14
13
</ItemGroup >
15
14
You can’t perform that action at this time.
0 commit comments