-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
32 lines (25 loc) · 822 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright © 2020 Aman Agnihotri
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using MoreLinq;
var jolts = File.ReadLines("Input.txt")
.Select(int.Parse)
.ToImmutableSortedSet();
jolts = jolts.Add(0).Add(jolts.Max + 3);
var diffCounts = jolts
.Window(2)
.GroupBy(js => js[^1] - js[0])
.ToImmutableDictionary(diff => diff.Key, diff => diff.Count());
var routes = new Dictionary<int, long> {{0, 1}};
jolts.Skip(1).ForEach(jolt =>
{
routes[jolt] = routes.GetValueOrDefault(jolt - 1) +
routes.GetValueOrDefault(jolt - 2) +
routes.GetValueOrDefault(jolt - 3);
});
Console.WriteLine(diffCounts[1] * diffCounts[3]);
Console.WriteLine(routes[jolts.Max]);