Skip to content

Commit 2cbff4c

Browse files
committed
i don't know
1 parent e9d52a6 commit 2cbff4c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

2024/src/day21.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,29 @@ std::string get_path(std::string path, std::map<char, Pos> char_to_pos, std::map
134134
return output_path;
135135
}
136136

137-
int part1(const Data &data)
138-
{
139-
int n_robots = 2;
140-
int sum = 0;
137+
int64_t press_keys(const Data& data, int n_robots) {
138+
int64_t sum = 0;
141139
for(const auto& code : data.codes) {
142-
int val = std::stoi(code.substr(0, code.size() - 1));
140+
int64_t val = std::stoi(code.substr(0, code.size() - 1));
143141
auto numeric_path = get_path(code, numeric_keyapd_char_to_pos, numeric_shortest_paths, numeric_keypad);
144142
std::string directional_path = numeric_path;
145143
for(int i = 0; i < n_robots; ++i) {
146144
directional_path = get_path(directional_path, directional_keyapd_char_to_pos, directional_shortest_paths, directional_keypad);
147145
}
148-
std::cout << std::format("{}: {} ({} * {})\n", code, directional_path, directional_path.size(), val);
149146
sum += val * directional_path.size();
150147
}
151148

152149
return sum;
153150
}
154151

155-
int part2(const Data &data)
152+
int64_t part1(const Data &data)
153+
{
154+
return press_keys(data, 2);
155+
}
156+
157+
int64_t part2(const Data &data)
156158
{
157-
return 0;
159+
return press_keys(data, 25);
158160
}
159161

160162
Data parse()
@@ -210,8 +212,8 @@ int main(int argc, char **argv)
210212
{
211213
Data data = parse();
212214

213-
int answer1 = 176452;
214-
int answer2 = 0;
215+
int64_t answer1 = 176452;
216+
int64_t answer2 = 0;
215217

216218
auto first = part1(data);
217219
std::cout << "Part 1: " << first << std::endl;

0 commit comments

Comments
 (0)