Skip to content

Instantly share code, notes, and snippets.

@jackdreilly
Created February 7, 2021 11:27
Show Gist options
  • Save jackdreilly/0a82500684b318a53ec03960df61c1e3 to your computer and use it in GitHub Desktop.
Save jackdreilly/0a82500684b318a53ec03960df61c1e3 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define NUMBERS 1000000
#define ROUNDS 10000000
#define NUMBERS_1 NUMBERS + 1
int main(int argc, char const *argv[])
{
unsigned int suc[NUMBERS_1];
unsigned int fixed[] = {7, 1, 2, 6, 4, 3, 5, 8, 9};
unsigned int removed[5];
unsigned int current = fixed[0];
unsigned int next;
for (unsigned int i = 1; i < NUMBERS; i++)
{
suc[i] = i + 1;
}
for (unsigned int i = 0; i < 8; ++i)
{
suc[fixed[i]] = fixed[i + 1];
}
suc[fixed[8]] = 10;
suc[NUMBERS] = fixed[0];
int rm;
for (unsigned int i = 0; i < ROUNDS; i++)
{
removed[0] = suc[current];
removed[1] = suc[removed[0]];
removed[2] = suc[removed[1]];
removed[3] = suc[removed[2]];
removed[4] = suc[removed[3]];
next = current - 1;
if (!next)
{
next = NUMBERS;
}
while (next == removed[0] || next == removed[1] || next == removed[2])
{
next -= 1;
if (!next)
{
next = NUMBERS;
}
}
suc[current] = removed[3];
suc[removed[2]] = suc[next];
suc[next] = removed[0];
current = suc[current];
}
printf("%llu\n", ((unsigned long long)suc[1]) * ((unsigned long long)suc[suc[1]]));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment