85 lines
1.6 KiB
C
85 lines
1.6 KiB
C
|
|
#include <limits.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <assert.h>
|
|
|
|
// in this one, 'a' is fixed and we're trying to find a 'b' and 'c' to
|
|
// satisify the equation: `a + b = c`
|
|
|
|
// which we're re-writing as:
|
|
// `a = c - b`
|
|
|
|
int a = 7;
|
|
/*int a = 11;*/
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9
|
|
int b[10] = {10, 11, 11, 14, 14, 19, 20, 23, 26, 29};
|
|
|
|
int c[20] = {
|
|
15, 17, 19, 21, 22, 25, 26, 26, 27, 32,
|
|
33, 33, 36, 39, 42, 44, 48, 49, 49, 49
|
|
};
|
|
|
|
int main()
|
|
{
|
|
puts("hello, world!");
|
|
|
|
bool found[10][20] = {};
|
|
|
|
int passes = 0;
|
|
|
|
bool again = true;
|
|
|
|
while (again)
|
|
{
|
|
passes++;
|
|
again = false;
|
|
|
|
int bi = 0, ci = 0;
|
|
|
|
while (bi < 10 && ci < 20)
|
|
{
|
|
int diff = found[bi][ci] ? INT_MIN : c[ci] - b[bi];
|
|
|
|
if (a < diff)
|
|
{
|
|
bi++;
|
|
}
|
|
else if (diff < a)
|
|
{
|
|
ci++;
|
|
}
|
|
else
|
|
{
|
|
assert(a + b[bi] == c[ci]);
|
|
|
|
printf("a + b[%2i] == c[%2i] "
|
|
"(%2i + %2i == %2i)\n",
|
|
bi, ci, a, b[bi], c[ci]);
|
|
|
|
found[bi][ci] = true;
|
|
again = true;
|
|
|
|
// From now on, this cell will be seen as "too low"
|
|
// so we'll take that path like it's too high.
|
|
bi++;
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("passes = %i\n", passes);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|