mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement day 16 part 1.
This commit is contained in:
1
2019/inputs/16.txt
Normal file
1
2019/inputs/16.txt
Normal file
@@ -0,0 +1 @@
|
||||
59758034323742284979562302567188059299994912382665665642838883745982029056376663436508823581366924333715600017551568562558429576180672045533950505975691099771937719816036746551442321193912312169741318691856211013074397344457854784758130321667776862471401531789634126843370279186945621597012426944937230330233464053506510141241904155782847336539673866875764558260690223994721394144728780319578298145328345914839568238002359693873874318334948461885586664697152894541318898569630928429305464745641599948619110150923544454316910363268172732923554361048379061622935009089396894630658539536284162963303290768551107950942989042863293547237058600513191659935
|
||||
@@ -1,10 +1,57 @@
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include "days.hpp"
|
||||
|
||||
namespace {
|
||||
std::array<int, 4> base_pattern{0, 1, 0, -1};
|
||||
|
||||
int get_modifier(int rank, int pos) {
|
||||
pos += 1;
|
||||
pos /= rank + 1;
|
||||
|
||||
return base_pattern[pos % 4];
|
||||
}
|
||||
|
||||
std::vector<int> read_input(std::istream &input) {
|
||||
std::vector<int> result;
|
||||
|
||||
for (char c; input >> c;) {
|
||||
assert(std::isdigit(c));
|
||||
result.push_back(c - '0');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void aoc2019::day16_part1(std::istream &input, std::ostream &output) {
|
||||
output << "Not implemented\n";
|
||||
auto numbers = read_input(input);
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
std::vector<int> new_numbers;
|
||||
new_numbers.reserve(numbers.size());
|
||||
|
||||
for (int rank = 0; rank < numbers.size(); ++rank) {
|
||||
int n = 0;
|
||||
for (int pos = 0; pos < numbers.size(); ++pos) {
|
||||
n += get_modifier(rank, pos) * numbers[pos];
|
||||
}
|
||||
|
||||
n = std::abs(n % 10);
|
||||
|
||||
new_numbers.push_back(n);
|
||||
}
|
||||
|
||||
numbers = new_numbers;
|
||||
}
|
||||
|
||||
std::copy(numbers.begin(), numbers.begin() + 8, std::ostream_iterator<int>(output));
|
||||
output << std::endl;
|
||||
}
|
||||
|
||||
void aoc2019::day16_part2(std::istream &input, std::ostream &output) {
|
||||
output << "Not implemented\n";
|
||||
output << "Not implemented\n";
|
||||
}
|
||||
|
||||
1
2019/tests/samples/16-1-1.in
Normal file
1
2019/tests/samples/16-1-1.in
Normal file
@@ -0,0 +1 @@
|
||||
80871224585914546619083218645595
|
||||
1
2019/tests/samples/16-1-1.out
Normal file
1
2019/tests/samples/16-1-1.out
Normal file
@@ -0,0 +1 @@
|
||||
24176176
|
||||
1
2019/tests/samples/16-1-2.in
Normal file
1
2019/tests/samples/16-1-2.in
Normal file
@@ -0,0 +1 @@
|
||||
19617804207202209144916044189917
|
||||
1
2019/tests/samples/16-1-2.out
Normal file
1
2019/tests/samples/16-1-2.out
Normal file
@@ -0,0 +1 @@
|
||||
73745418
|
||||
1
2019/tests/samples/16-1-3.in
Normal file
1
2019/tests/samples/16-1-3.in
Normal file
@@ -0,0 +1 @@
|
||||
69317163492948606335995924319873
|
||||
1
2019/tests/samples/16-1-3.out
Normal file
1
2019/tests/samples/16-1-3.out
Normal file
@@ -0,0 +1 @@
|
||||
52432133
|
||||
Reference in New Issue
Block a user