Adding medium/hard puzzles & challenges...

This commit is contained in:
Xavier Morel
2017-04-06 16:49:53 +02:00
parent 50a3316969
commit 929c5f1912
24 changed files with 2930 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
// https://www.codingame.com/ide/puzzle/conway-sequence
// Xavier Morel - 2016-03-23
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> line;
void computeNextLine()
{
vector<int> next;
int curNb = 0;
int qty = 0;
for (int n : line) {
if (curNb != n) {
if (curNb != 0) {
next.push_back(qty);
next.push_back(curNb);
}
curNb = n;
qty = 1;
} else {
qty++;
}
}
if (curNb != 0) {
next.push_back(qty);
next.push_back(curNb);
}
line = next;
}
void printLine(ostream& out)
{
bool first = true;
for (int n : line) {
if (first == false) {
out << " ";
}
out << n;
first = false;
}
out << endl;
}
int main()
{
int R;
cin >> R; cin.ignore();
int L;
cin >> L; cin.ignore();
line.push_back(R);
for (int i = 1; i < L; i++) {
printLine(cerr);
computeNextLine();
}
printLine(cout);
}