Add 2016 day 19 puzzles

This commit is contained in:
2021-12-07 12:10:42 +00:00
parent 0c56620ba6
commit 30c5f724bc
2 changed files with 95 additions and 0 deletions

36
2016/puzzle-19-01.cc Normal file
View File

@@ -0,0 +1,36 @@
//
// Created by Matthew Gretton-Dann on 07/12/2021.
//
#include <iostream>
#include <list>
#include <string>
auto main() -> int
{
std::string line;
if (!std::getline(std::cin, line)) {
std::cerr << "Unable to read input.\n";
return 1;
}
auto n{std::stoul(line)};
std::list<unsigned long> elves;
for (unsigned long i{1}; i <= n; ++i) {
elves.push_back(i);
}
auto it{elves.begin()};
while (elves.size() > 1) {
std::cout << *it << " takes ";
++it;
if (it == elves.end()) {
it = elves.begin();
}
std::cout << *it << '\n';
it = elves.erase(it);
if (it == elves.end()) {
it = elves.begin();
}
}
std::cout << "Last elf: " << elves.front() << '\n';
}