├── poly_gif ├── hh.gif ├── fizzbuzz7.gif └── README.md ├── cal_bf ├── README.md └── cal.bf ├── lisp_sed └── README.md ├── lisp_bef └── README.md ├── poly5_quine ├── README.md └── poly_quine5.txt ├── very_symmetric_js ├── README.md ├── very_symmetric_base.js ├── very_symmetric_tmpl.html ├── very_symmetric.js └── very_symmetric_js.rb ├── Makefile ├── README.tmpl ├── rad_hard_quine ├── README.md ├── check_robust_quine.rb └── robust_quine.pl ├── lower_rb └── README.md ├── sym_poly_quine ├── README.md └── sym_poly_quine.txt ├── keyword_pl ├── README.md └── ppencode.html ├── alparen_py ├── README.md ├── gen_alparen_quine.py └── ppencode_py.html ├── gen_readme.rb ├── bf_rb_reg ├── README.md └── bf.rb └── README.md /poly_gif/hh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shinh/hack/HEAD/poly_gif/hh.gif -------------------------------------------------------------------------------- /poly_gif/fizzbuzz7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shinh/hack/HEAD/poly_gif/fizzbuzz7.gif -------------------------------------------------------------------------------- /cal_bf/README.md: -------------------------------------------------------------------------------- 1 | # cal(1) in Brainfuck 2 | 3 | Keywords: Esolang Brainfuck 4 | 5 | [cal.bf](cal.bf) 6 | -------------------------------------------------------------------------------- /lisp_sed/README.md: -------------------------------------------------------------------------------- 1 | # Sed Lisp 2 | 3 | Keywords: Esolang Sed 4 | 5 | https://github.com/shinh/sedlisp 6 | -------------------------------------------------------------------------------- /lisp_bef/README.md: -------------------------------------------------------------------------------- 1 | # Befunge Lisp 2 | 3 | Keywords: Esolang Befunge 4 | 5 | https://github.com/shinh/beflisp 6 | -------------------------------------------------------------------------------- /poly5_quine/README.md: -------------------------------------------------------------------------------- 1 | # 5 Languages Polyglot Quine 2 | 3 | Keywords: Polyglot Quine C Ruby Python Perl Brainfuck 4 | 5 | [poly_quine5.txt](poly_quine5.txt) 6 | -------------------------------------------------------------------------------- /very_symmetric_js/README.md: -------------------------------------------------------------------------------- 1 | # Very symmetric JS 2 | 3 | Keywords: Restricted JavaScript 4 | 5 | See [very_symmetric_js.html](http://shinh.skr.jp/obf/very_symmetric_js.html) 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: README.md README.html 2 | 3 | README.md: gen_readme.rb README.tmpl $(wildcard */README.md) 4 | ./gen_readme.rb README.tmpl > $@.tmp && mv $@.tmp $@ 5 | 6 | README.html: README.md 7 | markdown $< > $@.tmp && mv $@.tmp $@ 8 | -------------------------------------------------------------------------------- /README.tmpl: -------------------------------------------------------------------------------- 1 | # A tricky code collection 2 | 3 | This repository will be a collection of tricky code. 4 | 5 | Unless otherwise specified, programs linked from this repository are 6 | written by myself. I'm also trying to mention pioneer works for each 7 | code. 8 | 9 | ## Categories 10 | 11 | %CATEGORIES% 12 | 13 | ## Languages 14 | 15 | %LANGUAGES% 16 | -------------------------------------------------------------------------------- /rad_hard_quine/README.md: -------------------------------------------------------------------------------- 1 | # Radiation-hardened Quine 2 | 3 | Keywords: Quine Ruby Perl 4 | 5 | mame defined "radiation-hardened Quine" as "a Quine which works even 6 | after any one characters is deleted" and implemented the first version 7 | in Ruby: https://github.com/mame/radiation-hardened-quine 8 | 9 | [robust_quine.pl](robust_quine.pl) is its Perl version, written by 10 | myself. 11 | -------------------------------------------------------------------------------- /lower_rb/README.md: -------------------------------------------------------------------------------- 1 | # Ruby only with lower-case alphabets 2 | 3 | Keywords: Restricted Quine Ruby 4 | 5 | [for Ruby 1.9](http://www.slideshare.net/mametter/ruby-2012) (by mame) 6 | 7 | [Quine for Ruby 1.8](http://golf.shinh.org/reveal.rb?Quine/shinh+%28downcase%2C+mame%29_1346181195&rb) 8 | 9 | [Alnum Quine by flagitious](http://golf.shinh.org/reveal.rb?Quine/flagitious%28alnum%29_1222800064&rb) 10 | is a pioneer work. 11 | -------------------------------------------------------------------------------- /rad_hard_quine/check_robust_quine.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | f = ARGV[0] || 'robust_quine.rb' 4 | 5 | prog = 'ruby' 6 | if f =~ /\.pl$/ 7 | prog = 'perl' 8 | end 9 | 10 | c = File.read(f) 11 | a = `#{prog} #{f}` 12 | raise if c != a 13 | 14 | c.size.times{|i| 15 | m = c.dup 16 | m[i, 1] = '' 17 | File.open('out.rb', 'w'){|of|of.print(m)} 18 | a = `#{prog} out.rb` 19 | if a == c 20 | puts "#{i}: OK" 21 | else 22 | puts "#{i}: FAIL at #{c[i-2,2]} '#{c[i]}' #{c[i+1,2]}" 23 | end 24 | } 25 | -------------------------------------------------------------------------------- /rad_hard_quine/robust_quine.pl: -------------------------------------------------------------------------------- 1 | $$qq.=q';printf"\$\$qq.=q%c%s%c;;##%c;\n\$\$uu.=q%c%s%c;;##%c;%s",39,$&,39,39,39,$&,39,39,q{ 2 | $$ii||=\$_;; 3 | $$$ii.=$$qq;;s#^;.{192}$#$$qq#see;;#;#^^; 4 | $$nn||=\$_;;$$$nn.=$$uu;;s#;.{192}$#$$uu#see;#;};exit';;##'; 5 | $$uu.=q';printf"\$\$qq.=q%c%s%c;;##%c;\n\$\$uu.=q%c%s%c;;##%c;%s",39,$&,39,39,39,$&,39,39,q{ 6 | $$ii||=\$_;; 7 | $$$ii.=$$qq;;s#^;.{192}$#$$qq#see;;#;#^^; 8 | $$nn||=\$_;;$$$nn.=$$uu;;s#;.{192}$#$$uu#see;#;};exit';;##'; 9 | $$ii||=\$_;; 10 | $$$ii.=$$qq;;s#^;.{192}$#$$qq#see;;#;#^^; 11 | $$nn||=\$_;;$$$nn.=$$uu;;s#;.{192}$#$$uu#see;#; -------------------------------------------------------------------------------- /sym_poly_quine/README.md: -------------------------------------------------------------------------------- 1 | # Polyglot Symbolic Quine 2 | 3 | Keywords: Restricted Polyglot Quine Ruby Perl JavaScript 4 | 5 | [sym_poly_quine.txt](sym_poly_quine.txt) 6 | 7 | This is a mixture of known techniques: 8 | 9 | [Acme::EyeDrops](http://search.cpan.org/dist/Acme-EyeDrops/lib/Acme/EyeDrops.pm) is a Perl module which convers normal Perl program to symbolic code. 10 | 11 | [kurimura invented a way to convert normal Ruby program to symbolic code](http://d.hatena.ne.jp/kurimura/20080824). 12 | 13 | I believe [javascripter invented a way to write JavaScript programs only with symbolic characters](http://javascripter.hatenablog.com/entry/20090607/1244386028). 14 | -------------------------------------------------------------------------------- /keyword_pl/README.md: -------------------------------------------------------------------------------- 1 | # Keyword-only Perl 2 | 3 | Keywords: Restricted Quine Perl 4 | 5 | A program which converts any Perl code to a Perl code which only has 6 | Perl keywords: 7 | 8 | [ppencode.html](http://shinh.skr.jp/obf/ppencode.html) 9 | 10 | Note, unlike other languages, Perl defines builtin functions as 11 | "keywords". "open", "length", "s", and so on are keywords in Perl. 12 | 13 | I think TAKESAKO's 14 | [ppencode](http://namazu.org/~takesako/ppencode/demo.html) 15 | is a pioneer work of this category. 16 | 17 | [yuine_kw.pl](yuine_kw.pl) is a keyword-only Perl program which 18 | generates [yuine_sym.pl](yuine_sym.pl), which is a symbol-only Perl 19 | program which generates [yuine_kw.pl](yuine_kw.pl). 20 | -------------------------------------------------------------------------------- /poly_gif/README.md: -------------------------------------------------------------------------------- 1 | # Polyglot GIF 2 | 3 | Keywords: Polyglot Binary Ruby Perl 4 | 5 | ## fizzbuzz7.gif 6 | 7 | [fizzbuzz7.gif](fizzbuzz7.gif) is 8 | 9 | - GIF file 10 | - Ruby (1.8) program 11 | - Perl program 12 | - Z80 program 13 | - COM program 14 | - Bootable 15 | 16 | So you can do 17 | 18 | ``` 19 | $ ruby1.8 fizzbuzz7.gif 20 | $ perl fizzbuzz7.gif 21 | $ z80golf fizzbuzz7.gif # http://golf.shinh.org/z80golf.tgz 22 | $ bef fizzbuzz7.gif # http://catseye.tc/projects/bef-2.21.zip 23 | $ cp fizzbuzz7.gif fb.com && dosemu -dumb fb.com 24 | $ qemu fizzbuzz7.gif 25 | ``` 26 | 27 | Description: http://shinhoge.blogspot.jp/2008/10/fizzbuzz7gif.html 28 | 29 | ## hh.gif 30 | 31 | [hh.gif](hh.gif) 32 | 33 | Description: http://shinhoge.blogspot.jp/2008/11/hhgif.html 34 | -------------------------------------------------------------------------------- /alparen_py/README.md: -------------------------------------------------------------------------------- 1 | # Python only with lowercase alphabets and parenthesis 2 | 3 | Keywords: Restricted Quine Python 4 | 5 | A program which converts a Python code to a Python code which only has 6 | lowercase alphabets and parenthesis: 7 | 8 | [ppencode_py.html](http://shinh.skr.jp/obf/ppencode_py.html) 9 | 10 | [nishiohirokazu found a way to write Python code only with lower case alphabets, parenthesis, and commas](http://d.hatena.ne.jp/nishiohirokazu/20120906/1346938523). 11 | 12 | There are also Quines with the same restriction: 13 | 14 | [for Python 2](alparen_quine.py) 15 | 16 | [for Python 3](alparen_quine.py3) 17 | 18 | These Quines are using some more tricks than ppencode_py mainly to 19 | reduce the size of code. Two important tricks are creditted to 20 | @mametter and @phoenixstarhiro. 21 | -------------------------------------------------------------------------------- /very_symmetric_js/very_symmetric_base.js: -------------------------------------------------------------------------------- 1 | // 671 2 | 3 | str_undefined=[]+[][num_1=0] 4 | str_o=(str_object=[]+{})[++num_1]; 5 | str_a=(str_false=[]+(0<0))[num_1]; 6 | str_t=(str_true=[]+(0<<"$_="+(_=""<<(___<<__+_)+$__-_)+($_+_+";$___="+_+$___+_+$___<<__+$__)#*/=_=+[];$$=""+{};_$=""+[][++_];$$$=""+!_;$$_=""+!$;$$=_[__$=($__=$$[_$$=_+_+_+_+_])+$$[_]+_$[_]+$$$[_+_+_]+$$[_$$+_]+$$_[_]+_$[$]+$__+$$_[$]+$$[_]+$$_[_]][__$];$$($_)() 2 | -------------------------------------------------------------------------------- /gen_readme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | CATEGORIES = %w(Quine Polyglot Esolang Restricted Binary Golf) 4 | LANGUAGES = %w(Ruby Perl Python Sed Brainfuck C JavaScript Befunge) 5 | 6 | DESCS = { 7 | 'Quine' => 'See http://en.wikipedia.org/wiki/Quine_%28computing%29', 8 | 'Esolang' => 'See https://esolangs.org/wiki/Main_Page', 9 | 'Restricted' => %q(Code written with some restrictions. For example, Ruby (>= 1.9), Perl, JavaScript, and Groovy are known to be turing complete only with symbolic characters (no alphabets, no numerals, no control characters, and no non-ascii characters.).), 10 | 'Polyglot' => 'See http://en.wikipedia.org/wiki/Polyglot_(computing)', 11 | } 12 | 13 | cats = {} 14 | langs = {} 15 | 16 | tmpl = $<.read 17 | 18 | Dir.glob('*/README.md').each do |md| 19 | c = File.read(md) 20 | if c !~ /\A# (.*)/ 21 | raise "no titles in #{md}" 22 | end 23 | title = $1 24 | if c !~ /^Keywords: (.*)/ 25 | raise "no keywords in #{md}" 26 | end 27 | 28 | $1.split.each do |c| 29 | if CATEGORIES.include?(c) 30 | cats[c] ||= [] 31 | cats[c] << [title, md] 32 | elsif LANGUAGES.include?(c) 33 | langs[c] ||= [] 34 | langs[c] << [title, md] 35 | else 36 | raise "unknown keyword: #{c}" 37 | end 38 | end 39 | end 40 | 41 | [['CATEGORIES', cats], ['LANGUAGES', langs]].each do |n, m| 42 | o = '' 43 | m.sort_by{|k, mds|k}.each do |k, mds| 44 | o += "\n### #{k}\n#{DESCS[k]}\n\n" 45 | mds.sort.each do |md| 46 | o += "- [#{md[0]}](#{md[1]})\n" 47 | end 48 | end 49 | tmpl.sub!("%#{n}%", o) 50 | end 51 | 52 | print tmpl 53 | -------------------------------------------------------------------------------- /bf_rb_reg/README.md: -------------------------------------------------------------------------------- 1 | # Brainfuck in Ruby's Regexp 2 | 3 | Keywords: Ruby Brainfuck 4 | 5 | [bf.rb](bf.rb) 6 | 7 | This code runs some Brainfuck code in a single Ruby's Regexp. As far 8 | as I know, Ruby's Regexp doesn't allow infinite loop and thus it's not 9 | Turing-complete. However, it still can run some non-trivial Brainfuck 10 | code like [cal.bf](../cal_bf/cal.bf): 11 | 12 | $ echo 2016 10 | ruby bf_rb_reg/bf.rb cal_bf/cal.bf 13 | 1 14 | 2 3 4 5 6 7 8 15 | 9 10 11 12 13 14 15 16 | 16 17 18 19 20 21 22 17 | 23 24 25 26 27 28 29 18 | 30 31 19 | 20 | The (fairly big) Regexp is defined as `BF_REG`. There's also a String 21 | constant `BF_SUFFIX` which provides the list of characters. You can run 22 | Brainfuck code `bf` by 23 | 24 | BF_REG =~ bf + BF_SUFFIX 25 | 26 | The output is stored in `$~['o0']`, `$~['o1']`, ... You can get it by 27 | 28 | output = '' 29 | 256.times do |i| 30 | o = $~["o#{i}"] 31 | break if !o 32 | output += o 33 | end 34 | 35 | Here's the list of specifications of the implementation: 36 | 37 | * 8bit cells 38 | * EOF is -1 39 | * There's only 256 cells 40 | * Can output at most 256 bytes 41 | * Can input at most 256 bytes 42 | * The Regexp doesn't match if there's a non-Brainfuck character 43 | * The Regexp doesn't match if there's an infinite loop (a loop stops 44 | after 256 iterations. This means a Brainfuck code which actually 45 | halts may fail) 46 | 47 | Acknowledgement: The original code was 2400x slower for cal.bf, but 48 | [@saito_ta](https://twitter.com/saito_ta) and 49 | [@yvl_](https://twitter.com/yvl_) made significant performance 50 | improvements. 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /alparen_py/gen_alparen_quine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | 5 | PYTHON_VER = sys.argv[1] if len(sys.argv) > 1 and sys.argv[1] else '2' 6 | CHR='chr' if PYTHON_VER == '3' else 'unichr' 7 | DIV='//' if PYTHON_VER == '3' else '/' 8 | 9 | def d(r,n): 10 | for i in range(n): 11 | r="next(reversed(range(%s)))"%r 12 | return r 13 | 14 | def e(v): 15 | a=[] 16 | v-=1 17 | while v: 18 | a.append(v%3) 19 | v/=3 20 | r=d("len(repr(repr(str())))",3-a[-1]) 21 | for i in list(reversed(a))[1:]: 22 | r=d("len(repr(list(bytearray(%s))))"%r,2-i) 23 | return r 24 | 25 | #print e(400) 26 | #print eval(e(299)) 27 | 28 | #sys.exit(0) 29 | 30 | # len(repr(list(bytearray(i)))) 31 | 32 | q='''q="q="+repr(q)+";exec(q)" 33 | def d(r,n): 34 | for i in range(n): 35 | r="next(reversed(range(%s)))"%r 36 | return r 37 | 38 | def e(v): 39 | if v<2: 40 | return"len(str(len(str())))"if v else"len(str())" 41 | a=[] 42 | v-=1 43 | while v: 44 | a+=[v%3] 45 | v'''+DIV+'''=3 46 | r=d("len(repr(repr(str())))",3-a[-1]) 47 | for i in list(reversed(a))[1:]: 48 | v*=3 49 | v-=2-i 50 | r=d("len(repr(list(bytearray(%s))))"%r,2-i) 51 | return r 52 | o="" 53 | i=0 54 | for c in q: 55 | o+="("+e(ord(c))+")if("+"'''+CHR+'''("+e(i)+")in('''+CHR+'''(i))"+")else" 56 | i+=1 57 | ''' 58 | if PYTHON_VER == '3': 59 | q+='''print("exec(eval(str(bytearray("+o+"()for(i)in(range("+e(len(q))+"))))))")''' 60 | else: 61 | q+='''print("exec(str(bytearray("+o+"()for(i)in(range("+e(len(q))+")))))")''' 62 | exec(q) 63 | 64 | sys.stderr.write("%s\n" % len(q)) 65 | 66 | #print len(q) 67 | #len(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(repr(str())))))))))))))))))))))) 68 | 69 | # 130: 70 | # len(repr(repr(repr(repr(repr(repr(repr(repr(list()))))))))) 71 | 72 | 73 | #q = '(print(bytearray()))' 74 | # 75 | #for x in slice(bytearray([40,33]): 76 | # exec('print(x)') 77 | 78 | 79 | -------------------------------------------------------------------------------- /very_symmetric_js/very_symmetric_tmpl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Very symmetric JavaScript code 5 | 6 | 7 | 19 | 20 | 63 | 64 | 65 | 66 | 67 |

