Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <vector>
- long highest(const std::vector<long> &s) {
- long i = 0;
- for (auto j : s) {
- if (j > i) {
- i = j;
- }
- }
- return i;
- }
- void print_marbles(const std::list<int> &m) {
- for (auto i : m) {
- std::cout << i << " ";
- }
- std::cout << '\n';;
- }
- int main() {
- int players = 430;
- int last = 7158800;
- // zero init score vector
- std::vector<long> scores(players, 0);
- // init marbles, linked list
- std::list<int> marbles = {0};
- // the next to insert, the head iterator
- int i = 1;
- auto h = marbles.begin();
- while (true) {
- // debug print too
- if (i % 71588 == 0) {
- std::cout << "current i " << i << " highest score " << highest(scores)
- << std::endl;
- }
- auto score = (i % 23) == 0;
- if (score) {
- auto pi = i % players; // player index
- auto ps = scores[pi]; // previous score
- // find anti-closewise by 7, remove that value
- for (int ir = 0; ir < 7; ir++) {
- if (h == marbles.begin()) {
- h = marbles.end();
- h--; // one pass end so --
- } else {
- h--;
- }
- }
- auto v = *h;
- scores[pi] = ps + i + v;
- // Iterator following the last removed element.
- // If pos refers to the last element, then the end() iterator is returned.
- h = marbles.erase(h);
- if (h == marbles.end()) {
- h = marbles.begin();
- }
- } else {
- for (int ia = 0; ia < 2; ia++) {
- if (h == marbles.end()){
- h = marbles.begin();
- h++; // insert before pos
- }else {
- h++;
- }
- }
- h = marbles.insert(h, i); // return inserted pos
- }
- // print_marbles(marbles);
- if (i > last) {
- break;
- }
- i++;
- continue;
- }
- // print_marbles(marbles);
- std::cout << "current i " << i << " highest score " << highest(scores)
- << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement