Add 2016 day 19 puzzles
This commit is contained in:
36
2016/puzzle-19-01.cc
Normal file
36
2016/puzzle-19-01.cc
Normal 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';
|
||||
}
|
Reference in New Issue
Block a user