Very symmetric JavaScript code

68 | 69 |

70 | This is a JavaScript code which has three symmetries - reflections by both horizontal and vertical axes and a rotation by 180 degrees. Here's the list of allowed characters and how they are transformed. 71 | 72 |

73 | TBL 74 | 75 |

76 | 77 | You can also run this code by SpiderMonkey or Node.js. 78 | 79 |

80 | Original code:
81 | 82 | 83 |

84 | Flipped horizontally (by CSS):
85 | 86 | 87 |

88 | Flipped vertically (by CSS):
89 | 90 | 91 |

92 | Rotated 180 degrees (by CSS):
93 | 94 | 95 |

96 |

97 |
98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A tricky code collection 2 | 3 | This repository will be a collection of tricky code. 4 | 5 | Unless otherwise specified, programs linked from this repository are 6 | written by myself. I'm also trying to mention pioneer works for each 7 | code. 8 | 9 | ## Categories 10 | 11 | 12 | ### Binary 13 | 14 | 15 | - [Polyglot GIF](poly_gif/README.md) 16 | 17 | ### Esolang 18 | See https://esolangs.org/wiki/Main_Page 19 | 20 | - [Befunge Lisp](lisp_bef/README.md) 21 | - [Sed Lisp](lisp_sed/README.md) 22 | - [cal(1) in Brainfuck](cal_bf/README.md) 23 | 24 | ### Polyglot 25 | See http://en.wikipedia.org/wiki/Polyglot_(computing) 26 | 27 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 28 | - [Polyglot GIF](poly_gif/README.md) 29 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 30 | 31 | ### Quine 32 | See http://en.wikipedia.org/wiki/Quine_%28computing%29 33 | 34 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 35 | - [Keyword-only Perl](keyword_pl/README.md) 36 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 37 | - [Python only with lowercase alphabets and parenthesis](alparen_py/README.md) 38 | - [Radiation-hardened Quine](rad_hard_quine/README.md) 39 | - [Ruby only with lower-case alphabets](lower_rb/README.md) 40 | 41 | ### Restricted 42 | Code written with some restrictions. For example, Ruby (>= 1.9), Perl, JavaScript, and Groovy are known to be turing complete only with symbolic characters (no alphabets, no numerals, no control characters, and no non-ascii characters.). 43 | 44 | - [Keyword-only Perl](keyword_pl/README.md) 45 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 46 | - [Python only with lowercase alphabets and parenthesis](alparen_py/README.md) 47 | - [Ruby only with lower-case alphabets](lower_rb/README.md) 48 | 49 | 50 | ## Languages 51 | 52 | 53 | ### Befunge 54 | 55 | 56 | - [Befunge Lisp](lisp_bef/README.md) 57 | 58 | ### Brainfuck 59 | 60 | 61 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 62 | - [Brainfuck in Ruby's Regexp](bf_rb_reg/README.md) 63 | - [cal(1) in Brainfuck](cal_bf/README.md) 64 | 65 | ### C 66 | 67 | 68 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 69 | 70 | ### JavaScript 71 | 72 | 73 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 74 | 75 | ### Perl 76 | 77 | 78 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 79 | - [Keyword-only Perl](keyword_pl/README.md) 80 | - [Polyglot GIF](poly_gif/README.md) 81 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 82 | - [Radiation-hardened Quine](rad_hard_quine/README.md) 83 | 84 | ### Python 85 | 86 | 87 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 88 | - [Python only with lowercase alphabets and parenthesis](alparen_py/README.md) 89 | 90 | ### Ruby 91 | 92 | 93 | - [5 Languages Polyglot Quine](poly5_quine/README.md) 94 | - [Brainfuck in Ruby's Regexp](bf_rb_reg/README.md) 95 | - [Polyglot GIF](poly_gif/README.md) 96 | - [Polyglot Symbolic Quine](sym_poly_quine/README.md) 97 | - [Radiation-hardened Quine](rad_hard_quine/README.md) 98 | - [Ruby only with lower-case alphabets](lower_rb/README.md) 99 | 100 | ### Sed 101 | 102 | 103 | - [Sed Lisp](lisp_sed/README.md) 104 | 105 | -------------------------------------------------------------------------------- /alparen_py/ppencode_py.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ppencode? for Python 7 | 8 | 9 | 10 | 11 | 12 | 91 | 92 | 93 |

