WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bf3bc05

Browse files
author
Jimmy Sorting
committed
wip
1 parent 65f88e1 commit bf3bc05

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

2020/Day14.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ module Day14 =
2424

2525
let applyMask bitMask (value: int64) =
2626
let b = Convert.ToString(value, 2).PadLeft(36, '0').ToCharArray()
27-
bitMask
28-
|> Seq.iteri (fun i x -> if x <> 'X' then b.[i] <- x)
27+
bitMask |> Seq.iteri (fun i x -> if x <> 'X' then b.[i] <- x)
2928
Convert.ToInt64(Array.map string b |> String.concat "", 2)
3029

3130
let getAll arr =

2020/Day15.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ module Day15 =
3333
| x :: xs ->
3434
turn (turnNumber + 1) { game with Turns = Map.add x (0, turnNumber) game.Turns; LastSpoken = Some x; First = not (Map.containsKey x game.Turns) } endTurn xs
3535

36-
let part1() = (turn 1 { Turns = Map.empty; LastSpoken = None; First = false } 2020 numbers)
37-
let part2() = (turn 1 { Turns = Map.empty; LastSpoken = None; First = false } 30000000 numbers)
36+
let initState = { Turns = Map.empty; LastSpoken = None; First = false }
37+
38+
let part1() = turn 1 initState 2020 numbers
39+
let part2() = turn 1 initState 30000000 numbers
3840

3941
let solve () = printDay 2020 15 part1 part2

2020/Day16.fs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ module Day16 =
2828
if value >= min && value <= max then if reverse then Some value else None
2929
else findInvalidValue value reverse xs
3030

31-
let rec findCandidates value candidateFields = function
32-
| [] -> candidateFields
33-
| RangeRule(field, min, max) :: xs ->
34-
if value >= min && value <= max then findCandidates value (field :: candidateFields) xs
35-
else findCandidates value candidateFields xs
36-
3731
let part1() =
3832
ticketTranslator.Tickets
3933
|> List.collect (fun values -> values |> List.choose (fun value -> findInvalidValue value false ticketTranslator.Rules))
4034
|> List.sum
4135

36+
let rec findCandidates value candidateFields = function
37+
| [] -> candidateFields
38+
| RangeRule(field, min, max) :: xs ->
39+
if value >= min && value <= max then findCandidates value (field :: candidateFields) xs
40+
else findCandidates value candidateFields xs
41+
4242
let part2() =
4343
let myTicket = List.head ticketTranslator.Tickets
4444
let validNearbyTickets =
@@ -66,11 +66,10 @@ module Day16 =
6666
|> List.sortBy (snd >> List.length)
6767
|> List.fold (fun map (field, candidates) ->
6868
candidates
69-
|> List.filter (fun idx -> not (Map.containsKey idx map))
70-
|> List.head
69+
|> List.find (fun idx -> not (Map.containsKey idx map))
7170
|> fun idx -> Map.add idx field map) Map.empty
7271
|> Map.toList
73-
|> List.filter (fun (_, field) -> field.Contains("departure"))
72+
|> List.filter (fun (_, field) -> field.StartsWith("departure"))
7473
|> List.map (fun (idx, _) -> int64 (List.item idx myTicket))
7574
|> List.reduce (*)
7675

2020/Day17.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Year2020
2+
3+
module Day17 =
4+
open Utilities
5+
6+
let part1() = 0
7+
let part2() = 0
8+
9+
let solve () = printDay 2020 17 part1 part2

2020/input/day17.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.#.
2+
..#
3+
###

Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let main argv =
2121
((2020, 7), Year2020.Day07.solve); ((2020, 8), Year2020.Day08.solve); ((2020, 9), Year2020.Day09.solve)
2222
((2020, 10), Year2020.Day10.solve); ((2020, 11), Year2020.Day11.solve); ((2020, 12), Year2020.Day12.solve)
2323
((2020, 13), Year2020.Day13.solve); ((2020, 14), Year2020.Day14.solve); ((2020, 15), Year2020.Day15.solve)
24-
((2020, 16), Year2020.Day16.solve)
24+
((2020, 16), Year2020.Day16.solve); ((2020, 17), Year2020.Day17.solve)
2525
]
2626

2727
match argv |> List.ofArray with

aoc.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<Compile Include="2020/Day14.fs" />
5252
<Compile Include="2020/Day15.fs" />
5353
<Compile Include="2020/Day16.fs" />
54+
<Compile Include="2020/Day17.fs" />
5455
<Compile Include="Program.fs" />
5556
</ItemGroup>
5657

0 commit comments

Comments
 (0)