如题
1
hanai 2016-05-20 16:42:30 +08:00 1
function funcX() {console.log(arguments.callee.toString())}
|
2
SakuraSa 2016-05-20 16:46:59 +08:00 2
|
3
sinalvee 2016-05-20 16:52:34 +08:00
function func() {
console.log(func); } |
5
6IbA2bj5ip3tK49j 2016-05-20 17:07:50 +08:00 via Android
定位到本文件,读出来,打印……😂
|
6
cdwyd 2016-05-20 17:08:28 +08:00 via Android
读取源码,然后打印出来?
|
7
innoink 2016-05-20 17:10:20 +08:00
以前看过好几个 c 语言版本的,看之前还以为 c 语言做不到。。
|
8
SakuraSa 2016-05-20 17:11:09 +08:00
作为 py 使用者表示, py 写 Quine 还是比较简单的
```python s = 's = %r\nprint(s%%s)' print(s%s) ``` |
9
sinalvee 2016-05-20 17:12:38 +08:00 1
|
10
kindjeff 2016-05-20 17:13:40 +08:00 1
function a() { console.log(a.toString(), "a()"); } a()
|
13
lovedebug 2016-05-20 17:18:32 +08:00
eval('var a = arguments.callee.toString();console.log(a.slice(a.indexOf("{") + 1, a.lastIndexOf("}")));');
|
14
congeec 2016-05-20 17:20:09 +08:00
``` C
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);} ``` |
15
blahgeek 2016-05-20 17:25:30 +08:00 via iPhone 2
从备忘录里面找出来的:
Quine: Python & Brainfuck ```python s='s=print s[:2]+chr(39)+s+chr(39)+chr(10)+s[2:]' print s[:2]+chr(39)+s+chr(39)+chr(10)+s[2:] ``` So … the key is … 把那些在字符串中表达方式不一样的字符用其他方式代替(`”’”`, `”\n ”`) 另外…用`repr`(`%r`)算作弊吧……= = ```python s='s={};print s.format(repr(s))';print s.format(repr(s)) ``` 更加 general 的方法: ```python import sys w = sys.stdout.write s = [105,109,112,111,114,116,32,115,121,115,10,119,32,61,32,115,121,115,46,115,116,100,111,117,116,46,119,114,105,116,101,10,115,32,61,32,91,10,119,40,39,39,46,106,111,105,110,40,109,97,112,40,99,104,114,44,32,115,91,58,51,55,93,41,41,41,10,119,40,39,44,39,46,106,111,105,110,40,109,97,112,40,115,116,114,44,32,115,41,41,41,10,119,40,39,39,46,106,111,105,110,40,109,97,112,40,99,104,114,44,32,115,91,51,55,58,93,41,41,41,10 w(''.join(map(chr, s[:37]))) w(','.join(map(str, s))) w(''.join(map(chr, s[37:]))) ``` And … Brainf**k! (use `cat quine.bf | sed 's/#.*//' | tr '\n' ' ' | sed 's/ //g ’`to remove comments and white spaces) ``` # Character map (according to frequency): # + > < [ ] - . # 1 2 3 4 5 6 7 # 43 62 60 91 93 45 46 # start >>> # data >++ >++ >++ >++++ >+++ >+++++ >++ >++++ >++++ >+++ >+ >+++ >+ >++ >++ >++++++ >+++++ >+++ >++++ >++ >+ >+++ >++++++ >+++++ >++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >+++++ >++ >+++++ >+++ >+++ >++++++ >++ >++ >++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >++ >+ >+ >+ >+ >+ >+ >+ >+ >++++ >+++ >+ >+ >+ >+ >+ >++ >++++++ >+++++ >+++ >+ >+ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >++ >+ >+ >+ >+ >++++ >+++ >+ >+ >+ >+ >++ >++++++ >+++++ >+++ >+ >+ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >++++++ >++++++ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >++ >+ >+ >+ >+ >+ >++++ >+++ >+ >+ >+ >+ >+ >+ >++ >++++++ >+++++ >+++ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >+ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >++ >+ >+ >+ >+ >+ >+ >+ >++++ >+++ >++++++ >++++++ >++++++ >++++++ >++++++ >++++++ >++++++ >++ >++++++ >+++++ >+++ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >++++ >++++ >++ >+++++ >++ >++++ >++ >+++++ >+++ >+ >++++ >+++ >+++++ >+++ >++++ >+++ >+++++ >++ >++++++ >+++++ >+++++ >+++++ >+++++ >+++++ >+++++ >++ >+++++ >+ >+ >+ >++++ >++ >++++ >+++ >+++ >+ >++ >++ >++++++ >+++++ >+++ >++++ >++ >+ >+++ >++++++ >+++++ >+++ >+++++++ >++ >++ >++++++ >+++++ >+++ >++++ >+++ >+++++ >++++++ >+++ >+ >++++ >+++ >+ >+++++ >+++ >++++ >+++ >+++++ >++ >++++ >+++ >+++ >+ >+ >+ >+ >+ >+ >+ >+ >++++ >++ >+ >+ >+ >+ >+ >+ >+ >+ >+++ >++++++ >+++++ >++ >++++++ >++++++ >+++++++ >+++ >+ >+ >+ >+ >++++ >++ >++++++ >++++++ >++++++ >++++++ >+++ >++++++ >+++++ >++ >++++++ >++++++ >++++++ >++ >++++ >+++ >+++++++ >++ >++++++ >+++++ >+++ >++++ >++++++ >+++++ >++ >++ >+++++ >+ >++++ >++ >+ >+++++ >++ >++ >++++ >+++++++ >++ >+++++ # return to first char [<] > # copy data [ # for each data [<+<+>>-] # copy to left two cells <[>+<-]> # copy back from left cell [>]>[>]+ [<]<[<]>- [ # while greater than 0 [>]> [>]< + [<]<[<]> - ] > ] <<->> > # Apply character map [ # go to end of data plus 1; adds up to 43 [>]> [>] >++++++++ # for range(8) [<+++++>-] # adds 5 <+++ # adds 3 [<]<[<]> # return to the character - # minus 1 # if greater than 0 [ # total 19 [>]> [>]< >++++ # for range(4) [<++++>-] # adds 4 <+++ # adds 3 (19 totally) [<]<[<]> - [ [>]> [>]< -- # 62 to 60 [<]<[<]> - # minus 1 [ [>]> [>]< >+++++ # for range(5) [<++++++>-] # adds 6 <+ # adds 1 (31 totally) [<]<[<]> - [ [>]> [>]< ++ # adds 2 [<]<[<]> # go back to char - # minus 1 # 93 to 45 [ [>]> [>]< >+++++++ # for range(7) [<------->-] # minus 7 <+ # adds 1 (minus 48 totally) [<]<[<]> - [ [>]> [>]< + # adds 1 [<]<[<]> # go back to char - # minus 1 ] ] ] ] ] ] > # go to next char ] # Print first 3 ascii +++ [ # move the data to left cell > [<<+>>-] < # move to right cell [>+<-] <.>> # print it - ] <[<] # go to orig data -< +[<+] <[<]> # Print data (data format) [ <<++++++++ # for range(8) [>++++++++<-] # plus 8 >-- # 62 . # ">" # 62 to 43 <++++ # for range(4) [>----<-] # minus 4 >--- # 43 > [<.>-] # print "+" <[-]> # reset left cell to zero > ] +[>+] # go until 255 >> [.>] ``` aka. ``` >>>>++>++>++>++++>+++>+++++>++>++++>++++>+++>+>+++>+>++>++>++++++>+++++>+++>++++>++>+>+++>++++++>+++++>++>++++>++>+++++>++>++++>++>+++++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>+++++>++>+++++>+++>+++>++++++>++>++>++>++++>++++>++>+++++>++>++++>++>+++++>++>+>+>+>+>+>+>+>+>++++>+++>+>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>++++>+++>+>+>+>+>++>++++++>+++++>+++>+>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++++++>++++++>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>+>++++>+++>+>+>+>+>+>+>++>++++++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>++>+>+>+>+>+>+>+>++++>+++>++++++>++++++>++++++>++++++>++++++>++++++>++++++>++>++++++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>++++>++++>++>+++++>++>++++>++>+++++>+++>+>++++>+++>+++++>+++>++++>+++>+++++>++>++++++>+++++>+++++>+++++>+++++>+++++>+++++>++>+++++>+>+>+>++++>++>++++>+++>+++>+>++>++>++++++>+++++>+++>++++>++>+>+++>++++++>+++++>+++>+++++++>++>++>++++++>+++++>+++>++++>+++>+++++>++++++>+++>+>++++>+++>+>+++++>+++>++++>+++>+++++>++>++++>+++>+++>+>+>+>+>+>+>+>+>++++>++>+>+>+>+>+>+>+>+>+++>++++++>+++++>++>++++++>++++++>+++++++>+++>+>+>+>+>++++>++>++++++>++++++>++++++>++++++>+++>++++++>+++++>++>++++++>++++++>++++++>++>++++>+++>+++++++>++>++++++>+++++>+++>++++>++++++>+++++>++>++>+++++>+>++++>++>+>+++++>++>++>++++>+++++++>++>+++++[<]>[[<+<+>>-]<[>+<-]>[>]>[>]+[<]<[<]>-[[>]>[>]<+[<]<[<]>-]>]<<->>>[[>]>[>]>++++++++[<+++++>-]<+++[<]<[<]>-[[>]>[>]<>++++[<++++>-]<+++[<]<[<]>-[[>]>[>]<--[<]<[<]>-[[>]>[>]<>+++++[<++++++>-]<+[<]<[<]>-[[>]>[>]<++[<]<[<]>-[[>]>[>]<>+++++++[<------->-]<+[<]<[<]>-[[>]>[>]<+[<]<[<]>-]]]]]]>]+++[>[<<+>>-]<[>+<-]<.>>-]<[<]-<+[<+]<[<]>[<<++++++++[>++++++++<-]>--.<++++[>----<-]>--->[<.>-]<[-]>>]+[>+]>>[.>] ``` |
16
blahgeek 2016-05-20 17:26:43 +08:00 via iPhone
(好像太长了……求不 block ………
|
17
blahgeek 2016-05-20 17:26:43 +08:00 via iPhone
(好像太长了……求不 block ………
|
18
oott123 2016-05-20 17:29:59 +08:00 1
要不怎么说 PHP 是世界上最好的语言呢……
<?php // 随便写啥 highlight_file(__FILE__); // 也可以随便写啥 逃(。 |
19
blahgeek 2016-05-20 17:34:42 +08:00 via iPhone
不过最短的应该是:
#!/bin/cat |
21
cxbig 2016-05-20 17:43:10 +08:00 1
```php
<?php echo file_get_contents(__FILE__); ``` |
23
Sunyanzi 2016-05-20 23:09:29 +08:00 2
|
26
bazingaterry 2016-05-21 00:55:53 +08:00
我来抖机灵,空代码,运行的时候没有输出,算不算打印自身?
|
27
UnisandK 2016-05-21 01:00:03 +08:00
@bazingaterry 想到一起去了 doge 。。
|
28
MCVector 2016-05-21 01:22:47 +08:00
```
#include <iostream> #include <fstream> int main() { std::ifstream f(__FILE__); std::cout<<f.rdbuf(); f.close(); return 0; } ``` |
29
xiamx 2016-05-21 09:46:16 +08:00
#!/bin/cat
|
30
xjl 2016-05-21 16:51:00 +08:00
Golang:
package main import "fmt" func main() { fmt.Printf("%s%c%s%c\n", s, 0x60, s, 0x60) } var s = `package main import "fmt" func main() { fmt.Printf("%s%c%s%c\n", s, 0x60, s, 0x60) } var s = ` |