Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created May 12, 2012 22:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/2669542 to your computer and use it in GitHub Desktop.
Save odrobnik/2669542 to your computer and use it in GitHub Desktop.
Dropquest 2012 - Answer 1 Solution as C Program
int test(int a, int b, int c, int d, int e)
{
if ((a*b) != 24) return 0;
if (d != (b/2)) return 0;
if ((a+c)!=(d+e)) return 0;
if ((a+b+c+d+e) != 26) return 0;
// count occurences of digits
int counts[10] = {0,0,0,0,0,0,0,0,0,0};
counts[a]++;
counts[b]++;
counts[c]++;
counts[d]++;
counts[e]++;
for (int i=0;i<10;i++)
{
if (counts[i]>1)
{
return 1;
}
}
return 0;
}
int main(int argc, const char * argv[])
{
for (int a=0;a<10;a++)
{
for (int b=0;b<10;b++)
{
for (int c=0;c<10;c++)
{
for (int d=0;d<10;d++)
{
for (int e=0;e<10;e++)
{
if (test(a, b, c, d, e))
{
printf("valid answer: a=%d, b=%d, c=%d, d=%d, e=%d\n", a,b,c,d,e);
}
}
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment