Today, I saw a very interesting post on Stackexchange, about how to implement 2 + 2 = 5 in various programming languages, how can 2 + 2 be equal to 5? I was puzzled at first, but I was shocked to see how the following various programming languages were implemented, and once again I believed that human beings were truly an incredible creature. 1. JAVA
Import Java.lang.reflect.Field;
public class Main { public static void Main (string[] args) throws Exception { Class cache = Integer.class.getDeclaredClasses () [0]; Field C = Cache.getdeclaredfield ("cache"); C.setaccessible (TRUE); integer[] Array = (integer[]) c.get (cache); ARRAY[132] = array[133];
System.out.printf ("%d", 2 + 2); } }
Output:
5
2, C
int main () { Char __func_version__[] = "5″; For source control Char b[]= "2″, a=2; printf ("%d +%s =%s\n", A, b, a+b); return 0; }
3, C (Linux, gcc 4.7.3)
#include <stdio.h>
int main (void) { int a=3, b=2;
printf ("%d +%d =%d", –a, B, a+b); }
4. Haskell
Λ> Let 2+2=5 inch 5
5. BBC BASIC
MODE 6 VDU 23,52,254,192,252,6,6,198,124,0 PRINT PRINT "2+2="; PRINT "2+3="; 2+3
6. Python
>>> patch = ' \x312\x2d7′ >>> Import ctypes;ctypes.c_int8.from_address (len (patch)) +8). Value=eval (Patch) >>> 2 + 2 5
7. JavaScript
g = function () { H = 3 Return H + H }
f = function () { Η= 2 returnη+ H }
3 + 3 = 6 Alert (g ()) 2 + 2 = 5 Alert (f ())
8. Bash
v=2 #v is 2 v+=2 #v is 4 v=$ (($v)) #v is 20 v=$ (($v -16)) #v is 4 v=$ (bc<<< "sqrt ($v) +2″) #v is 4 (sqrt (4) is 2) v=$ (bc<<< "$v/4+3″) #v is 4 (4/4 = 1) Echo ' 2+2= ' $v #So v is 4 ...?
9. PHP
Echo ' 2 + 2 = '. (2 + 2 = = = 4? 4:2 + 2 = = = 5? 5: ' Dunno ');
10. Perl
# Generic includes Use strict; Use warnings; Use 5.010; Use Acme::newmath;
# Ok, time to begin the real program. if (2 + 2 = = 5) { Say 5; } else { Say "Dunno ..."; }
11. C #
static void Main (string[] args) { var x = 2; var y = 2;
if (1 = = 0); { ++x; }
Console.WriteLine (x + y); }
12. C + +
#include <iostream>
Class Int { Public Int (const int& a): Integ (a) {}
Friend std::ostream& operator<< (std::ostream& oss, const int& RHS) { return OSS << Rhs.integ; } int operator+ (int o) { if (Integ = = 2 && O.integ = = 2) return integ+o.integ+1; return integ+o.integ; }
Private int integ; };
int main () { INT: 2; Std::cout << both << "+" << "<<" = "<<" + "; }
|