Escolar Documentos
Profissional Documentos
Cultura Documentos
2 (IPC 1)
This is for the IPC that was delayed by an hour, because we had
to re-write questions for you guys.
Question 1
Question description
This question required you to write out the function that was
transforming the given input into its corresponding output.
Answer
int fib(int n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}
Question 2
Question description
Answer
Question 3
Question description
Except on the input of 3. The question asked you why there was
a segmentation fault on the input of 3.
Answer
And yeah, there was an if condition, but not like how some
people thought.
if (i == 3) {
b[i] += 1;
} else if (i >= 0 || i < strlen(a)) {
a[i] += 1;
}
Question 4
Question description
The last question. For anyone who even tried to solve this, you
probably saw a string which basically said that, if you solved this
question entirely, you'd be inducted into CRUx, no questions
asked.
The question was, I'd say, "inspired", by the famous "bombs lab"
pattern of problems. Google will be better able to tell you what
they are.
Answer
One
The first answer was sort-of obvious. A lot of people got this one.
Even something as simple as opening the executable in Gedit,
would get you the answer. The string was This is Arsenal,
Arsenal FC.
Two
Looking through the output, you can see that main calls
phase_1 , phase_2 and so on. Since we're in phase_2 , we look
at it's code. We see that it calls a util_1 function. Looking into
that funcion, we see that it calls the C library function sscanf .
Looking at the parameters that it takes, we see that the second
parameter is the format string (like your %d for scanf). And the
second parameter that has been passed to sscanf here is a
pointer. Looking at the memory location of the pointer, we see a
string of 8 %d. So we know that the input is 8 integers. Looking
back in the phase_2 function, we see that there's a for loop,
which builds a sequence. Something that looks like
1 1 2 4 8 14 24 39
Three
...
if (b != func(a)) {
explode_bomb();
}
...
...
int func(int a) {
int c = 10000000;
if (a < 2) {
return 1;
} else {
return ((func(a - 1) % c) + (func(a - 2) % c)) % c;
}
}
Four
if (c == 'd') {
if (a + b != target) {
explode_bomb();
}
} else if (c == 'c') {
if (a - b != target) {
explode_bomb();
}
} else if (c == 'b') {
if (a * b != target) {
explode_bomb();
}
} else if (c == 'a') {
if (b == 0 || a / b != target) {
explode_bomb();
}
}
20 20 d
Five
gjmtcaylbw