ppencode? for Python - JavaScript demo

94 | 95 |

96 | This converts a text or Python script to a Python script which 97 | uses only lowercase alphabet characters and parenthesis. 98 | 99 |

100 | 101 |

102 |
103 |
Input 104 | text 105 | Python script 106 |
107 |
108 |
Python 109 | 2 110 | 3 111 | program
112 |
113 |
114 | 115 | 116 |
117 |
118 | 119 | 120 | -------------------------------------------------------------------------------- /cal_bf/cal.bf: -------------------------------------------------------------------------------- 1 | # these fields will be used for data lookup 2 | >>>>>>>>>>>>>>>>>>>> 3 | # load year 4 | > 5 | ,--------------------------------[---------------->,--------------------------------] 6 | # 0 y y y y 7 | <+ 8 | <[->++++++++++<] 9 | <<[->++++++++++<] 10 | <<< 11 | # 0 0 y1 0 y2 12 | # load month 13 | , 14 | ------------------------------------------------ 15 | <, 16 | +[-----------[-----------------------------[->+<]]] 17 | > 18 | [-<+<+>>>>+<<] 19 | << 20 | # m 0 y1 0 y2 21 | 22 | # data lookup (wday adjustment) 23 | <<------<----<-<------<---<-------<-----<--<-------<----<----<- 24 | [>] 25 | >-[-<<[<]>[+]>[>]>] 26 | - 27 | <<<[>[+]<<]> 28 | >+[-<[+>-<]>>+] 29 | 30 | >[-<<<<+>>>>] 31 | <<<< 32 | 33 | # data lookup (num days per month minus 32) 34 | <<-<--<-<--<-<-<--<-<--<-<----<- 35 | [>] 36 | >-[-<<[<]>[+]>[>]>] 37 | - 38 | <<[>[+]<<]> 39 | >+[-<[+>-<]>>+] 40 | 41 | # calculate correct num days (plus 32) 42 | <++++++++++++++++++++++++++++++++ 43 | 44 | >>> 45 | >> 46 | >>> 47 | 48 | # m *0 y1 0 y2 49 | >>[-<+>>>>>>>+<<<<<<] 50 | >>>>>> 51 | [>[-]>[-]>[-]>[-]<<<<<<++++<+>[->>[>]+[<]>-<<]>>]>[>]<<[>-<[<]>+[>]<<] 52 | >[-<<<+>>>] 53 | <<<----[++++<->>]<[<] 54 | # m y1 0 0 y2 y1/4 y1%4 55 | >-[-<+>>>>>>>+<<<<<<] 56 | >>>>>> 57 | ++++ 58 | [>[-]>[-]>[-]>[-]<<<<<<++++<+>[->>[>]+[<]>-<<]>>]>[>]<<[>-<[<]>+[>]<<] 59 | >[-<<<+>>>] 60 | <<<----[++++<->>] 61 | <<<<<<<<<[<]> 62 | >>>>>>>- 63 | # m y1 0 y2 0 y1/4 y1%4 *y2/4 y2%4 64 | [-<<+>>]<< 65 | <<[-<+<<<+>>>>]>> 66 | [-<<<+>>>]<<<[->+<] 67 | < 68 | [->+>+++++<<] 69 | >> 70 | 71 | # m 0 y1 *wday 0 0 y1%4 0 y2%4 72 | 73 | # leap (check y%100) 74 | <<<< 75 | <+> 76 | [<->>>>>>+>>>>[<<<<->>>>[-]]<<<<<<<<<[-]] 77 | <[->>>>>>+>>[<<->>[-]]<<<<<<<<]> 78 | >>>> 79 | 80 | # m 0 y1 *wday leap 0 y1%4 0 y2%4 81 | 82 | # leap test 83 | >[- 84 | <<<< 85 | # month minus 12 86 | ------------[+[+[+[+[+[+[+[+[+[ 87 | # only Jan or Feb can be here, let's adjust wday 88 | >>>-<<< 89 | # only Feb can be inside the loop, 28 to 29 90 | ++[<<<<<<<<+>>>>>>>>-] 91 | [+] 92 | ]]]]]]]]]] 93 | >>>>] 94 | < 95 | 96 | # moving wday data (ugly) 97 | - 98 | <<<<<<<<[+>>>>>>>>+<<<<<<<<]>>>>>>>> 99 | [->>>>>>>>>+<<<<<<<<<] 100 | >>>>>>>>> 101 | 102 | # divide wday by 7 103 | [>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<+++++++<+>[->>[>]+[<]>-<<]>>]>[>]<<[>-<[<]>+[>]<<] 104 | >[-<<<+>>>] 105 | <<< 106 | <+> 107 | # 0 0 y1 0 0 0 y1%4 0 y2%4 ?? *wday 108 | ------- 109 | [+++++++>>+<] 110 | 111 | >[<]>[-]< 112 | < 113 | 114 | [->+>+<<]>> 115 | 116 | >++++++++++++++++++++++++++++++++< 117 | [->...<] 118 | >[-] 119 | <+<------- 120 | <[-]> # unecessary 121 | 122 | # 0 0 y1 0 0 0 y1%4 0 y2%4 ?? 0 *(wday minus 7) 0 1 123 | 124 | > 125 | 126 | # loop for printing numbers 127 | <<<<<<<<<<<<<<<<<<<< 128 | [ 129 | >>>>>>>>>>>>>>>>>>>> 130 | 131 | # checks if day number is bigger than 9 132 | [->+>+>+<<<]>>> 133 | -[-[-[-[-[-[-[-[-[ 134 | [-] 135 | < 136 | 137 | [->>>+<<<] 138 | >>> 139 | [ 140 | >>>>>>>>>>>>>>>>>>>> 141 | + 142 | <<<<<<<<<<<<<<<<<<<< 143 | # divide by 10 (ugly) 144 | >[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<<<<++++++++++<+>[->>[>]+[<]>-<<]>>]>[>]<<[>-<[<]>+[>]<<] 145 | 146 | > 147 | 148 | ----------[++++++++++< 149 | >>>>>>>>>>>>>>>>>>>> 150 | - 151 | <<<<<<<<<<<<<<<<<<<< 152 | ] 153 | <<<[>]>> 154 | >>>>>>>>>>>>>>>>>>>> 155 | ++++++++++++++++++++++++++++++++++++++++++++++++.[-] 156 | <<<<<<<<<<<<<<<<<<<< 157 | >++++++++++++++++++++++++++++++++++++++++++++++++. 158 | 159 | [-]<[-] 160 | <<<[-] 161 | ]]]]]]]]] 162 | 163 | # else (day number is smaller than 10) 164 | <[<]>> 165 | [>++++++++++++++++++++++++++++++++.[-] 166 | < 167 | # 1 0 y1 0 0 0 y1%4 0 y2%4 ?? 0 (wday minus 7) 0 1 *1 168 | ++++++++++++++++++++++++++++++++++++++++++++++++.[-] 169 | ] 170 | 171 | <<< 172 | # 1 0 y1 0 0 0 y1%4 0 y2%4 ?? 0 *(wday minus 7) 0 1 173 | 174 | # if wday % 7 then print space else print new line 175 | +[>>>++++++++++++++++++++++<<<<] 176 | >>[<<------->] 177 | >>++++++++++.[-] 178 | <[-<+>]< 179 | + 180 | 181 | [->+>+<<] 182 | >[-<+>] 183 | > 184 | [-] 185 | 186 | << 187 | 188 | <<<<<<<<<<<<<<<<<<<< 189 | - 190 | 191 | ] 192 | -------------------------------------------------------------------------------- /bf_rb_reg/bf.rb: -------------------------------------------------------------------------------- 1 | #BF_CHARS = [*'0'..'9'] + [*'A'..'Z'] 2 | 3 | #BF_CHARS = (0..255).map do |i| 4 | # (i / 16).to_s(32) + (i % 16 + 16).to_s(32) 5 | #end 6 | 7 | #BF_CHARS = (0..127).map do |i| 8 | # (i + 128).chr 9 | #end 10 | 11 | BF_CHARS = (0..255).map(&:chr) 12 | 13 | Z = BF_CHARS[0] 14 | 15 | ANY = '.' * BF_CHARS[0].size 16 | 17 | BF_SUFFIX = "#{BF_CHARS[-1]};;" + BF_CHARS * '' * 4 18 | 19 | def h(c) 20 | if '()*+?[]\\#$.^|'.index(c) 21 | "\\#{c}" 22 | elsif c == "\t" 23 | "\\t" 24 | elsif c == "\n" 25 | "\\n" 26 | elsif c == "\f" 27 | "\\f" 28 | elsif c == "\r" 29 | "\\r" 30 | elsif c == " " 31 | "[ ]" 32 | else 33 | c 34 | end 35 | end 36 | 37 | def gen_set_mi 38 | a = [] 39 | BF_CHARS.each_with_index do |c, i| 40 | a << "(?(?#{ANY})){0}" 41 | end 42 | a * '' 43 | end 44 | 45 | def gen_inc_p 46 | a = [] 47 | BF_CHARS.each_with_index do |c, i| 48 | a << "(\\k

