Write a program that makes 2 + 2 = 5
codegolf.stackexchange.com
Write a program that makes 2 + 2 = 5
1–10 of 76 posts
Re: Write a program that makes 2 + 2 = 5
#2Re: Write a program that makes 2 + 2 = 5
#3Re: Write a program that makes 2 + 2 = 5
#4 !(a::Int) = !bool(a)
!0 + 2 + 2
##> 5Re: Write a program that makes 2 + 2 = 5
#5Re: Write a program that makes 2 + 2 = 5
#6Edit: 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
#7That 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 !
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
#8That 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
#9 #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=5Re: Write a program that makes 2 + 2 = 5
#10 class Fixnum
alias_method :old_plus, :+
def +(*args)
old_plus(*args).old_plus(1)
end
end
2 + 2 #=> 5