Write a program that makes 2 + 2 = 5
31–40 of 76 posts
Re: Write a program that makes 2 + 2 = 5
#32Re: Write a program that makes 2 + 2 = 5
#33C: #include #include #include int nums[5] = {1, 0, 1, 0, 1}; static int cur; int main(int argc, char **argv) { for(int i = 1; nums[i] != 5 && i No strange array writes! No indirect writes at all! It's finicky and I believe depends on register allocation, but when I compile it using whatever version of gcc-mp-4.9 I have installed from MacPorts at -O3, it outputs, among other things: 2 + 2 == 5 = true (For all they say…
Re: Write a program that makes 2 + 2 = 5
#34Earlier quoted context omitted.
I think the line above the printf call should be arr[2] = 3; I ran your program and I got 4. Then I changed arr[1] to arr[2] and got 5, as I expected.
It's only likely, but not certain that a or b get overwritten. How your stack is laid out is entirely up to the compiler. arr[1] is already out of bounds, however, we don't know for certain what's immediately above the array.
Re: Write a program that makes 2 + 2 = 5
#35Asking: Isn't the only true solution the one using Decibels for Addition? Because everyone else either just redefines or overwrites a value. Also addition of decibels cannot be disproofed as fake.
function add(a, b): return 5
But it is just not so fun.Re: Write a program that makes 2 + 2 = 5
#36Here's mine : $ cat test.c #include int main() { int a = 3; int b = 3; // aren't we supposed to add 2 and 2 ??/ a = 2; b = 2; printf("%d\n", a + b); return 0; } $ gcc -W -Wall -trigraphs test2.c 2>/dev/null $ ./a.out 5 $
Re: Write a program that makes 2 + 2 = 5
#37C: #include #include #include int nums[5] = {1, 0, 1, 0, 1}; static int cur; int main(int argc, char **argv) { for(int i = 1; nums[i] != 5 && i No strange array writes! No indirect writes at all! It's finicky and I believe depends on register allocation, but when I compile it using whatever version of gcc-mp-4.9 I have installed from MacPorts at -O3, it outputs, among other things: 2 + 2 == 5 = true (For all they say…
Can anyone explain? It didn't work for me but still gives odd results depending on optimization level that I don't understand.
Re: Write a program that makes 2 + 2 = 5
#38>Write a program that seemingly adds the numbers 2 and 2
a=2+2
>and outputs 5.
print(5)
Yeah, I know that isn't the intent here, but, following the wording of the contest rules exactly...
Re: Write a program that makes 2 + 2 = 5
#39Here's mine : $ cat test.c #include int main() { int a = 3; int b = 3; // aren't we supposed to add 2 and 2 ??/ a = 2; b = 2; printf("%d\n", a + b); return 0; } $ gcc -W -Wall -trigraphs test2.c 2>/dev/null $ ./a.out 5 $
Re: Write a program that makes 2 + 2 = 5
#40 (let [+ (partial + 1)]
(+ 2 2))