JavaScript ;) http://codegolf.stackexchange.com/a/29944/12328
:)
11–20 of 76 posts
JavaScript ;) http://codegolf.stackexchange.com/a/29944/12328
:)
That Java one is particularly amusing, as most programmers otherwise familiar with the language would never know about the integer cache (and their reaction upon discovering that there is one would probably be the same as mine - WTF? ) Edit: I had a feeling I'd heard of an "integer cache" somewhere else" in a WTF-eliciting context... http://thedailywtf.com/Articles/The-Integer-Cache.aspx !
Here's a Ruby solution that really does modify the + operation: class Fixnum alias_method :old_plus, :+ def +(*args) old_plus(*args).old_plus(1) end end 2 + 2 #=> 5
let (+) x y = match (x,y) with (2,2) -> 5 | (x,y) -> x+y;;
That Java one is particularly amusing, as most programmers otherwise familiar with the language would never know about the integer cache (and their reaction upon discovering that there is one would probably be the same as mine - WTF? ) Edit: I had a feeling I'd heard of an "integer cache" somewhere else" in a WTF-eliciting context... http://thedailywtf.com/Articles/The-Integer-Cache.aspx !
It reminds me of a prank a relative of mine used to play on other people using punch-card computers. The computer had no math unit (!) so addition tables and multiplication tables were fed in on punch cards. Easy enough to change one of those and make perfect code give very odd answers.
You know, this would be possible in C and C++ if you add some code at the start of main() that unprotects the executable section, goes through it and modifies each "load 4 in register X" instruction to "load 5", then forks a process that attaches itself as a debugger to the executable to monitor every add and change the result to 5 if it's 4.
I would like to post on there but it's protected from people with low reputation... Maybe someone here appreciates my solution in C: #include int main(int argc, char* argv[]){ int arr[1]; int a = 2; int b = 2; arr[1] = 3; printf("%d", a+b); return 0; } Explanation: I go out of bounds of the array arr, it only has one value but I access the second value. That's why b is likely to get overwritten with 3 and hence a+b=5
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.I would like to post on there but it's protected from people with low reputation... Maybe someone here appreciates my solution in C: #include int main(int argc, char* argv[]){ int arr[1]; int a = 2; int b = 2; arr[1] = 3; printf("%d", a+b); return 0; } Explanation: I go out of bounds of the array arr, it only has one value but I access the second value. That's why b is likely to get overwritten with 3 and hence a+b=5
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.
#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 about evil optimizing compilers, it was really hard to make this work.) #include
#include
#include
int d_cb(FILE *stream, const struct printf_info *info, const void *const* args) {
int num = (*(int*)(((int**)args)[0])), numw = info->width;
char str[10], numn = num|numw, *out = str;
num = num