\\g.*?(?=\\k)\\g.*?(?=\\k)\\g|#{h(c)}" 49 | end 50 | a * '' + ')' * BF_CHARS.size 51 | end 52 | 53 | def gen_dec_p 54 | a = [] 55 | BF_CHARS.each_with_index do |c, i| 56 | a << "((?=#{ANY}\\k

)\\g.*?(?=\\k)\\g.*?(?=\\k)\\g|#{h(c)}" 57 | end 58 | a * '' + ')' * BF_CHARS.size 59 | end 60 | 61 | def output 62 | a = [] 63 | BF_CHARS.each_with_index do |c, i| 64 | a << "(?=.*(?=#{h(c)})\\k)(?#{ANY})" 65 | end 66 | a * '|' 67 | end 68 | 69 | def input 70 | a = [] 71 | BF_CHARS.each_with_index do |c, i| 72 | a << "(?=.*(?=#{h(c)})\\k)(?=#{ANY*i}\\g)" 73 | end 74 | a * '|' 75 | end 76 | 77 | def init_m 78 | a = [] 79 | BF_CHARS.each_with_index do |c, i| 80 | a << "(?=.*;;.*(?=#{h(c)})\\g)(?=.*;;.*(?=#{Z})\\g)" 81 | end 82 | a.reverse * '' 83 | end 84 | 85 | def nest 86 | "(?=.*;;(?=#{Z})\\k)\\g|(?=\\g)(" * BF_CHARS.size + ")" * BF_CHARS.size 87 | end 88 | 89 | BF_REG = /^ 90 | 91 | #{gen_set_mi} 92 | 93 | (?(?

