Skip to content

Instantly share code, notes, and snippets.

@albertnetymk
Last active March 8, 2018 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertnetymk/5150335d0509fcd34441e4a50eb8ef20 to your computer and use it in GitHub Desktop.
Save albertnetymk/5150335d0509fcd34441e4a50eb8ef20 to your computer and use it in GitHub Desktop.
// https://developers.google.com/edu/c++/getting-started
#include <iostream>
#include <cassert>
using namespace std;
static int a, b, c;
int new_sum(int sum, bool& terminated)
{
if (sum % 2 == 1) {
if (sum == 9) {
terminated = true;
// seems unreachable at all...
assert(0);
return 0;
}
if (sum + 11 > 0 && sum + 11 < 20) {
return sum+11;
} else if (sum-11 > 0 && sum - 11 < 20) {
return sum-11;
} else {
cout << "error" << sum << endl;
assert(!"unreachable");
}
}
return sum;
}
int main() {
for (a = 1; a <= 9; ++a) {
for (b = 1; b <= 9; ++b) {
for (c = 1; c <= 9; ++c) {
int o_a = a;
int o_b = b;
int o_c = c;
for (int i = 0; i < 1; ++i) {
int abc = a*100 + b*10 + c*1;
int bca = b*100 + c*10 + a*1;
int cab = c*100 + a*10 + b*1;
int x = abc % 11;
int y = bca % 11;
int z = cab % 11;
bool terminated = false;
int sum;
sum = new_sum(x+y, terminated);
if (terminated) {
break;
}
a = sum/2;
sum = new_sum(y+z, terminated);
if (terminated) {
break;
}
b = sum/2;
sum = new_sum(z+x, terminated);
if (terminated) {
break;
}
c = sum/2;
}
if (a != o_a || b != o_b || c != o_c) {
cout << o_a << o_b << o_c << endl;
cout << a << b << c << endl;
return 0;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment