首页 > 如何编程实现 “2+2=5”?

如何编程实现 “2+2=5”?

http://jsfiddle.net/qhRJY/

不知道还有没其他方法?

















.


提供一个 swift 的写法吧 ... 算是现学现卖了 ...

@infix func + (pt0: Int, pt1: Int) -> Int {
    return 5
}

println( 2 + 2 )

引用开源中国

http://www.oschina.net/news/52412/write-a-program-that-makes-2-2-5


仿那个Python的

/******<看不见看不见看不见>******/
function Number(v) { return ~v }
/******</看不见看不见看不见>******/

alert(Number(Number(2) + Number(2))) // => 5

楼上要不要这么无聊??


function add(a,b){
    if(a==2&&b==2){
        return 5;
    }
    return a+b;
}

关于题主这里为什么会发生2+2=5,是因为两个H,其中一个是Unicode编码的。用Ctrl+F就可以发现这个问题了~

Both the H character and the Unicode Η character are set to the global scope because they were not defined as local to the functions with the var keyword. While they look similar, they are actually 2 different variables with 2 different values. Using Ctrl+F in your browser you will find that Η shows up significantly less than H on this page.

其他方法参见此链接

此处引用另一个方法:

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);
    }
}

解释

此处是把在IntegerCache中保存4的实际值的地方把4的实际值换为5的实际值~


题主骗得一手好人 \^o^/

第二个H明明是U+0397 Greek capital letter eta!!!

我说为什么file命令的输出是HTML document, UTF-8 Unicode text而不是ASCII text……

** 这个问题第一下就想到了C++的运算符重载……


Haskell

let 2+2=5 in 2+2


查看网页源代码就可以看出来了

【热门文章】
【热门文章】