#{ANY})){0} 94 | 95 | (?(?#{ANY})){0} 96 | (?=.*;;.*?(?=#{Z})\g) 97 | 98 | (?(?#{ANY})){0} 99 | (?=.*;;.*?(?=#{Z})\g) 100 | 101 | (?(?#{ANY})){0} 102 | (?=.*;;.*?(?=#{Z})\g) 103 | 104 | (?(?=.*;;#{gen_inc_p})){0} 105 | (?(?=.*;;#{gen_dec_p})){0} 106 | 107 | (?#{output}){0} 108 | 109 | (?#{init_m}){0} 110 | \g 111 | 112 | (?[^\[\]]*(\[\g\][^\[\]]*)*){0} 113 | 114 | (? 115 | 116 | ( 117 | ( 118 | \+(?=.*;;.*?\k\g) 119 | | -(?=.*;;.*?(?=#{ANY}\k)\g) 120 | | >\g 121 | | <\g 122 | | \[ ( #{nest} ) \] 123 | | \.(?=.*;;.*?(?=\k)\g)(?=.*;;.*?\k\g) 124 | | ,(?=.*?!(#{input}))(?=.*;;.*?\k\g) 125 | ) 126 | )+ 127 | 128 | ){0} 129 | 130 | \g 131 | 132 | (!|#{BF_SUFFIX.chars.map{|_|h(_)}*''}$)/xms 133 | 134 | def run_bf(bf) 135 | if BF_REG =~ bf + BF_SUFFIX 136 | $~ 137 | else 138 | false 139 | end 140 | end 141 | 142 | def collect_output(m) 143 | r = '' 144 | BF_CHARS.size.times do |i| 145 | o = m["o#{i}"] 146 | if !o 147 | break 148 | end 149 | r += o 150 | end 151 | r 152 | end 153 | 154 | def check(bf, ep, em, eo='') 155 | start = Time.now 156 | ex = em[ep] 157 | 158 | m = run_bf(bf) 159 | if !m 160 | puts "FAIL(match): #{bf}" 161 | return 162 | end 163 | 164 | ap = BF_CHARS.index(m['p']) 165 | if ap != ep 166 | puts "FAIL(ptr): #{bf} expected=#{ep} actual=#{ap}" 167 | return 168 | end 169 | 170 | ax = BF_CHARS.index(m['x']) 171 | if ex && ax != ex 172 | puts "FAIL(x): #{bf} expected=#{ex} actual=#{ax}" 173 | return 174 | end 175 | 176 | am = [] 177 | em.size.times do |i| 178 | if i == ep 179 | am << ax 180 | else 181 | am << BF_CHARS.index(m["m#{i}"]) 182 | end 183 | end 184 | if am != em 185 | puts "FAIL(mem): #{bf} expected=#{em} actual=#{am}" 186 | return 187 | end 188 | 189 | ao = collect_output(m) 190 | if ao != eo 191 | puts "FAIL(out): #{bf} expected=#{eo} actual=#{ao}" 192 | return 193 | end 194 | 195 | puts "OK: #{bf} #{Time.now - start}" 196 | end 197 | 198 | if ARGV.empty? 199 | puts "Usage: %s [input]" % $0 200 | 201 | puts "Running tests..." 202 | 203 | check('+++', 0, [3]) 204 | 205 | check('>>', 2, []) 206 | 207 | check('+++++--+>+++<+>>', 2, [5, 3]) 208 | 209 | check('[+]+', 0, [1]) 210 | 211 | check('+++[-]+', 0, [1]) 212 | 213 | check('+++[->++<]+', 0, [1, 6]) 214 | 215 | check('[[]]+', 0, [1]) 216 | 217 | check('+++[->++[->+++<]<]+', 0, [1, 0, 18]) 218 | 219 | check('+' * 33 + '.', 0, [33], '!') 220 | 221 | check('+' * 33 + '.++.', 0, [35], '!#') 222 | 223 | check(',.!x', 0, [120], 'x') 224 | 225 | check(',.,.,.!foo', 0, [111], 'foo') 226 | check(',.,.,.,.!hoge', 0, [101], 'hoge') 227 | 228 | check(',+[-.,+]!xyz', 0, [0], 'xyz') 229 | 230 | check('-', 0, [BF_CHARS.size - 1]) 231 | check('>' * (BF_CHARS.size + 1), 1, []) 232 | check('<<', BF_CHARS.size - 2, []) 233 | check('+' * (BF_CHARS.size + 2), 0, [2]) 234 | 235 | check(',[-]!;;!',0, [0]) 236 | check(',[-]!;;!' + BF_CHARS[1], 0, [0]) 237 | 238 | check('+<<---------[>+++++>>+>++>+>++[+++<]>--]>.[->+>+>+<<<]>+.>..+++.>>>-.<----.<++.<.+++.------.<-.>>>+.', 3, [100, 108, 119, 33, 44], 'Hello, world!') 239 | else 240 | bf = File.read(ARGV[0]) 241 | bf = bf.chars.select{|c|'+-><[].,'.index(c)} * '' 242 | if ARGV[1] 243 | bf += "!#{ARGV[1]}" 244 | elsif bf.index(',') 245 | bf += "!#{STDIN.read}" 246 | end 247 | 248 | m = run_bf(bf) 249 | if m 250 | puts collect_output(m) 251 | else 252 | STDERR.puts "Program doesn't finish" 253 | exit 1 254 | end 255 | end 256 | -------------------------------------------------------------------------------- /very_symmetric_js/very_symmetric.js: -------------------------------------------------------------------------------- 1 | ///*//XH}{0O=()=O0}{HX\\*\\\ 2 | O0=[]+[][I=0]//II]X][X[II\\[0=I][]+[]=0O 3 | HH=(H0X=[]+{})[++I]//XI0XX0IX\\[I++]({}+[]=X0H)=HH 4 | XX=(OH=[]+(0<0))[I]//+=OXO)OHHO(OXO=+\\[I]((0>0)+[]=HO)=XX 5 | HI=(HH0=[]+(00)+[]=0HH)=IH 6 | {IH=OH[H0=(H=I+I)+I]}{OI=O0[0]}//HH\\{[0]0O=IO}{[I+(I+I=H)=0H]HO=HI} 7 | {II=H0X[HO=H0+H]}{IO=O0[I]}//XH[HH0+HH+0HH]HX\\{[I]0O=OI}{[H+0H=OH]X0H=II} 8 | {HX=HH0[I]}{OO=O0[HO]}{I0=OH[H]}//=+O0==0O+=\\{[H]HO=0I}{[OH]0O=OO}{[I]0HH=XH} 9 | {X=OH[HO-I]}{IX=(OX=[]+/|()/)[I]}//HIH0OOOO0HIH\\{[I](\()|\+[]=XO)=XI}{[I-OH]HO=X} 10 | {IX+=IX}{X0=OX[H]}{XH=OX[H0]}//OHH]]+OH{(X==X)}HO+[[HHO\\{[0H]XO=HX}{[H]XO=0X}{XI=+XI} 11 | XI=II+HH+IO+IH+HI+HX+OI+II+HI+HH+H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}{HX//*/// 57 | -------------------------------------------------------------------------------- /keyword_pl/ppencode.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ppencode 2 7 | 8 | 9 | 139 | 140 | 141 |

ppencode 2 - JavaScript demo

142 | 143 |

144 | This is an improved version of ppencode. Like ppencode, this generates a Perl script which only uses Perl's (lowercase) keywords. Instead of printing the encoded string, this version evals it. So, you can convert any Perl script to a Perl script which only contains Perl keywords separated by whitespace. Believe it or not, I think this is a significantly more complex task than the original ppencode. 145 | 146 |

147 | This means Perl is Turing complete only with keywords, which means you can write a Quine only with keywords. 148 | 149 |

150 | 151 |

152 |
153 |
Input Perl program
154 |
155 |
Perl program
156 |
157 |
158 | 159 | 160 | 161 | 162 |
163 |
164 | 165 | 166 | -------------------------------------------------------------------------------- /very_symmetric_js/very_symmetric_js.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | def escapeHTML(c) 4 | c = c.gsub('&', '&') 5 | c = c.gsub('"', '"') 6 | c = c.gsub('<', '<') 7 | c = c.gsub('>', '>') 8 | c 9 | end 10 | 11 | D=28 12 | 13 | CONVS = { 14 | "(" => ")()", 15 | ")" => "()(", 16 | "/" => "\\\\/", 17 | "\\" => "//\\", 18 | "<" => "><>", 19 | ">" => "<><", 20 | "[" => "][]", 21 | "]" => "[][", 22 | "{" => "}{}", 23 | "}" => "{}{", 24 | } 25 | %q( #*+-0:=HIOX|).each_char{|c|CONVS[c] = c*3} 26 | 27 | c = File.read('very_symmetric_base.js') 28 | c.gsub!(/^\/\/.*\n/, '') 29 | c.gsub!(/^\n/, '') 30 | c="///*\n"+c 31 | 32 | var_chars = {} 33 | c.scan(/str_(\w)/) do 34 | var_chars[$1]=$& 35 | end 36 | var_chars[' ']='str_sp' 37 | var_chars['(']='str_op' 38 | var_chars[')']='str_cp' 39 | #var_chars['.']='str_dot' 40 | 41 | lengthy_map = Hash.new{0} 42 | 43 | c+="obj_function(obj_unescape(" 44 | code=%q((this.alert||this.print||console.log)("Hello, world!")) 45 | a=[] 46 | skip_next = false 47 | code.each_char do |ch| 48 | if skip_next 49 | skip_next = false 50 | next 51 | end 52 | if ch == '|' 53 | skip_next = true 54 | a << "str_or" 55 | elsif var_chars[ch] 56 | a << var_chars[ch] 57 | else 58 | lengthy_map[ch] += 1 59 | a << "str_percent" 60 | ('%02x'%ch.ord).each_char do |d| 61 | d = d.hex 62 | a << case d 63 | when 0 64 | '0' 65 | when 1 66 | 'num_1' 67 | when 2 68 | 'num_2' 69 | when 3 70 | 'num_3' 71 | when 4 72 | 'num_2*num_2' 73 | when 5 74 | 'num_5' 75 | when 6 76 | 'num_2*num_3' 77 | when 7 78 | '(num_5+num_2)' 79 | when 8 80 | 'num_2*num_2*num_2' 81 | when 9 82 | 'num_3*num_3' 83 | when 10..15 84 | 'str_' + d.to_s(16) 85 | end 86 | end 87 | end 88 | end 89 | c += a * '+' 90 | c += '))()' 91 | 92 | STDERR.puts lengthy_map 93 | 94 | cnts = Hash.new{0} 95 | c.scan(/(num|str|obj)_\w+/) do 96 | cnts[$&]+=1 97 | end 98 | 99 | sym_map={} 100 | n = 0 101 | cnts.sort_by{|_,c|-c}.each do |ident, _| 102 | n+=1 103 | sym_map[ident] = n.to_s(5).tr('01234', '0HIOX') 104 | end 105 | STDERR.puts sym_map 106 | 107 | File.open('before_symmetric.js','w') do |of| 108 | of.print(c) 109 | end 110 | 111 | used_cnts = {} 112 | sym_map.each do |k, _| 113 | used_cnts[k] = 0 114 | end 115 | c.gsub!(/(num|str|obj)_\w+/) do 116 | used_cnts[$&] += 1 117 | sym_map[$&] 118 | end 119 | STDERR.puts used_cnts.sort_by{|_,v|v}.inspect 120 | 121 | c.gsub!(/;/, '') 122 | 123 | File.open('only_symmetric.js','w') do |of| 124 | of.print(c) 125 | end 126 | 127 | STDERR.puts "#{c.size}" 128 | 129 | R=57 130 | R2=R-D 131 | tmpl=[] 132 | 1.upto(R-1) do |i| 133 | n = Math.sqrt(R*R - (R-i*2)**2).to_i 134 | j = i-D/2 135 | n2 = j > 0 && j < R2 ? Math.sqrt(R2*R2 - (R2-j*2)**2).to_i : 0 136 | s = ' ' * (R-n-1) 137 | #s += '/' * (n-n2) + ' ' * (n2*2) + '/' * (n-n2) 138 | l = (n-n2) 139 | #if i==R/2 140 | # l-=1 141 | #end 142 | s += '/' * l + ' ' * (n2*2) + ' ' * (n-n2) 143 | s += ' ' * ((R-1)*2-s.size) 144 | tmpl << s 145 | end 146 | 147 | lines=c.split("\n") 148 | last_line=lines.pop+'+/ *\\\\*' 149 | line='' 150 | buf='' 151 | last_line.each_char do |c| 152 | buf+=c 153 | if c=='+'||c=='*' 154 | if line.size+buf.size+1<=26 155 | line+=buf 156 | buf='' 157 | else 158 | lines << line.dup 159 | line='' 160 | end 161 | end 162 | end 163 | lines << line + buf 164 | 165 | lines.each_with_index do |line, i| 166 | if !tmpl[i].sub!('/'*line.size){line.chomp} 167 | raise "#{line} at #{i}" 168 | end 169 | end 170 | 171 | hist=(tmpl*'').gsub(/[ \n\/*]/, '') 172 | 173 | srand(27) 174 | 175 | H = tmpl.size / 2 176 | W = tmpl[0].size / 2 177 | H.times do |y| 178 | l = tmpl[y][0,W] 179 | l=l.gsub(/\/\/+(?= |$)/) do 180 | n=$&.size 181 | b='' 182 | if H-1!=y 183 | b='//' 184 | end 185 | pch=nil 186 | while b.size#{c}"}*'' + '' 296 | end 297 | tbl += '' 298 | 299 | convs = [] 300 | CONVS.sort_by{|o, c|o}.each{|o, c|convs << [o,*c.chars] if o != ' '} 301 | tbl = '' 302 | ['Original', 'Flip horizontally', 'Flip vertically', 'Rotate 180 degrees'].each_with_index do |h, i| 303 | tbl += "" 308 | end 309 | tbl += '
#{h}" 304 | convs.each do |a| 305 | tbl += " #{escapeHTML(a[i])}  " 306 | end 307 | tbl += "
' 310 | 311 | html=File.read('very_symmetric_tmpl.html') 312 | html.sub!('TBL', tbl) 313 | html.sub!('TMPL'){ 314 | c=File.read('very_symmetric.js') 315 | escapeHTML(c) 316 | } 317 | File.open('very_symmetric_js.html', 'w') do |of| 318 | of.print(html) 319 | end 320 | -------------------------------------------------------------------------------- /poly5_quine/poly_quine5.txt: -------------------------------------------------------------------------------- 1 | #include/*[ 2 | s='''*/ 3 | main(){char*_,*t;/*==;sub _:lvalue{$_};sub t:lvalue{$t}<