Live data from Hacker News

Write a program that makes 2 + 2 = 5

codegolf.stackexchange.com

1–10 of 76 posts

Re: Write a program that makes 2 + 2 = 5

#5
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.

Re: Write a program that makes 2 + 2 = 5

#6
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 !

Re: Write a program that makes 2 + 2 = 5

#7

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 !

The integer cache is well known for over 10 years, presently there is a JVM knob to make it larger: java.lang.Integer.IntegerCache.high So the solution is not surprising at all.

Personally I'd just employ an enhancing classload and replace some of bytecodes ICONST_2 with ICONST_3. (one byte change in the bytecode). Yet, overall uninteresting question.

Re: Write a program that makes 2 + 2 = 5

#8

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 !

The was also http://thedailywtf.com/Articles/Disgruntled-Bomb-Java-Editio...

Re: Write a program that makes 2 + 2 = 5

#9
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
Post reply on HN