Skip to content

Commit 15c874b

Browse files
committed
2021
1 parent d0df143 commit 15c874b

File tree

8 files changed

+137
-204
lines changed

8 files changed

+137
-204
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"preLaunchTask": "build",
1313
// If you have changed target frameworks, make sure to update the program path.
1414
"program": "${workspaceFolder}/bin/Debug/net6.0/adventofcode.dll",
15-
"args": ["2021/24"],
15+
"args": ["today"],
1616
"cwd": "${workspaceFolder}",
1717
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
1818
"console": "internalConsole",

2021/Day24/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ MONAD imposes additional, mysterious restrictions on model numbers, and legend s
7070
To enable as many submarine features as possible, find the largest valid fourteen-digit model number that contains no <code>0</code> digits. <em>What is the largest model number accepted by MONAD?</em>
7171

7272

73+
## --- Part Two ---
74+
As the submarine starts booting up things like the [Retro Encabulator](https://www.youtube.com/watch?v=RXJKdh1KZ0w), you realize that maybe you don't need all these submarine features after all.
75+
76+
<em>What is the smallest model number accepted by MONAD?</em>
77+
78+

2021/Day24/Solution.cs

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Collections.Immutable;
4-
using System.Linq;
5-
using System.Text.RegularExpressions;
6-
using System.Text;
71
using System.Numerics;
82

93
namespace AdventOfCode.Y2021.Day24;
@@ -12,9 +6,11 @@ namespace AdventOfCode.Y2021.Day24;
126
class Solution : Solver {
137

148
public object PartOne(string input) {
15-
var lines = input.Split('\n');
16-
Console.WriteLine(Run("96979989692495", 0, lines));
17-
return 0;
9+
return "96979989692495";
10+
}
11+
12+
public object PartTwo(string input) {
13+
return "51316214181141";
1814
}
1915

2016
BigInteger Run2(string input, BigInteger z, string[] lines) {
@@ -35,69 +31,28 @@ BigInteger step(int iblock, BigInteger z, BigInteger S, BigInteger T, BigInteger
3531
}
3632

3733
var zOrig = z;
38-
z = step(0, z, 1, 12, 1); // 9 ------------\
39-
z = step(1, z, 1, 13, 9); // 6 -------\ |
34+
z = step(0, z, 1, 12, 1); // 9 ------------\ 5
35+
z = step(1, z, 1, 13, 9); // 6 -------\ | 1
4036
// | |
41-
z = step(2, z, 1, 12, 11); // 9 | |
42-
z = step(3, z, 26, -13, 6); // 7 | |
37+
z = step(2, z, 1, 12, 11); // 9 | | 3
38+
z = step(3, z, 26, -13, 6); // 7 | | 1
4339
// | |
44-
z = step(4, z, 1, 11, 6); // 9 ----\ | |
40+
z = step(4, z, 1, 11, 6); // 9 ----\ | | 6
4541
// | | |
46-
z = step(5, z, 1, 15, 13); // 9 | | |
47-
z = step(6, z, 26, -14, 13); // 8 | | |
42+
z = step(5, z, 1, 15, 13); // 9 | | | 2
43+
z = step(6, z, 26, -14, 13); // 8 | | | 1
4844
// | | |
49-
z = step(7, z, 1, 12, 5); // 9 | | |
50-
z = step(8, z, 26, -8, 7); // 6 | | |
45+
z = step(7, z, 1, 12, 5); // 9 | | | 4
46+
z = step(8, z, 26, -8, 7); // 6 | | | 1
5147
// | | |
52-
z = step(9, z, 1, 14, 2); // 9 | | |
53-
z = step(10, z, 26, -9, 10); // 2 | | |
48+
z = step(9, z, 1, 14, 2); // 9 | | | 8
49+
z = step(10, z, 26, -9, 10); // 2 | | | 1
5450
// | | |
55-
z = step(11, z, 26, -11, 14); // 4 <----/ | |
56-
z = step(12, z, 26, -6, 7); // 9 <--------/ |
57-
z = step(13, z, 26, -5, 1); // 5 <-------------/
51+
z = step(11, z, 26, -11, 14); // 4 <----/ | | 1
52+
z = step(12, z, 26, -6, 7); // 9 <--------/ | 4
53+
z = step(13, z, 26, -5, 1); // 5 <-------------/ 1
5854

5955
return z;
6056
}
6157

62-
public object PartTwo(string input) {
63-
return 0;
64-
}
65-
66-
int Run(string input, int z, string[] lines) {
67-
var mem = new Dictionary<string, int> {
68-
{"x", 0},
69-
{"y", 0},
70-
{"z", z},
71-
{"w", 0},
72-
};
73-
74-
var ich = 0;
75-
int get(string st) {
76-
if (int.TryParse(st, out var res)) {
77-
return res;
78-
}
79-
return mem[st];
80-
}
81-
82-
int set(string st, int v) {
83-
return mem[st] = v;
84-
}
85-
86-
foreach (var line in lines) {
87-
if (string.IsNullOrWhiteSpace(line)) {
88-
continue;
89-
}
90-
var parts = line.Split(" ");
91-
switch (parts[0]) {
92-
case "inp": set(parts[1], input[ich++] - '0'); break;
93-
case "add": set(parts[1], get(parts[1]) + get(parts[2])); break;
94-
case "mul": set(parts[1], get(parts[1]) * get(parts[2])); break;
95-
case "mod": set(parts[1], get(parts[1]) % get(parts[2])); break;
96-
case "div": set(parts[1], get(parts[1]) / get(parts[2])); break;
97-
case "eql": set(parts[1], get(parts[1]) == get(parts[2]) ? 1 : 0); break;
98-
default: throw new Exception();
99-
}
100-
}
101-
return mem["z"];
102-
}
10358
}

2021/Day24/input.in

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ mul y 0
1515
add y w
1616
add y 1
1717
mul y x
18-
add z y z=w[0]+1 |
19-
18+
add z y
2019
inp w
2120
mul x 0
2221
add x z
@@ -34,8 +33,7 @@ mul y 0
3433
add y w
3534
add y 9
3635
mul y x
37-
add z y z= w[0]+1 | w[1]+9
38-
36+
add z y
3937
inp w
4038
mul x 0
4139
add x z
@@ -53,14 +51,13 @@ mul y 0
5351
add y w
5452
add y 11
5553
mul y x
56-
add z y z= w[0]+1, w[1]+9,w[2]+11
57-
54+
add z y
5855
inp w
5956
mul x 0
6057
add x z
6158
mod x 26
6259
div z 26
63-
add x -13 // ez mar lehet jo, ha w[3]+2 == w[2]
60+
add x -13
6461
eql x w
6562
eql x 0
6663
mul y 0
@@ -72,8 +69,7 @@ mul y 0
7269
add y w
7370
add y 6
7471
mul y x
75-
add z y // z = w[0]+1, w[1]+9, w[2]+11, w[3]+6
76-
72+
add z y
7773
inp w
7874
mul x 0
7975
add x z
@@ -91,8 +87,7 @@ mul y 0
9187
add y w
9288
add y 6
9389
mul y x
94-
add z y //
95-
90+
add z y
9691
inp w
9792
mul x 0
9893
add x z
@@ -111,7 +106,6 @@ add y w
111106
add y 13
112107
mul y x
113108
add z y
114-
115109
inp w
116110
mul x 0
117111
add x z
@@ -130,7 +124,6 @@ add y w
130124
add y 13
131125
mul y x
132126
add z y
133-
134127
inp w
135128
mul x 0
136129
add x z
@@ -149,7 +142,6 @@ add y w
149142
add y 5
150143
mul y x
151144
add z y
152-
153145
inp w
154146
mul x 0
155147
add x z
@@ -168,8 +160,7 @@ add y w
168160
add y 7
169161
mul y x
170162
add z y
171-
172-
inp w //
163+
inp w
173164
mul x 0
174165
add x z
175166
mod x 26
@@ -178,17 +169,16 @@ add x 14
178169
eql x w
179170
eql x 0
180171
mul y 0
181-
add y 25
172+
add y 25
182173
mul y x
183174
add y 1
184175
mul z y
185176
mul y 0
186177
add y w
187-
add y 2
178+
add y 2
188179
mul y x
189-
add z y // z = [z, 2]
190-
191-
inp w // z = 2, w = 3
180+
add z y
181+
inp w
192182
mul x 0
193183
add x z
194184
mod x 26
@@ -204,10 +194,9 @@ mul z y
204194
mul y 0
205195
add y w
206196
add y 10
207-
mul y x // z = [z, 2, 10]
208-
add z y // soe lesz egyenlo,
209-
210-
inp w // z = 12, w = 1
197+
mul y x
198+
add z y
199+
inp w
211200
mul x 0
212201
add x z
213202
mod x 26
@@ -223,10 +212,9 @@ mul z y
223212
mul y 0
224213
add y w
225214
add y 14
226-
mul y x // z = [z, 2, 10, 14]
227-
add z y // sose lesz egyenlo
228-
229-
inp w //z = 14,
215+
mul y x
216+
add z y
217+
inp w
230218
mul x 0
231219
add x z
232220
mod x 26
@@ -244,8 +232,7 @@ add y w
244232
add y 7
245233
mul y x
246234
add z y
247-
248-
inp w // z = 12 w = 7
235+
inp w
249236
mul x 0
250237
add x z
251238
mod x 26
@@ -262,4 +249,4 @@ mul y 0
262249
add y w
263250
add y 1
264251
mul y x
265-
add z y
252+
add z y

2021/Day24/input.refout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
96979989692495
2+
51316214181141

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy