These are my solutions in C# and F# for Advent of Code 2015-2023.
You can find benchmarks at the bottom of this README.
About my solutions:
- My solutions tend to favour high performance over readability, I use Advent of Code as a way to practice my skills in writing high-performance code.
- If you are struggling to understand any of my solutions, feel free to create an issue to ask about it and I will provide an explanation for you.
- Oftentimes my solutions may not solve the general case as most of the problems are not clear on all the input constraints, however it will solve all actual inputs that could appear.
- Feel free to copy my solutions if you are stuck, credit is always appreciated but not required since many of my approaches are not unique.
- All my solutions are single-threaded, but they will often make use of SIMD as a way to emulate parallelism on a single thread.
Day | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 |
---|---|---|---|---|---|---|---|---|---|
1 | C# | F# | C# | F# | C# | F# | C# | F# | C# | F# | C# | C# | C# | C# |
2 | C# | F# | C# | F# | C# | F# | C# | F# | C# | F# | C# | C# | C# | C# |
3 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | C# |
4 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | C# |
5 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | C# |
6 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | C# |
7 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | C# |
8 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
9 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
10 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
11 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
12 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
13 | C# | F# | C# | F# | F# | F# | F# | C# | C# | C# | |
14 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
15 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
16 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
17 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
18 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
19 | C# | F# | F# | F# | F# | F# | C# | C# | C# | C# |
20 | C# | F# | F# | F# | F# | F# | C# | C# | C# | C# |
21 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
22 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
23 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
24 | C# | F# | F# | F# | F# | F# | C# | C# | C# | |
25 | C# | F# | F# | F# | F# | F# | C# | C# | C# |
BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.2715/22H2/2022Update/SunValley2)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK 8.0.100
[Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 43.86 μs | 44.01 μs | 44.29 μs | -- |
2 | 2.99 μs | 3.00 μs | 3.02 μs | -- |
3 | 11.15 μs | 11.23 μs | 11.63 μs | 584 B |
4 | 9.80 μs | 9.91 μs | 9.93 μs | -- |
5 | 7.06 μs | 7.11 μs | 7.22 μs | 7.6 KB |
6 | 0.12 μs | 0.12 μs | 0.12 μs | -- |
7 | 74.99 μs | 75.12 μs | 75.62 μs | 16.0 KB |
8 | 76.05 μs | 76.90 μs | 77.41 μs | 22.4 KB |
9 | 19.77 μs | 20.17 μs | 21.03 μs | -- |
10 | 45.81 μs | 45.92 μs | 46.08 μs | -- |
11 | 2.13 μs | 2.15 μs | 2.15 μs | 584 B |
12 | 1,638.72 μs | 1,655.85 μs | 1,675.29 μs | 162.0 KB |
13 | 15.11 μs | 15.31 μs | 15.54 μs | -- |
14 | 1,653.89 μs | 1,661.73 μs | 1,666.60 μs | 11.8 KB |
15 | 66.49 μs | 66.76 μs | 67.16 μs | 65.6 KB |
16 | 261.27 μs | 264.36 μs | 265.81 μs | 851.7 KB |
17 | 3,187.56 μs | 3,194.01 μs | 3,223.26 μs | 411.7 KB |
18 | 3.99 μs | 4.03 μs | 4.04 μs | -- |
19 | 45.24 μs | 45.53 μs | 45.76 μs | -- |
20 | 3.15 μs | 3.18 μs | 3.19 μs | 15.8 KB |
21 | 15.13 μs | 15.18 μs | 15.19 μs | -- |
22 | 59.05 μs | 59.28 μs | 59.62 μs | 17.8 KB |
23 | 240.03 μs | 241.12 μs | 241.53 μs | 25.5 KB |
24 | 242.95 μs | 243.72 μs | 245.08 μs | 13.3 KB |
25 | 213.96 μs | 214.80 μs | 215.22 μs | 282.2 KB |
All | 8,141.14 μs | 8,156.37 μs | 8,164.63 μs | 1.9 MB |
2023 benchmarks are a result of measuring my solver on 5 separate inputs in a row. This means the results should be more representative and less susceptible to branch prediction biases.
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 5.06 μs | 5.09 μs | 5.74 μs | -- |
2 | 5.23 μs | 5.25 μs | 5.29 μs | -- |
3 | 5.01 μs | 5.03 μs | 5.08 μs | -- |
4 | 4.23 μs | 4.27 μs | 4.42 μs | -- |
5 | 5.69 μs | 5.70 μs | 5.73 μs | 1.8 KB |
6 | 6.18 μs | 6.21 μs | 6.22 μs | -- |
7 | 3.64 μs | 3.66 μs | 3.67 μs | 1.1 KB |
19 | 86.84 μs | 87.22 μs | 87.77 μs | 177.5 KB |
20 | 5,168.68 μs | 5,205.51 μs | 5,353.50 μs | 105.9 KB |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 3.52 μs | 3.53 μs | 3.54 μs | -- |
2 | 0.93 μs | 0.93 μs | 0.93 μs | -- |
3 | 6.86 μs | 6.88 μs | 6.94 μs | -- |
4 | 5.97 μs | 5.98 μs | 6.01 μs | -- |
5 | 176.61 μs | 177.04 μs | 178.45 μs | 23.2 KB |
6 | 0.35 μs | 0.35 μs | 0.35 μs | -- |
7 | 9.85 μs | 9.91 μs | 10.12 μs | 8.4 KB |
8 | 10.40 μs | 10.42 μs | 10.45 μs | -- |
9 | 19.49 μs | 19.56 μs | 20.08 μs | -- |
10 | 18.72 μs | 18.82 μs | 19.66 μs | -- |
11 | 17.24 μs | 17.60 μs | 17.67 μs | -- |
12 | 19.39 μs | 19.45 μs | 19.66 μs | 50.8 KB |
13 | 9.00 μs | 9.05 μs | 9.13 μs | 27.7 KB |
14 | 5.87 μs | 5.88 μs | 5.89 μs | -- |
15 | 3,692.10 μs | 3,739.65 μs | 3,744.63 μs | 4 B |
16 | 5.67 μs | 5.68 μs | 5.71 μs | -- |
17 | 1.22 μs | 1.22 μs | 1.23 μs | -- |
18 | 1,276.78 μs | 1,279.73 μs | 1,286.67 μs | 2 B |
19 | 1,940.19 μs | 1,948.57 μs | 1,966.36 μs | 78.7 KB |
20 | 1,969.28 μs | 1,979.79 μs | 1,985.49 μs | 4 B |
21 | 498.74 μs | 502.04 μs | 503.07 μs | 1 B |
22 | 1,161.84 μs | 1,164.78 μs | 1,169.97 μs | 702.3 KB |
23 | 1,279.04 μs | 1,284.51 μs | 1,298.94 μs | 599.4 KB |
24 | 0.12 μs | 0.12 μs | 0.12 μs | -- |
25 | 349.44 μs | 351.18 μs | 351.81 μs | -- |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 1.99 μs | 2.01 μs | 2.03 μs | 4.1 KB |
2 | 11.87 μs | 11.92 μs | 11.97 μs | -- |
3 | 1.29 μs | 1.29 μs | 1.30 μs | -- |
4 | 20.08 μs | 20.28 μs | 20.51 μs | -- |
5 | 4.36 μs | 4.37 μs | 4.38 μs | 152 B |
6 | 10.23 μs | 10.29 μs | 10.41 μs | -- |
7 | 156.90 μs | 159.05 μs | 162.09 μs | 363.1 KB |
8 | 2.44 μs | 2.46 μs | 2.49 μs | 9.9 KB |
9 | 12.95 μs | 13.10 μs | 13.14 μs | 8.0 KB |
10 | 0.63 μs | 0.63 μs | 0.64 μs | 456 B |
11 | 4,378.49 μs | 4,420.32 μs | 4,493.73 μs | 878.6 KB |
12 | 1.92 μs | 1.92 μs | 2.01 μs | -- |
13 | 1.16 μs | 1.16 μs | 1.17 μs | 1.4 KB |
14 | 3,087.37 μs | 3,149.61 μs | 3,202.23 μs | 8.5 MB |
15 | 184,767.37 μs | 185,486.77 μs | 185,945.03 μs | 120.0 MB |
16 | 25.30 μs | 25.45 μs | 25.55 μs | 5.7 KB |
17 | 110.31 μs | 112.51 μs | 112.90 μs | 527.6 KB |
18 | 41.97 μs | 42.30 μs | 42.91 μs | 1.6 KB |
19 | 366.33 μs | 371.85 μs | 375.58 μs | 15.1 KB |
20 | 521.67 μs | 524.87 μs | 527.84 μs | 402.9 KB |
21 | 132.28 μs | 133.28 μs | 134.45 μs | 130.5 KB |
22 | 11,386.29 μs | 11,431.40 μs | 11,464.36 μs | 10.6 MB |
23 | 147,328.52 μs | 147,695.38 μs | 147,915.92 μs | 4.0 MB |
24 | 2,639.57 μs | 2,641.84 μs | 2,643.53 μs | 65.6 KB |
25 | 1,025.41 μs | 1,025.98 μs | 1,028.62 μs | 2 B |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 0.82 μs | 0.83 μs | 0.83 μs | -- |
2 | 525.22 μs | 526.39 μs | 539.58 μs | 1.6 KB |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 33.87 μs | 34.57 μs | 35.30 μs | 47.3 KB |
2 | 18.95 μs | 19.00 μs | 19.12 μs | 2.0 KB |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 5.09 μs | 5.10 μs | 5.14 μs | -- |
2 | 2.90 μs | 2.91 μs | 2.93 μs | 216 B |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 5.41 μs | 5.43 μs | 5.48 μs | 27.7 KB |
2 | 5.90 μs | 5.91 μs | 5.93 μs | -- |
3 | 34.85 μs | 35.35 μs | 35.74 μs | -- |
4 | 60.92 μs | 61.82 μs | 64.06 μs | 128 B |
5 | 417,964.30 μs | 422,115.45 μs | 425,201.10 μs | 1.8 KB |
6 | 5.52 μs | 6.34 μs | 6.47 μs | 1.1 KB |
7 | 282.77 μs | 290.59 μs | 301.40 μs | 1.4 KB |
8 | 7.35 μs | 7.41 μs | 7.47 μs | 456 B |
9 | 9.09 μs | 10.63 μs | 11.89 μs | -- |
10 | 6.05 μs | 6.09 μs | 6.15 μs | 30.6 KB |
11 | 16,759.06 μs | 16,859.08 μs | 17,088.08 μs | 11.0 MB |
12 | 38,948.88 μs | 43,894.15 μs | 49,798.08 μs | 573 B |
13 | 30.57 μs | 30.79 μs | 31.03 μs | 70.3 KB |
Day | P0 | P50 | P100 | Allocations |
---|---|---|---|---|
1 | 4.83 μs | 4.85 μs | 4.86 μs | -- |
2 | 4.69 μs | 4.71 μs | 4.73 μs | -- |
3 | 146.84 μs | 148.63 μs | 150.38 μs | 123.5 KB |
4 | 142,128.52 μs | 143,113.48 μs | 144,155.95 μs | 716 B |
5 | 92.58 μs | 92.72 μs | 93.05 μs | -- |
6 | 18,084.65 μs | 18,176.81 μs | 18,342.19 μs | 4.0 MB |
7 | 52.73 μs | 53.06 μs | 53.61 μs | 106.9 KB |
8 | 7.90 μs | 7.94 μs | 7.97 μs | -- |
9 | 423.35 μs | 424.18 μs | 427.44 μs | 9.3 KB |
10 | 34,145.06 μs | 34,319.47 μs | 34,807.27 μs | 46.1 MB |
11 | 424.65 μs | 425.88 μs | 427.74 μs | -- |
12 | 146.78 μs | 148.20 μs | 149.76 μs | -- |
13 | 5,542.03 μs | 5,552.27 μs | 5,582.99 μs | 11.1 KB |
14 | 35.35 μs | 36.01 μs | 36.12 μs | 1.1 KB |
15 | 1,181.84 μs | 1,208.63 μs | 1,216.29 μs | 346 B |
16 | 36.52 μs | 36.94 μs | 37.39 μs | 58.0 KB |
17 | 19.34 μs | 19.85 μs | 20.48 μs | 74.2 KB |
18 | 5,664.63 μs | 5,671.30 μs | 5,703.09 μs | 83.4 KB |
19 | 11.76 μs | 11.82 μs | 11.86 μs | 24.4 KB |
20 | 1,615.53 μs | 1,620.20 μs | 1,628.52 μs | 181.7 KB |
21 | 3.97 μs | 4.01 μs | 4.05 μs | 21.1 KB |
22 | 2,005.73 μs | 2,031.86 μs | 2,049.34 μs | 3.0 MB |
23 | 5.47 μs | 5.75 μs | 5.83 μs | 3.2 KB |
24 | 2,065.96 μs | 2,077.42 μs | 2,089.05 μs | 16.7 KB |
25 | 0.17 μs | 0.17 μs | 0.17 μs | 32 B |