| Bytes | Lang | Time | Link |
|---|---|---|---|
| 001 | H🌍 | 250925T053710Z | CanonNi |
| 7242 | 230626T060503Z | Leo | |
| 166 | Setanta | 200826T133155Z | bb94 |
| 002 | Pyth | 250527T003829Z | Lucenapo |
| 038 | Python 3 | 250314T190802Z | 3RR0R404 |
| 529 | SAKO | 250314T161344Z | Acrimori |
| 003 | No. 3chars | 250224T194707Z | Oskar Kl |
| 053 | 32bit ELF Linux 6.11.7 | 250208T115526Z | Kamila S |
| 026 | Changeling | 250204T230906Z | Lucenapo |
| 056 | Python | 241213T191817Z | Username |
| 059 | AutoHotkey v2 | 241213T071038Z | Xuesong |
| 071 | Hatchback | 241211T043742Z | madeforl |
| 055 | BrainChild | 241101T030208Z | ATaco |
| 161 | Javascript Operators 161 Bytes | 240828T151214Z | ThePlane |
| 021 | PIO | 240930T070016Z | The Empt |
| 038 | JavaScript Node.js | 230929T025614Z | noodle p |
| 032 | Jellyfish | 221202T121233Z | angel_p_ |
| 003 | RProgN 2 | 170922T032818Z | ATaco |
| 074 | Befalse | 240620T070302Z | Bubbler |
| 022 | Easyfuck | 240325T160537Z | Quadrupl |
| 2273 | Positionally | 240313T051548Z | Mukundan |
| 016 | dc | 130419T062418Z | Geoff Re |
| 028 | Perl 5 | 120203T083934Z | Ilmari K |
| 050 | Haskell | 120325T165357Z | Aardvark |
| 004 | Vyxal 3 | 240103T045903Z | pacman25 |
| 115 | TypeScript's Type System | 231230T041523Z | noodle p |
| 061 | Pyret | 231230T030757Z | noodle p |
| 049 | JavaScript | 180207T140256Z | Dom Hast |
| 142 | HTML+JS data url | 231019T163214Z | FaniX |
| 093 | Python 3 | 231009T072519Z | The Empt |
| 014 | Uiua | 230930T000738Z | lyxal |
| 036 | CoffeeScript | 230929T022617Z | noodle p |
| 1869 | Headascii | 230914T093706Z | thejonym |
| 045 | Lua | 230914T141609Z | Luatic |
| 034 | FALSE | 230914T105004Z | Luatic |
| 009 | Nekomata | 230319T010016Z | alephalp |
| 006 | Thunno 2 j | 230502T142234Z | The Thon |
| 016 | ARBLE | 230315T030333Z | ATaco |
| 024 | ForWhile | 230725T083917Z | bsoelch |
| 5654 | Trilangle | 230725T020927Z | Bbrk24 |
| 034 | FALSE | 230725T002448Z | Joe |
| nan | Positionally | 230724T030153Z | Dadsdy |
| 039 | Thue++ 39 Bytes | 230720T214925Z | Dadsdy |
| 023 | Emacs Lisp | 230717T105741Z | Ed The & |
| 014 | ARM Thumb machine code + Linux syscalls | 230625T004147Z | landfill |
| 056 | Factor | 230628T233937Z | noodle p |
| nan | 230604T211651Z | Dadsdy | |
| 067 | Shasta v0.0.9 | 230604T145736Z | noodle p |
| 042 | Commodore C64 machine code 6502 using the Kernal noncompeting/just for fun | 230603T155139Z | Shaun Be |
| 060 | C | 170525T231026Z | MD XF |
| 117 | ReRegex | 230501T004338Z | ATaco |
| nan | 230213T100134Z | The Thon | |
| nan | 230104T131049Z | lyxal | |
| 026 | SQL Snowflake | 221230T165528Z | lad2025 |
| 602 | Functional | 221125T111158Z | angel_p_ |
| 022 | pl – Perl OneLiner Magic Wand | 201015T204949Z | Daniel |
| 013 | Javascript 13 Characters | 221205T193425Z | Shubshub |
| 330 | Whitespace | 221129T124338Z | angel_p_ |
| 167 | MySQL | 110206T091925Z | TehShrik |
| 020 | Bash | 161017T194828Z | LinusKro |
| nan | Fig | 221018T222725Z | naffetS |
| 035 | Knight v2.0alpha | 220918T042134Z | Sampersa |
| 004 | Atari BASIC. | 220915T091320Z | SE - sto |
| nan | Malbolge | 161216T052532Z | ATaco |
| 011 | RASEL | 220721T182522Z | Nakilon |
| 066 | SQLite | 220711T151512Z | Jakque |
| 062 | Pyxplot 0.8.4 | 220705T150105Z | Dingus |
| 542 | Scratch | 220608T030835Z | badatgol |
| 029 | Perl 5 + p0513 | 200626T120326Z | Dom Hast |
| 033 | !@#$%^&*_+ | 220417T173946Z | SuperPiz |
| 002 | tinylisp | 220417T175128Z | des54321 |
| 032 | Joy | 220415T023119Z | alephalp |
| 034 | Python 3 | 220304T000001Z | Zachary |
| 085 | Insitux | 220222T160224Z | jerbear4 |
| 001 | 7 | 161204T025509Z | user6213 |
| 149 | TypeScript Types | 201029T011902Z | tjjfvi |
| 037 | Zsh | 211225T173721Z | user |
| 040 | Zsh | 210531T075859Z | pxeger |
| 077 | OIL | 211207T125141Z | L3viatha |
| 004 | Vyxal 2.6.0 | 211128T130147Z | lyxal |
| 026 | Ruby | 201121T085832Z | Sisyphus |
| 028 | Pari/GP | 180309T172509Z | alephalp |
| 009 | K oK | 210805T091455Z | emanresu |
| 024 | ErrLess | 211023T073142Z | Ruan |
| 631 | JsonLogic | 211027T005855Z | cardboar |
| 066 | OCaml | 210915T191657Z | Maya |
| 042 | Grok | 210913T182219Z | Wheat Wi |
| 045 | ed1 | 201113T124455Z | roblogic |
| 350 | Alumin | 210819T061338Z | Jo King |
| 070 | ALGOL 68 Genie | 210817T065339Z | Jo King |
| 243 | Agony | 210817T054624Z | Jo King |
| 160 | Agda | 210817T015012Z | Jo King |
| 064 | Javastack | 210805T090341Z | emanresu |
| 012 | Vyxal D | 210730T085110Z | emanresu |
| 021 | Pxem esolangbox notation | 210723T063535Z | user1004 |
| 087 | Nim | 210708T185441Z | Adam |
| nan | Shakespeare Programming Language | 161016T055548Z | Oliver N |
| nan | Klein | 170518T170136Z | Wheat Wi |
| 010 | Unix Executable | 210613T122629Z | astroide |
| 022 | Knight | 210522T205341Z | EasyasPi |
| 021 | Red | 210609T082942Z | dingledo |
| 109 | 210326T073554Z | user1004 | |
| 013 | 05AB1E | 190613T114917Z | Grimmy |
| 008 | Vyxal | 201113T061848Z | lyxal |
| 013 | 05AB1E | 210529T212619Z | Makonede |
| 048 | Python 3 | 210523T072433Z | pan |
| 056 | AWK | 210522T182019Z | Pedro Ma |
| 057 | Vyxal | 210522T092449Z | emanresu |
| 021 | Adjust | 210507T230129Z | caird co |
| 018 | Jq rn | 210417T235720Z | Wezl |
| 038 | Perl 5 | 180215T153620Z | mik |
| 024 | Perl 5 | 210218T123734Z | mik |
| 032 | PHP r | 210203T194922Z | Dom Hast |
| 090 | Groovy | 110608T125006Z | Ant' |
| 054 | convey | 210201T034135Z | Jo King |
| 041 | R | 200804T152733Z | Robin Ry |
| 202 | Swift 5 | 201113T042935Z | BaseZen |
| 620 | Assembly NASM | 201016T204540Z | Petr Fie |
| 117 | C++ | 170113T150350Z | Ralph Ta |
| 070 | C gcc | 201016T000438Z | Petr Fie |
| 011 | JavaScript ES6 | 201015T221803Z | Petr Fie |
| 043 | Stax packed | 201011T163243Z | wastl |
| 052 | Labyrinth | 200928T121428Z | Jo King |
| 1713 | beeswax | 151228T191633Z | M L |
| 911 | √ å ı ¥ ® Ï Ø ¿ | 170313T191441Z | caird co |
| 029 | anyfix | 200926T143031Z | Jo King |
| 014 | Add++ i | 170828T165333Z | caird co |
| 019 | Adapt | 200921T103209Z | Jo King |
| 038 | Whispers v2 | 191009T210500Z | Jo King |
| 270 | Acc!! | 200920T131406Z | Jo King |
| 089 | ABC | 200920T113430Z | Jo King |
| 3101 | 4 | 200919T130418Z | Jo King |
| 024 | 33 | 200919T013638Z | Jo King |
| 010 | 2sable | 200919T010017Z | Jo King |
| 853 | 2DFuck | 200918T105020Z | Jo King |
| 016 | ShapeScript | 151108T004338Z | Dennis |
| 009 | Pushy | 161117T173134Z | FlipTack |
| 004 | V | 161119T042659Z | DJMcMayh |
| 015 | 200918T003359Z | Jo King | |
| 014 | *><> | 200917T133412Z | Jo King |
| 3560 | 200917T130126Z | Jo King | |
| 021 | Perl 5 | 200917T125708Z | mik |
| 038 | !@#$%^&*_+ | 200917T022626Z | Jo King |
| 060 | MAWP | 200816T052036Z | Dion |
| 105 | Bubblegum | 200901T064421Z | Sisyphus |
| 022 | APL | 160130T060104Z | Alex A. |
| 012 | Integral | 200805T040829Z | lyxal |
| 056 | FEU | 200804T140101Z | PkmnQ |
| 066 | Aceto | 200804T114226Z | L3viatha |
| 241 | Minecraft Java Edition | 200705T003131Z | jm8 |
| 058 | Common Lisp | 200622T202416Z | Wezl |
| 190 | Python 3 | 200601T063555Z | Smiley10 |
| 008 | tq | 191231T105011Z | user8505 |
| 314 | Hexagony | 180220T134348Z | user2027 |
| 392 | brainfuck | 160103T193357Z | user4264 |
| 1043 | Ral | 200419T085247Z | Endenite |
| 133 | Javascript | 200408T135835Z | Odog8 |
| 013 | W | 200128T030719Z | user8505 |
| nan | Unary | 200128T025029Z | Josh Din |
| 004 | Keg | 191101T231154Z | lyxal |
| 008 | Pyth | 191108T220332Z | Edgex42 |
| 036 | Symbolic Raku | 191230T075610Z | Jo King |
| 054 | BaCon | 161013T201945Z | Peter |
| 021 | JavaScript REPL | 110421T180702Z | Ry- |
| 1896 | Poetic | 191104T140221Z | JosiahRy |
| 299 | Alchemist | 191104T040345Z | Jo King |
| 287 | Wren | 191029T140503Z | user8505 |
| 330 | Klein | 191023T103544Z | Jo King |
| 024 | Tir | 191017T131120Z | user8505 |
| 011 | Corea | 191010T012337Z | Conor O& |
| 338 | Whitespace | 191008T022851Z | Jo King |
| 834 | 1+ | 191008T112042Z | Jo King |
| 3748 | 1+ | 191005T182140Z | dzaima |
| 021 | Keg | 191002T002059Z | Jo King |
| 043 | Keg | 191001T044444Z | Unrelate |
| 035 | Perl 5 | 190920T152210Z | rpGYNay0 |
| 261 | Hexagony | 190920T042217Z | Jo King |
| 031 | Amazon Alexa | 190311T091650Z | Jo King |
| 006 | Fission | 150529T093528Z | Martin E |
| 021 | Javascript REPL | 190731T205833Z | Kenzie |
| 027 | Ruby | 170612T170357Z | Nnnes |
| 026 | 33 | 190718T065415Z | TheOnlyM |
| 353 | C | 190802T004837Z | T. Salim |
| 085 | C gcc | 190802T220008Z | jxh |
| 023 | Pip | 190802T175749Z | Kenzie |
| 515 | Java | 190626T025650Z | Ethan Ga |
| 057 | C# Visual C# Interactive Compiler | 190614T171034Z | dana |
| 078 | A Classic Lisp | 110511T220656Z | arrdem |
| 135 | Fob | 110128T094026Z | Hiato |
| 084 | Brian & Chuck | 190531T094733Z | Dorian |
| nan | Golunar | 190527T111118Z | Dorian |
| nan | Fueue | 190525T073237Z | jimmy230 |
| 047 | Tcl | 190518T184708Z | jimmy230 |
| 066 | Rust | 190518T180808Z | Maya |
| 012 | Brachylog v2 | 190415T052227Z | Unrelate |
| 036 | Perl 6 | 160826T002517Z | bb94 |
| 067 | Tamsin | 190310T044908Z | Esolangi |
| 016 | Aubergine | 190220T164406Z | ASCII-on |
| 036 | Muriel | 190213T033356Z | Jo King |
| 102 | Clean | 161018T101520Z | user4268 |
| 041 | Attache | 180123T172759Z | Conor O& |
| 589 | Alchemist | 190131T015936Z | Jo King |
| 006 | Gol><> | 190205T184951Z | KrystosT |
| 076 | !@#$%^&*_+ | 190108T230654Z | Conor O& |
| 071 | Tidy | 190108T212447Z | Conor O& |
| 018 | APL Dyalog Unicode | 190107T072940Z | Adá |
| 032 | Julia 1.0 | 190106T105417Z | H.PWiz |
| 030 | Symbolic Python | 181215T050911Z | Jo King |
| 027 | Perl 6 | 181121T070433Z | Jo King |
| 406 | Whitespace | 180416T114917Z | Kevin Cr |
| 009 | MathGolf | 181004T061919Z | Jo King |
| 007 | Runic Enchantments | 181001T182138Z | Draco18s |
| 103 | Pascal FPC | 181001T151316Z | AlexRace |
| 006 | Runic Enchantments | 180927T060059Z | Jo King |
| 044 | Elixir | 180919T094031Z | Kirill L |
| 021 | Backhand | 180916T062212Z | Jo King |
| 094 | Flobnar | 180910T061654Z | Jo King |
| 020 | J REPL 20 16? char | 140426T183149Z | algorith |
| 027 | J | 180907T052110Z | Bubbler |
| 010 | Cardinal | 180420T115433Z | Jo King |
| 017 | Excel | 180905T111621Z | seadoggi |
| 120 | Z80Golf | 180810T012449Z | Bubbler |
| 008 | Ahead | 180731T070654Z | snail_ |
| 030 | Noether | 180726T131634Z | Beta Dec |
| 1289 | 2DFuck | 180507T182941Z | wastl |
| 103 | Yabasic | 180705T131807Z | Taylor R |
| 077 | VBA | 180705T130835Z | Taylor R |
| 096 | Foo | 180331T191100Z | Conor O& |
| 021 | Javascript REPL | 180608T130412Z | Carles C |
| 012 | MATL | 161023T025513Z | Luis Men |
| nan | Shakespeare Programming Language | 180530T155755Z | user2027 |
| 005 | Gol><> | 180401T074229Z | Bubbler |
| 095 | Nim | 180525T125456Z | Kirill L |
| 022 | Befunge93 | 180319T035037Z | Jo King |
| 4222 | Reflections | 180516T163333Z | Jo King |
| 9228 | Reflections | 180511T201033Z | wastl |
| 030 | Python 2 | 110128T085602Z | hallvabo |
| 147 | PHP | 180427T164003Z | Boian Iv |
| 004 | Jstx | 180401T075220Z | Quantum6 |
| 423 | Fueue | 180420T071817Z | Ørj |
| 2009 | PainFlak | 180410T012429Z | Nitrodon |
| 1805 | BrainFlak | 170930T004948Z | Nitrodon |
| 066 | Lost | 180206T135511Z | Jo King |
| 004 | Stax | 180224T055416Z | Weijun Z |
| 041 | Haskell | 180402T020300Z | Ørj |
| 054 | SmileBASIC | 170130T141751Z | 12Me21 |
| nan | BrainFlak | 161004T052420Z | Wheat Wi |
| nan | Reflections | 180325T003822Z | Jo King |
| nan | Befunge93 | 180319T051218Z | jimmy230 |
| nan | Cubically | 180317T222825Z | jimmy230 |
| 050 | HTML + CSS 118 78 77 75 53 51 | 121120T120605Z | null |
| 276 | ColdFusion | 180319T144554Z | Dom Hast |
| 985 | Dodos | 180315T205121Z | Dennis |
| 063 | Swift 4 | 180317T110438Z | Endenite |
| 006 | DipDup | 170114T063642Z | alephalp |
| 009 | Japt | 180221T154617Z | ETHprodu |
| 108 | Rust | 180218T133636Z | null |
| 383 | Hexagony | 180210T120019Z | Jo King |
| 528 | Java | 110412T003218Z | user unk |
| 120 | Swift 4 | 180214T215438Z | osuka_ |
| 010 | Underload | 180212T135419Z | Wurlitze |
| 018 | Bash + coreutils | 160906T224934Z | jimmy230 |
| 009 | Wumpus | 180210T122102Z | Martin E |
| 048 | Bash | 180207T163919Z | Dom Hast |
| 201 | Locksmith | 180206T155719Z | Conor O& |
| 249 | Lost | 170810T222612Z | Wheat Wi |
| 015 | Operation Flashpoint scripting language | 170504T151411Z | Steadybo |
| 008 | ><> | 171220T073911Z | Jo King |
| 020 | Implicit | 170922T020328Z | Dennis |
| 007 | Retina | 151222T212232Z | Martin E |
| 064 | Awk | 170524T220522Z | MD XF |
| 392 | Java 8 | 180109T154825Z | the_evic |
| 021 | Aubergine | 161023T060007Z | Oliver N |
| 021 | Funky | 171220T015822Z | ATaco |
| 007 | Chicken | 140110T233005Z | Timtech |
| 088 | tinylisp | 170101T080951Z | DLosc |
| 020 | OML | 171019T023817Z | Conor O& |
| 022 | JavaScript ES6 REPL | 170102T173622Z | user6403 |
| 026 | JavaScript ES6 | 140913T132633Z | Optimize |
| 1221 | Bob | 170525T005340Z | MD XF |
| 515 | ABAP | 170524T220904Z | MD XF |
| 028 | shortC | 170524T180657Z | MD XF |
| 074 | MaybeLater | 170922T025514Z | ATaco |
| 970 | Taxi | 170911T201604Z | Luke |
| 064 | C tcc | 170911T193020Z | user5898 |
| 028 | Octave | 170829T143844Z | Stewie G |
| 042 | ><> | 170828T191539Z | Sasha |
| 030 | Proton | 170817T193542Z | totallyh |
| nan | 151031T230246Z | ETHprodu | |
| 050 | PHP | 170814T125019Z | Umbrella |
| 010 | Gaia | 170803T144859Z | Business |
| 062 | C gcc | 170725T041740Z | Conor O& |
| 015 | Foam | 170708T180049Z | Esolangi |
| 017 | Zsh | 170702T083627Z | jimmy230 |
| 175 | JScript | 170630T224745Z | Conor O& |
| 008 | Husk | 170625T180404Z | Leo |
| 045 | Alice | 170624T021600Z | Nitrodon |
| 094 | Mathcad | 150131T074441Z | Mints97 |
| nan | Triangular | 170612T021141Z | Wheat Wi |
| 005 | Micro | 170610T184538Z | raddish0 |
| 008 | QBIC | 170607T204249Z | steenber |
| 054 | Python 3 | 140406T211002Z | Evpok |
| 048 | Groovy | 170601T155648Z | totallyh |
| 121 | Kotlin | 170601T153834Z | totallyh |
| 112 | Go | 170531T163057Z | totallyh |
| 007 | Conway's Game of Life | 170526T001527Z | MD XF |
| 052 | Bash | 170526T144430Z | MD XF |
| 131 | Excel | 170526T145119Z | MD XF |
| 027 | Vim | 170526T031805Z | MD XF |
| nan | COBOL | 170525T010316Z | MD XF |
| 204 | /// | 170525T043227Z | Ørj |
| 154 | Ceylon | 170525T005734Z | MD XF |
| 041 | ACL2 | 170524T220746Z | MD XF |
| 161 | Babel | 170524T175840Z | MD XF |
| 561 | 80x86 TASM | 170523T160003Z | MD XF |
| 4619 | x86/DOS assembly | 170523T155854Z | MD XF |
| 054 | Turtlèd | 161022T050516Z | Destruct |
| 032 | Charcoal | 170519T100529Z | Destruct |
| 009 | ><> | 170517T033215Z | Conor O& |
| nan | Klein | 170519T071836Z | Martin E |
| 020 | Ohm | 170509T160546Z | Riley |
| 011 | GNU Make | 170514T155927Z | eush77 |
| 016 | dc | 170514T153823Z | eush77 |
| 060 | Standard ML MLton | 170514T094939Z | Laikoni |
| 105 | Forth | 170510T144130Z | mbomb007 |
| 404 | Brainfuck | 170502T203551Z | Luke |
| 060 | Hack | 170428T143140Z | Mayube |
| 026 | Brachylog 2 | 170426T222253Z | user6213 |
| 020 | Cubix | 170424T214036Z | Luke |
| 024 | PowerShell | 170426T153529Z | wubs |
| 008 | Befunge98 cfunge | 170425T032528Z | user6213 |
| 009 | Alice | 170412T190141Z | Martin E |
| 065 | Bash | 140221T190235Z | Kevin |
| 068 | Mathematica | 120203T163053Z | celtschk |
| 091 | Clojure | 110609T124147Z | mikera |
| 540 | Scala | 170314T084224Z | Stefan A |
| 066 | Forte | 170127T030515Z | ATaco |
| 014 | Vim | 160909T005653Z | DJMcMayh |
| 048 | k | 170223T205806Z | zgrep |
| 072 | AWK | 170223T203400Z | Robert B |
| 015 | Pip | 170130T060135Z | DLosc |
| 090 | Racket | 170122T224406Z | Matthew |
| 006 | ಠ_ಠ | 151105T051412Z | Mama Fun |
| 085 | Threead | 170113T002404Z | Riley |
| 101 | Threead | 170116T195010Z | user6213 |
| 017 | Befunge93 | 170113T223637Z | osuka_ |
| 024 | Threead | 170113T012800Z | ATaco |
| 1086 | Logicode | 170112T232026Z | Wheat Wi |
| 047 | R | 170105T161405Z | JAD |
| 085 | D | 110625T142408Z | ratchet |
| 6900 | MiniFlak | 161208T233715Z | Wheat Wi |
| 038 | Python 3 | 170101T134211Z | wizzwizz |
| 056 | SimpleTemplate | 161230T175134Z | Ismael M |
| 094 | Java 8 | 161230T160414Z | FlipTack |
| 014 | Pyke | 161230T135506Z | Blue |
| 021 | Forth gforth | 161228T171113Z | 2xsaiko |
| 004 | Actually | 161225T154108Z | Dennis |
| 007 | Haystack | 161222T094209Z | user4180 |
| 056 | Cheddar | 161222T052335Z | Conor O& |
| 016 | stacked | 161221T011139Z | Conor O& |
| 013 | Zetaplex | 161220T025344Z | Riker |
| 045 | Cubix | 161218T080403Z | user6213 |
| 003 | RProgN | 161215T204703Z | Dennis |
| 414 | BotEngine | 161211T175109Z | SuperJed |
| 054 | JavaScript | 160907T011614Z | ETHprodu |
| nan | 110128T011512Z | Nakilon |
(,), 8167 7594 7402 7242 Chars
((),()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),()()()())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),()()()())(((),(())()),)(((),(())()),)(((),(())()),)(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())((()),((()())))((),()()())(()(),(()())(())()(),,,(),,(())(())()())(,,,(()()),(),,()())(,,,(()(),,,(()())())(())())(,,,(()(),,,(()()))(),(),,(()))(,,,(()())())((,,,(()()),(),,()()())(,,,(()(),,,(()())())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())(,,,(()(),,,(()()))(),(),,((())))((),(())(),,(()())()),,,,((())))((),()()())((),(())(),,((()))(()()),((())))
Thanks to some golfs (and help from Dadsdy herself) now fits in a link!
I wanted to golf Dadsdy's submission but I couldn't really understand the implementation of the decoder, so I've ended up writing a new submission from scratch.
Edit: reverted one golf because the interpreter changed and broke it; I've managed to nest some print statements however, which ended up in a lower bytecount anyway!
Edit: new golf suggested by Dadsdy cuts 160 more bytes!
Explanation
A typical quine strategy, the first part encodes the second part of the code, and the second part prints the encoded version followed by the unencoded one.
I'm using the variable at address 1 (var1) as a pointer, going through the characters of the quine one by one. var2 will contain the ascii code for an open bracket ((, 40), while closed bracket (), 41) and comma (,, 44) will be printed by adding 1 and 4 respectively to that number. Variables from 3 onward will contain the encoding of the quine.
((),()()())
Set var1 to 3
((),(())())....(((),(())()),())
Encode all the code after this part:
(((),(())()),) is an open bracket
(((),(())()),()) is a closed bracket
(((),(())()),()()()()) is a comma
this sets each memory address in order to 0, 1, or 4 to match the following code.
((()),((()())))
Set the memory address after the end of the data to -1
((),()()())
Reset var1 to 3
(()(),(()())(())()(),,,(),,(())(())()())
Set var2 to 40 (5*8)
(,,,(()()),(),,()())(,,,(()(),,,(()())())(())())(,,,(()(),,,(()()))(),(),,(()))(,,,(()())())
Print ((),()()()), the first instruction of the quine which was not included in the encoded part
((,,,(()()),(),,()()())(,,,(()(),,,(()())())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())(,,,(()(),,,(()()))(),(),,((())))((),(())(),,(()())()),,,,((())))
For each variable in memory print the corresponding encoding
(this will print the encoded part of the quine)
((),()()())
Reset var1 to 3
((),(())(),,((()))(()()),((())))
For each variable in memory, print the corresponding character
(this will print the unencoded part of the quine)
text = `((()),((()())))((),()()())(()(),(()())(())()(),,,(),,(())(())()())(,,,(()()),(),,()())(,,,(()(),,,(()())())(())())(,,,(()(),,,(()()))(),(),,(()))(,,,(()())())((,,,(()()),(),,()()())(,,,(()(),,,(()())())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())(,,,(()(),,,(()()))(),(),,((())))((),(())(),,(()())()),,,,((())))((),()()())((),(())(),,((()))(()()),((())))`;
text = text.replace("\n","").replace("\r","")
output = "((),()()())";
inc = "((),(())())"
for (let c of text){
output += c=="(" ? `(${inc},)` : c==")" ? `(${inc},())` : `(${inc},()()()())`;
}
output += text
out1.innerHTML = output.length + " chars"
out2.innerHTML = output
<h1 id=out1></h1>
<p id=out2></p>
Setanta, 254 166 bytes
−88 bytes by using a loop instead of repeated calls to athchuir (= replace)
s:="t:='s:=\"'le i idir(0,77){c:=s[i]t+=(c=='\\\\'|c=='\"'&'\\\\'+c)|c}scriobh(t+'\"'+s)"t:='s:="'le i idir(0,77){c:=s[i]t+=(c=='\\'|c=='"'&'\\'+c)|c}scriobh(t+'"'+s)
This was pretty long, mainly because Setanta doesn't have any string formatting builtins. Probably could still be improved.
Pyth, 2 bytes
()
The opening bracket encodes both brackets, while the closing bracket encodes nothing:
(
outputs
()
Python 3, 38 bytes
S=";print(f'{S=}'+S)";print(f'{S=}'+S)
f-strings are pretty cool, basically giving you the hard part for free here
SAKO, 529 bytes
CALKOWITE:*T,I
TABLICA(126):T
40 25 31 39 40 43 29 25 38 39 46 45 50 58 23 21 32 31 35 43 29 40 25 11 5 40 10 29 58 40 21 22 32 29 23 21 3 49 50 54 6 11 40 58 5 49 6 24 38 41 31 41 30 3 48 6 11 40 3 29 6 58 36 35 43 40 35 38 46 11 29 13 48 3 49 6 49 50 54 58 32 29 34 29 21 58 40 25 31 39 40 58 5 58 32 29 34 29 21 58 24 38 41 31 41 30 43 29 25 38 39 46 11 40 58 39 40 35 36 49 58 31 35 34 29 25 23
*
TEKSTWIERSZY2
CALKOWITE:*T,I
TABLICA(126):T
*1)DRUKUJ(0):T(I)
POWTORZ:I=0(1)126
LINIA
TEKST
*
LINIA
DRUKUJWIERSZ:T
STOP1
KONIEC
This probably isn't the shortest possible quine, as I golfed it from my first ever SAKO quine, but it's the shortest one I came up with.
No. 3chars
No.
What is No.
No is a language that ignores the code and outputs "No."
Try it online here
32-bit ELF (Linux 6.11.7), 53 bytes.
% ./a.out | xxd
00000000: 7f45 4c46 0100 0000 0000 0000 0000 0100 .ELF............
00000010: 0200 0300 2e00 0100 2e00 0100 0400 0000 ................
00000020: b004 b235 cd80 584b cd80 2000 0100 4341 ...5..XK.. ...CA
00000030: c1e1 10eb eb .....
% xxd ./a.out
00000000: 7f45 4c46 0100 0000 0000 0000 0000 0100 .ELF............
00000010: 0200 0300 2e00 0100 2e00 0100 0400 0000 ................
00000020: b004 b235 cd80 584b cd80 2000 0100 4341 ...5..XK.. ...CA
00000030: c1e1 10eb eb
AutoHotkey (v2), 59 bytes
Looks like the first AHK answer!
MsgBox Format(s:="MsgBox Format(s:={:c}{}{1:c},34,s)",34,s)
Hatchback, 97 85 71 bytes
0
0
255
0
1
1
0
3
65534
2
3
1
11
2
0
1
2
2
0
1
14
2
3
6
2
65281
8
65535
This is half-cheating(?) as it's technically not reading the source file.
Program data in Hatchback is loaded in a RAM block to be run, which can be read and copied in the program itself. So it's reading from a RAM block and NOT the source file
this is the first quine i've written (ever) so it feels nice to cross that off my coding bucket list
Javascript Operators: 161 Bytes
-1: removed some unnecessary tokens
I wanted to make one of these with just JS operators (and one character)
What I count as an operator: +-*/^&~|=<>()[]{}?., (+ combination)
One character I used that isn't an operator: _
Full character set: +-*/^&~|=<>()[]{}?.,_
(_=(__=(-~[]|-~[]-~[]),___=((_=>(_=_))+[]),____=___[__],______=___[__-~[]],_______=___[__-~[]-~[]],_____=___[__+++__])=>____+______+_______+_+_____+____+_____)()
Semi-explanation:
_2=(-~[]|-~[]-~[]) // 3 (-~[] = 1, 1|2 = 3)
_3=((_=>(_=_))+[]) // "_=>(_=_)" (converts a function to a string)
_4=_3[_2] // "("
_6=_3[_2-~[]] // "_"
_7=_3[_2-~[]-~[]] // "="
_5=_3[_2+++_2] // ")"
(_=()=>_4+_6+_7+_+_5+_4+_5)() // (_=()=>"(_="+_+")()")
Further explanation:
Numbers:
Numbers can be expressed in multiple ways.
-1: ~[]
1: -~[]
2+: -~[]-~[]-~[]...-~[]
4: -~[]<<-~[]-~[]
10: []+-~[]+-[]
etc.
Strings/Characters:
Strings are normally made by converting a function/object to a string, then slicing.
"_=>(_=_)": (_=>(_=_))+[]
char of str: str[charIdx]
"_": slice (_=>(_=_))+[]
etc.
This can most definitely be improved, and I welcome all of you to try it! Good luck!
PIO, 21 Bytes
I hate input errors!
Note the trailing newline. As a bonus, this 34 byte program also works:
Oh dear! No useful programs here!
Also note the trailing newline.
JavaScript (Node.js), 38 bytes
console.log(s='console.log(s=%o,s)',s)
This seems to be the shortest JavaScript quine that doesn't abuse function stringification. Unfortunately seems to be platform-specific: it works as-is in both Chrome and Node.js, but in Safari the single quotes must be replaced with double quotes.
This uses the %o formatting directive of console.log to insert a JSON-stringified object, which in this case wraps the string in single quotes.
In a strict-mode setting like Deno, you need to declare var s; at the start:
var s;console.log(s="var s;console.log(s=%o,s)",s)
Bun doesn't seem to support the %o directive in any form.
Jellyfish, 67 53 32 bytes
P-vP,"Hi<H(V3|V2b(
Bc6B"P-vP,\"
apply a minor update (other than the score);
avoid non-printable characters such as NUL or ACK in the previous code.
Try it online!
Try the 32B with non-printable chars online!
Try the 53B version online!
Try the 67B version online!
RProgN 2, 3 bytes
«Ø
This code does nothing with the first line, then, pushes the function «Ø. As « is unmatched, it falls through and executes the contents. Ø then pushes an empty string. The implicit printing behaviour first prints the empty string, then the function, giving our source code.
4 bytes
«•.
(With a leading space)
This uses the fall through behaviour of the last quine, but ensures "quine" behaviour a different way. • pushes a space, . concatenates it, which gives our code.
6 bytes
{`{.}{
This uses a different fallthrough behaviour. {`{.} pushes a function, then {, with an unmatched }, fails and moves the IP back to index 1, which skips the function definition, and runs its contents instead. (backtick){ pushes { as a string, then . appends it to the function, stringifying it. } then terminates the program, and the string is implicitely output.
Befalse, 74 bytes
0:"(48.(58.(34.::::::::: .$?;(34.(59./.95(.43(;?$. :::::::::.43(.85(.84(";
Trying to create a one-line quine in Befalse was quite challenging.
- The IP does not wrap around the grid like Befunge or Fish.
- Since all we have are mirrors
/and\, redirection is impossible, and IP must always go right. :(call) and;(return/halt) exist, which allow to run a section of code a certain number of times like this, but in this case we need to somehow output more (";part) after entire string is printed.
(It is possible to exploit interpreter-specific features and bugs, but I wanted to keep things "pure" for this one.)
In order to escape the "loop", I put a sentinel 0 below the string, and used $? (dup; skip if zero) before ;. At this point, the loop is escaped, but there might be some return addresses left, so we can't use ; to halt; a mirror is used instead to direct the IP out of the grid, which also halts the program.
The string is printed backwards, so I palindromized the string.
0 Push a sentinel zero at the bottom
:"..."; Push a string, and then start executing the content of the string
(one char after `:` is skipped on return)
(48. Print `0` (there's no command for printing a number)
(58. Print `:`
(34. Print `"`
::::::::: Setup a "call loop" so it runs enough times to print everything
.$?; Print the top char; escape the loop when top is 0
(34. Print `"`
(59. Print `;`
/ Direct IP to outside of code, halting the program
Befalse (quirkster), 37 bytes
0:"$.\;/?$\!%.$43(^
!.-1^/ \{:/}.;0";
There is a "bug" in the interpreter that in string mode, if the IP hits the end of line, it pushes the newline character and continues to the next line instead of halting. This allows a proper loop to be embedded within a single string.
Also, the interpreter page kindly has an example that prints a string left to right, so we can utilize that.
0"Hello world!"!/$?\#;
;.}\:{/
Figuring out how it works is left as an exercise to the reader.
0:"..."; The same gadget as the one-line quine
$. Dup and print `0`
^1-. Over (copy the 2nd top of stack which is `;`), subtract 1 and print `:`
! "Skip" the newline
^ Copy `;` again
(34$. Print `"` and leave a copy on the stack
% Swap `"` and `;` so they are printed in the correct order in the end
;/?$\!
\{:/}.; Adapt the "Hello world" example to print the entire stack and halt
Easyfuck, 25 22 bytes
¶ąőÖ‹ĄU¶ąőŘ␖×>şŃt޶×>ş
Decompressed:
[.>]4.JU[.>]@[.>]4.JU[.>]
[.>]4.JU[.>]@[.>]4.JU[.>]
[ ] [ ] while loops
.> .> print char and go to the next cell
4. set the cell to @ (64 = 4*16) and print it
JU go to the first cell and remove the last
@ end the program
[.>]4.JU[.>] initializer data
Positionally, 2273 bytes
QQ
/ 1 \/ \
> ^
^ + <
> : v> P v
;<
\ /
\ /
/ \
^ > |
^ <
> : v> v
s /\
> \
\ 1 \/ \ \ 2 \/ \
> b ^ > ^
^+ < <^ - <
> : v > v> "" " v > P v
s / \
^ /
\ \ / \
> & ^
^ % <
> : v
\ / /\
\ 5 \
^ % <
> P v
\ / s /
^ /
P P"!O␟␟␟O␉ ␉␉␉␉.␟␟ ]␟␟␟␟␟␟ ␟␟␟␟␟␟␉ .␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ r␟␟.␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟[␟ ␟␟␟␟␟␟␟ ␉␉u␟␟␟␟ O␟=␟␟␟␟ ␟␟␟␟␉;␟ ␟$␟␟␟]␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␉ ␉[␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟4␟␟ ␟␟␟␟[␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␉␉␉[. ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟.␟␟␟ ␟␟␟[␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␉ ␉u␟␟9␟␟ ␟=␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␉ ;␟␟$␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟]␟␟␟␟ ␟␟␟␟␉]␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟%␟␟␟␟ =␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␉[␟␟ ␟␟␟␟.␟␟ ␟␟␟␟␟␟[ ␟␟␟␟␟␟␟ [␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␉␉.␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟] ␟␟␟␟␟␟␟ ␟␟␟␟␟␉[ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟.␟␟␟␟ r␟␟␟␟␟␟ ␟␟␟␟␉␉u ␟␟␟␟O␟= ␟␟␟␟␟␟␟ ␟u␟!␟␟␟ ␟␟␟!!␟␟ ␟␟=u␟␟␟ ␟␟␟=␟␟␟ ␟␟␟␟␟u␟ ␟9␟␟␟=␟ ␟␟␟␟␟␟␟ ␉;␟␟␟␟, ␟];␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟;␟ ␟␟␟␟*]␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␉]␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟=␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟] ␟␟␟␟␟␟␟ ␟␟␟␟a␟␟ =␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␉[␟␟ ␟␟␟␟.[␟ ␟␟1␟␟␟[ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟[␟␟␟␟␟ ␟.[␟␟␟␟ 0␟␟[␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␉[ ␟␟=␟␟␟␟ ␟␟␟␟␟␟␟ ␟␉␉[.␟␟ ␟␟r␟␟␉␉ u␟␟␟␟␟␟ =u␟␟9␟␟ ␟=␉;␟␟␟ ␟␟␟]␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␉ {␟␟␟␟␟= ␟␟␟␟␟␟␟ ␟]␟␟␟␟␟ ␟␟␉[␟␟␟ ␟␟␟.␉␉. ␟␟␟␟␟␟[ ␉.␟␟␟␟␟ ␟[␟␟␟␟␟ ␟␟␟␉;:␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␉u␟␟␟␟ O␟=u␟␟␟ ␟␟␟␟␟␟␟ 9␟␟␟=␉; ␟␟␟␟␟*␟ ␟␟␟␟␟␟␟ ]␉]␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟␟␟␟ ␟␟␟␟=␉[ ␟␟␟␟␟␟. [␟␟␟␟0␟ .␟␟␟␟␟␟ ␟␟␉
Note: Unprintable characters and tabs are replaced with symbols from the Unicode Control Pictures block for clarity. For functional code, use the "Try it Online" link.
Explanation
The main idea is to maintain an encoded program string at the bottom, outputting its decoded version and pushing the encoded form onto the global stack, before ultimately displaying the global stack.
Caveats
- The encoded version must not contain spaces as the interpreter ignores them. For instance, the encoding used here reduces each ASCII value by 1, prohibiting the use of
!since! (33) - 1 = space (32). - The encoded version needs to be spaced every 8 characters when including it in the program to avoid exiting string mode, as every 8 characters trigger the " command, which toggles string mode on and off. Spaces are used to maintain string mode continuously.
- Because the encoded version is spaced every 8 characters, logic must be added to output a space every 8 characters when printing the global stack.
Perl 5, 30 28 bytes
printf+(q(printf+(q(%s))x2))x2
I first posted this one years ago to the Fun With Perl mailing list, and I've been quite fond of it ever since.
You can save two characters if you use qw instead of q:
printf+qw(printf+qw(%s)x2)x2
TypeScript's Type System, 115 bytes
type Y="'";type A='type O=`type Y="${Y}";type A=${Y}${A}${Y};${A}`';type O=`type Y="${Y}";type A=${Y}${A}${Y};${A}`
This beats tjjfvi's 149 byte quine.
Pyret, 72 61 bytes
a="\nprint('a=' + torepr(a) + a)"
print('a=' + torepr(a) + a)
No, I can't remove the spaces surrounding the +
I'm learning a little Pyret because my brother is taking a coding class where this is being taught and he wanted me to help him learn.
JavaScript, 49 bytes
A quine without any uses of uneval or Function.prototype.toString.
eval(Q="q=Q.link()[8];alert(`eval(Q=${q+Q+q})`)")
Can avoid use of template strings for + 1 byte.
eval(Q="q=Q.link()[8];alert('eval(Q='+q+Q+q+')')")
JavaScript, 74 bytes
Another approach avoiding uneval and Function.prototype.toString:
console.log(a="console.log(a=%s%s%s,q=a.link()[8],a,q)",q=a.link()[8],a,q)
HTML+JS (data url), 142 bytes
data:text/html,<pre id="a"></pre><script>!function f(){a.innerText=`data:text/html,<pre id="a"></pre><script>!`+f+"()</scr"+"ipt>"}()</script>
This requires no "extra environment", just paste it into the browser address bar.
common version, 112 bytes
<pre id="a"></pre><script>!function f(){a.innerText=`<pre id="a"></pre><script>!`+f+"()</scr"+"ipt>"}()</script>
Python 3, 93 bytes
Note the trailing newline.
f=lambda x:chr(34).join([x,x,'))']);print(f("f=lambda x:chr(34).join([x,x,'))']);print(f("))
Inspired by Vyxal’s I builtin.
This quine isn’t winning any challenges, but it’s still a quine!
Uiua, 14 bytes
&s&pf."&s&pf."
RTL evaluation made this way more easier than it could have been.
Explained
&s&pf."&s&pf."
"&s&pf." # Push the string "&s&pf."
. # Duplicate it
&pf # Print without newline
&s # Print repr version
💎
Created with the help of Luminespire.
CoffeeScript, 36 bytes
console.log s='console.log s=%o,s',s
This was intended to be a Civet quine, but it turns out it's a polyglot with CoffeeScript and there isn't a CoffeeScript quine here yet.
This uses the %o formatting directive of JavaScript to print a value as JSON, wrapping the string s in single quotes. This would also make a 38 byte JS quine.
Headascii, 41821869 bytes
+OU+++++++++OU++++++++++++++OU+OU+OU+OU+OU+OU++++++++++OU++++OU++++OU++++OU++++OU++++++++++OU++++OU++++OU++++++++++OU+++++++OU++OU+++OU+++++++OU+++++++++++++++OU+++++OU++++OU++++OU+++++++++++++OU+++++++++++OU+OU+OU+OU+OU+OU+OU+++++++++++OU++++++OU++++OU+OU+OU+OU+++++++++++OU++++++++++++++++OU+++++++++++++OU++++++++OU++++++++++++OU+++++++++++++++++OU+++++OU++++++++OU++++++OU+OU+OU+++++++++OU++++++++++++++OU++OU+++++OU++++++++++++++++++++OU+++++++++++++OU+++++++++OU++++++OU++++++++++++++++++OU++++++++++OU+++++++OU++OU+++OU+++++OU++++++OU++++++++OU++++++++++++OU+++++++OU++OU+++OU++++++++++++++++OU+OU+++++++++++++++OU+++++++++++++++++++OU++++OU+++++OU++++++++++++++++++OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+++++++++++OU++++++OU++++++++OU++++++++++++OU+++++++OU+++++++++++++++++OU+++++++++++++++++++OU+++++OU++OU+++OU++++++OU+OU+++++++++OU++++++++++++OU++++++++OUOU++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++OU+++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++OU++++++++++++OU+++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++OUOU+E.+++++[]]]][]][{UO{^)]]-P++++++P:]+++PD-};N)}:++E.U)!-E:R[{UO):};{UOD+^(])R+++++++++++++++++++++++++++++++++P:};{N()UO:+E;}
Unfortunately there isn't a fancy TIO style interpreter for Headascii, just the same old replit hosted one. you can run that here by running
erun("+OU+++++++++OU++++++++++++++OU+OU+OU+OU+OU+OU++++++++++OU++++OU++++OU++++OU++++OU++++++++++OU++++OU++++OU++++++++++OU+++++++OU++OU+++OU+++++++OU+++++++++++++++OU+++++OU++++OU++++OU+++++++++++++OU+++++++++++OU+OU+OU+OU+OU+OU+OU+++++++++++OU++++++OU++++OU+OU+OU+OU+++++++++++OU++++++++++++++++OU+++++++++++++OU++++++++OU++++++++++++OU+++++++++++++++++OU+++++OU++++++++OU++++++OU+OU+OU+++++++++OU++++++++++++++OU++OU+++++OU++++++++++++++++++++OU+++++++++++++OU+++++++++OU++++++OU++++++++++++++++++OU++++++++++OU+++++++OU++OU+++OU+++++OU++++++OU++++++++OU++++++++++++OU+++++++OU++OU+++OU++++++++++++++++OU+OU+++++++++++++++OU+++++++++++++++++++OU++++OU+++++OU++++++++++++++++++OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+OU+++++++++++OU++++++OU++++++++OU++++++++++++OU+++++++OU+++++++++++++++++OU+++++++++++++++++++OU+++++OU++OU+++OU++++++OU+OU+++++++++OU++++++++++++OU++++++++OUOU++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++OU+++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++OU++++++++++++++++++++++++++OU++++++++++++OU+++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++OU+++++++++++++++++++++++++++++++++++++++++++++++++OU+++++++OUOU+E.+++++[]]]][]][{UO{^)]]-P++++++P:]+++PD-};N)}:++E.U)!-E:R[{UO):};{UOD+^(])R+++++++++++++++++++++++++++++++++P:};{N()UO:+E;}")
Alternatively, Try It In Headass!, works the same way but outputs the character codes rather than the actual characters, which I personally deem unacceptable but whatever :P
Explanation
It's basically just the vanilla Encode, Print Encoding, Print Decoding style quine. Still on the hunt for a more clever trick to do it shorter but I thought this would be fun to start as a benchmark lol.
EDIT: was able to save quite a few (2313) bytes by writing a program to (mildly) optimize which characters were assigned which values, changed up the structure of code block 2 to have a loop (as discovered in previous revision), and removing a constant amount from each of the ascii values in the encoding and adding it back on in decoding later instead.
+OU…UOU+OU…+E. code block 0 (heavily abridged / altered)
(this block handles encoding)
encode part 1: many of the following
+ n +s: increment r0 by n, 1<=n<=20
O enqueue r0
U set r0 to 0
… (these encode which of the characters from
encode part 2 are going to be decoded later)
UO enqueue a 0 to delimit parts 1 and 2
encode part 2: 20 of the following
+ n +s: increment r0 by n, n being
an ascii character code minus 33
O enqueue r0
U set r0 to 0
… (these encode the actual ascii character
codes, and we'll add 33 to them later.
we can call this little index of values
our "table" of ascii values)
+E go to code block 1
. end code block
+…[]]]][]][{UO{^)]]-P+…P:]+++PD-};N)}:++E. code block 1 (edited)
(this block prints the encoding)
+… 5 +s: r0 = 5
[ r2 = r0
]]]] r0 = r2*4
[ r2 = r0
]] r0 = r2*2
[ r2 = r0
+…[]]]][]][ r2 = 40
{UO N)}: for each value x on the queue
^ r1 = x
{^) : D-}; while r1--
]+++P print ascii r2+3
(r2==40, 43 is +'s ascii
this loop prints x +s)
]]-P print ascii r2*2-1
+… 6 +s: => r0 = 49
P print ascii r2+9
(these two print O and U to
go after each string of +s)
++E go to code block 2
. end code block
U)!-E:R[{UO):};{UOD+^(])R+…P:};{N()UO:+E;} code block 2 (edited)
(this block decodes the encoding)
U x = queue.pop()
) : if x==0
(meaning we've reached the 0
delimiter separating the two
halves of encoded data)
! ACTUALLY print
(explanation below code block)
-E go to code block -1 (halt)
R[ r2 = x
{UO):}; cycle through queue until
we reach the 0 delimiter
UO cycle to next x
{ D+^(]) :}; while r1++ != r2
UO cycle to next x
R+…P R 33 +s P:print ascii table[x]+33
{N()UO: ;} cycle through remainder of queue
(language quirk mandates this...
i think these two loops can maybe
be one loop, but its nontrivial)
+E go to code block 2
So in Headass, P just prints whatever number is in r0. In Headascii, P appends the ascii character for the value at r0 to a global "output" string, which can be printed with !. That's kind of wordy though and didn't fit in the little margin up there. #fermat
Lua, 45 bytes
Simple format approach. We can use %q for conciseness.
s="s=%qprint(s:format(s))"print(s:format(s))
FALSE, 34 bytes
["'[,34,$!34,'],!"]'[,34,$!34,'],!
Explanation
["'[,34,$!34,'],!"] {quote that prints the program sources}
'[,34, {write `["`; ASCII code for " is used because FALSE has no escaping}
$! {dup the quote, then call}
34,'], {write `"]`}
! {call the quote again}
Nekomata, 9 bytes
"ᵉĝ,"ᵉĝ,
"ᵉĝ,"ᵉĝ,
"ᵉĝ," Push the string "ᵉĝ,"
ĝ Wrap the string in quotes
ᵉ , Join it with the original string
Since Nekomata always prints the result with a trailing newline, I have to add a newline to the code to make it a quine.
Thunno 2 j, 6 bytes
"DṘ"DṘ
Explanation
"DṘ"DṘ # Full program
"DṘ" # Push the string "DṘ"
D # Duplicate it
Ṙ # Get its representation
# (Surround by quotes)
# j flag joins the stack
ARBLE, 22 16 bytes
(f%f)"(f%%f)%q"
Essentially the lua quine of s="s=%qprint(s:format(s))"print(s:format(s)).
Takes the function f%f (which acts as f:format(f)) and then calls it with the format string "(f%%f)%q, where %q escapes the provided argument.
ForWhile, 24 bytes
"34#.(,#)~:?"34#.(,#)~:?
prints the string "34#.(,#)~:? twice
Explanation
"34#.(,#)~:?" \ push the string 34#.(,#)~:?
34#. \ print a "
(,#) \ print the string
~:? \ 1st iteration: go back to the start of the program now with an additional -1 on the stack
~:? \ 2nd iteration: jump to address 0, terminating the program
Trilangle, 15858 5562 characters, 15950 5654 bytes
Nowhere near as short as the others but it finally works! Posting what I have before attempting to get it shorter.
Edit: I think that's the most extreme golf I've ever had in a single go.
The program consists of two interesting sections separated by 5329 periods (.):
\\!.(2."!L.2'7!..2j.++!"%_".#:_",oI#.!"%_"2..._",o+..S#\(,o+!":.,##,o."<!L*2/!..2,,<><#..(!(,oj)2_,o""<!L#"!B!!B!!B!!><#2"!B!!B!!B!!@"!!7!
and
"ᘠ"𥧷"l"𥱏"࠰"𥰱""⍋"㩇""𘑨"喨"⍎"㩇"𜼱"㩐"𗶇""𐲮"𗶇""䪤""""Ճ"𥰱""傤"ﮧ"𘙤"""⏮""a"!"!"!"傤"p"!"!"!"~"ࠪ".
The second part contains unallocated Unicode codepoints, so I can guarantee that your font doesn't have them all. It's the first part encoded in base-95, three instructions per character, length-suffixed.
To scale, the full program looks like this when unfolded:
The decoder does three things, in order:
- Decode the data from base-95 and print it. I use
!for zero rather thanbecause the interpreter ignores spaces. In hindsight I could've done base-94 but that's still only 3 instructions per character, so it wouldn't make a massive difference.
\
. ( 2
. L
. 2 ' 7
. . 2 j +
+ ! " % _ " .
# : _ " , o
. ! " % _ " 2 .
. _ " , o + . .
\ ( , o + ! " : .
- Print 5329 periods.
7
.
"
I
.
S
,
# , o . " < L * 2 /
> < # . . ( !
- Print the whole stack, alternating with
"characters.
. . 2 , , < >
( , o j ) 2 _ , o " " < L
> < #
@
Most of the !s, some of the "s, and all of the Bs are never hit. They're just what the decoder produces at those locations. ! and " are used because they're 0 and 1 in base-95, respectively, and B is used because B!! is the smallest triplet that corresponds to a printable non-whitespace character.
This can obviously be compressed by making the NOP slide smaller. There's two ways to do this, one easier than the other:
- Be a bit smarter about computing the size of the NOP slide. I gave myself very little room to do so and so the only thing I could come up with was
"I2*, i.e. \$73^2\$. Rearranging some other things to give myself more room to compute this value means I could move the data closer to the decoder.- Partially addressed by edit 1: 15625 -> 5329. This is the smallest square that will work, but there's a smaller non-square number. I only got the absolute lowest-hanging fruit.
- Be a bit more clever about how the stack is printed, so that it doesn't have to be all on one line. This brings the amount of NOPs needed from \$O\left(n^2\right)\$ to \$O(n)\$ if you do it right, I think. See Bubbler's suggestion in chat the other day. I can definitely do this, but it'd take a bit of thinking.
Like I said, I'm just posting this for now to be on the board. I'll have to revisit this to make it shorter.
FALSE, 34 39 bytes
["$91,34,!34,93,!"]$91,34,!34,93,!
This is a "standard" quine program as outlined here: https://esolangs.org/wiki/Quine. What makes this program interesting is its use of FALSE's lambda ([]) command. FALSE doesn't have string literals, so I had to make an anonymous lambda function that prints a string, rather than returning it's value. This can then be executed multiple times by duping it ($).
Positionally, 1551 Chars or \$1551\log_{256}(3)\approx\$ 307.28 Bytes (cheating)
>v > v >v / >
/ \/ \/ 1 \/ \ / \
> ^
^+ <
: > . $ v > $ : v :
v v { < }
g \ s \ /\ / \ /
\ ^> ^ > / \ ^> ^
/ \ / \ / \
/ 1 \ / \/ 1 \ 0
> 9 ^
+ ^+ <
> v $ > . v> : v
v ~ < ;<
\ s / /
\ / \ /\ /\ / \ /
\$\log_{256}3\$ is because each character is a space, newline, or command. General outline (ignoring most control flow, represented in easy mode*):
g:s\.$1+$:{:} >
>~$s;19+.1+:0^
*Easy mode is a new test mode on my interpreter, using the s flag. It treats each instruction as what you tell it it is, rather than using the table and your coords.
Explanation
The stack is set up before each running of g as follows:
x
y
y
x
g: gets the char code at x,y and pushes it on the stack twice.
s\ will continue straight if the value pushed by g is non-zero (aka it's not yet at the end of that line), otherwise goes down to the next line.
. outputs the character gotten by g (if it wasn't null, otherwise control would have already moved).
$+1$ swaps the remaining y and x on the stack, increments x, and swaps them back.
:{:} first duplicates y, rotates x onto the top, dupes it, and rotates one copy back to the bottom, restoring the stack format.
> is just used to allow the second line to rejoin the first.
Now for the other line:
> is to make control go along the second line.
~ gets rid of the unoutputted extra g result.
$s; swaps x and y, checks if x is 0 (popping it in the process), and halting if so.
19+. outputs a newline (1+9=10, 10 is code for a newline).
1+: increments y and duplicates it.
0 pushes 0, resetting/setting x to 0.
^ merges back up to the first line.
Thue++ 39 Bytes
.+::=~$0\n::=\n$0
::=
.+::=~$0\n::=\n$0
Emacs Lisp, 23 bytes
(insert(buffer-string))
Execute it with C-x C-e. The normal C-j key binding runs it in debug mode, so the nil return value of insert will also get printed afterwards. (Also, if an error appears, make sure the cursor is at the end of the buffer.)
Explanation
Emacs uses buffers to edit, read or write text/code. By default, the current buffer is used for most operations. To get the contents of the current buffer, we can use buffer-string. We can then insert the contents back into the buffer using the handy-dandy function insert.
Output
On the first execution, it sets the buffer to:
(insert(buffer-string))(insert(buffer-string))
Since C-x C-e only executes the last S-expression, running the program again will copy its contents:
(insert(buffer-string))(insert(buffer-string))(insert(buffer-string))(insert(buffer-string))
Have a fantastic week!
ARM Thumb machine code + Linux syscalls, 14 bytes (non-competing)
Hexdump of source:
0210 2ffa 1040 22e0 7240 fd00 7407
Disassembly:
00: 2001 movs r0, #1 // stdout
02: f2af 0104 subw r1, pc, #4 // address of start
06: 220e movs r2, #14 // 14 bytes
08: 2704 movs r7, #4 // write()
0a: df00 svc #0 // syscall
0c: 4770 bx lr // return
Is this against the rules?
Factor, 56 bytes
"%uUSE: formatting dup printf"USE: formatting dup printf
Inspired by fede s.’s answer.
Explanation:
%uUSE: forma…" String with printf-directive %u to print an unparsed value (wrapping string in quotes) at start of string
USE: formatting Import formatting vocabulary to get printf; string is still on stack.
dup Duplicate the string; now there are two copies on the stack.
printf Print the string with its copy as a formatting argument; the copy is wrapped in quotes and inserted at the start due to %u directive.
(,) 46114 17682 14022 12123 11403 11183 9947 Chars or \$9947\log_{256}(3)\approx\$1970.7 Bytes
Less than 10,000 Characters!! Still 2000 characters to go before I can fit it in a url :(
((),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),()())(((),(())()),()()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()()())(((),(())()),())(((),(())()),())(((),(())()),())(((),(())()),()())(((),(())()),()())(((),(())()),()())(((),(())()),()())(()(),()()()()()()()())(()(),(()(),,,,(),,()()()()()))((()),()()())(,,,(()()),(),,()())(,,,(()())())(,,,(()())()()()())(,(,,,(()()))(,,,(()())()),,,(),,()()())(,,,(()())())(,(,,,(()()),(),,()()())(,,,(()())())(,,,(()())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())((())(),())((())(),((())())(,,,(()())),,(()())(),(((())))(),((())()))(,,,(()())())(((())),((,,,,,()))(((()))))((()),((()))()),,,(()),((())))((()),()()())((()),((()))(),,(()())(((())),,,,(),,(((())))),(()),((())))
let text = "(()(),()()()()()()()())(()(),(()(),,,,(),,()()()()()))((()),()()())(,,,(()()),(),,()())(,,,(()())())(,,,(()())()()()())(,(,,,(()()))(,,,(()())()),,,(),,()()())(,,,(()())())(,(,,,(()()),(),,()()())(,,,(()())())(,,,(()())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())((())(),())((())(),((())())(,,,(()())),,(()())(),(((())))(),((())()))(,,,(()())())(((())),((,,,,,()))(((()))))((()),((()))()),,,(()),((())))((()),()()())((()),((()))(),,(()())(((())),,,,(),,(((())))),(()),((())))";
output = "((),()()())";
for (let c of text){
output += "(((),(())())," + "()".repeat(c=="(" ? 1 : c==")" ? 2 : 3) + ")";
}
output += text;
out1.innerHTML = output.length + " Chars";
out2.innerHTML = output;
<h1 id=out1></h1>
<p id=out2></p>
Like most esolang quines, there is an encoder and decoder. The decoder is shown below:
(()(),()()()()()()()())(()(),(()(),,,,(),,()()()()()))((()),()()())(,,,(()()),(),,()())(,,,(()())())(,,,(()())()()()())(,(,,,(()()))(,,,(()())()),,,(),,()()())(,,,(()())())(,(,,,(()()),(),,()()())(,,,(()())())(,,,(()())()()()())(,,,(()()),(),,()())(,,,(()())(),(),,()())(,,,(()()))(,,,(()())(),(),,()())(,,,(()())()()()())((())(),())((())(),((())())(,,,(()())),,(()())(),(((())))(),((())()))(,,,(()())())(((())),((,,,,,()))(((()))))((()),((()))()),,,(()),((())))((()),()()())((()),((()))(),,(()())(((())),,,,(),,(((())))),(()),((())))
And in pseudo-code:
a is var[1]
b is var[2]
c is var[a]
d is var[a]+1
b=8
b=b*5;
c=3
(str-output b)*2
str-output b+1, b+4
(str-output b, b+1)*3
str-output b+1
while a>/>=c{
_=(
(str-output b)*3
str-output b+1, b+4
(str-output b)*2
(str-output b+1)*2
str-output b
(str-output b+1)*2
str-output b+4
d=1
while var[c]+1>/>=d{
d=d+_=(str-output b)
str-output b+1
}
str-output b+1
var[c] = var[c]+var[while None>/>=1] // while None>/>=1 is 0, var[0] is input, and EOF is -1, so this is equivilent to var[c] = var[c]-1
c=c+1
)
}
c=3
while a>/>=c{
c=c+1
str-output b+c*c
}
And the encoder is of the format below:
Once: ((),()()()), and for each char in the decoder: (((),(())()),?) with ? being (), ()(), or ()()() depending on whether the char is (, ), or ,, respectively.
Try It Online!
You have to paste the code yourself, the url was to long otherwise.
Shasta v0.0.9, 67 bytes
q='"'a="q='%s'a=%s(printf a[q,(wrap a q)])"(printf a[q,(wrap a q)])
There is no online interpreter for Shasta yet, but there are installation instructions at the GitHub link and I have verified that this works on my machine.
There is likely a much shorter quine possible, but I'm new to writing these.
Commodore C64 machine code (6502) using the Kernal (non-competing/just for fun), 42 bytes
From memory location 0x033c, enter the following machine code in your monitor:
>C:033c a2 00 bd 3c 03 48 4a 4a 4a 4a 20 59 03 68 48 29
>C:034c 0f 20 59 03 68 cd 65 03 f0 0e e8 d0 e5 c9 0a 90
>C:035c 02 69 06 69 30 20 d2 ff 60 01
Now call with g 033c or SYS 828 from the BASIC prompt.
Each byte of the machine code is written to the screen with the CHROUT routine in the Commodore Kernal, so this will likely work with all Commodore 8-bit machines, though it is untested on all but the Commodore C64.
How it works:
The routine starts from the base address at 0x033c, and reads each byte by loading its value into the accumulator; the accumulator is pushed to the stack, and then the value is logically shifted right so to get the high nybble (so d2 becomes 0d), and the high nybble is converted to its PETSCII equivalent (0 - F inclusive) and outputted to the screen.
We pull the value back from the accumulator and then mask out the high nybble, leaving the lower nybble (so a9 will become 09) and again we convert this to its PETSCII equivalent and output it to the screen.
Finally, we check the value of the current memory location of 0x033c offset by the X register (our counter); if it is equal to our terminating byte (in this case is 01, the last byte of the quine) we're done. Otherwise, we increment our X register by 1 and go again.
For some hints, you may disassemble this by using d 033c in your monitor; this will show you the 6502 assembly equivalent to the machine code bytes.
For further guidance and reference, consult C64 Wiki or CodeBase 64.
C, 64 60 bytes
main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}",34,s);}
This may segfault on 64-bit systems with some compilers, such as newest Clang, due to the type of s being interpreted as 32-bit int instead of a pointer.
So far, this is the shortest known C quine. There's an extended bounty if you find a shorter one.
This works in GCC, Clang, and TCC in a POSIX environment. It invokes an excessive amount of undefined behavior with all of them.
Just for fun, here's a repo that contains all the C quines I know of. Feel free to fork/PR if you find or write a different one that adds something new and creative over the existing ones.
Note that it only works in an ASCII environment. This works for EBCDIC, but still requires POSIX. Good luck finding a POSIX/EBCDIC environment anyway :P
How it works:
main(s)abusesmain's arguments, declaring a virtually untyped variables. (Note thatsis not actually untyped, but since listed compilers auto-cast it as necessary, it might as well be*.)printf(s="..."setssto the provided string and passes the first argument toprintf.sis set tomain(s){printf(s=%c%s%1$c,34,s);}.- The
%cis set to ASCII34,". This makes the quine possible. Nowslooks like this:
main(s){printf(s="%s%1$c,34,s);}. - The
%sis set tositself, which is possible due to #2. Nowslooks like this:
main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}%1$c,34,s);}. - The
%1$cis set to ASCII 34",printf's first** argument. Nowslooks like this:
main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}",34,s);}
... which just so happens to be the original source code.
* Example thanks to @Pavel
** first argument after the format specifier - in this case, s. It's impossible to reference the format specifier.
I think it's impossible that this will get any shorter with the same approach. If printf's format specifier was accessible via $, this would work for 52 bytes:
main(){printf("main(){printf(%c%0$s%1$c,34);}",34);}
Also here's a longer 64-byte version that will work on all combinations of compilers and ASCII environments that support the POSIX printf $ extension:
*s;main(){printf(s="*s;main(){printf(s=%c%s%1$c,34,s);}",34,s);}
ReRegex, 117 bytes
_()9(?=.*\/)/\//_()8(?=.*\/)/\\/^\/(.*)/$1\/$1/\/_()9(?=.*_8_9)_9_8_9_9_()8(?=.*_8_9)_9_8_8_9^_8_9(.*)_9$1_8_9$1_9_8
As with many quines, works by unpacking and decoding the data. The data is _()9(?=.*_8_9)_9_8_9_9_()8(?=.*_8_9)_9_8_8_9^_8_9(.*)_9$1_8_9$1_9_8 (Everything after the last regex), and the decoding is done via 3 regexes.
_()9(?=.*\/)/\// # Replace instances of _9 with /
_()8(?=.*\/)/\\/ # Replace instances of _8 with \
^\/(.*)/$1\/$1/\/ # If the data starts with a /, copy everything behind it.
_()s are included in the first half of the number regex to ensure they aren't replaced when they represent the regexes themselves. (?=.*\/) asserts that it only replaces numbers behind a /.
Thunno KJ, \$ 16 \log_{256}(96) \approx \$ 13.17 bytes
"D34CDZs"D34CDZs
Sort of like lyxal's Thunno answer, but uses flags and the stack instead of the x variable.
Explanation
"D34CDZs"D34CDZs # STACK:
"D34CDZs" # Push the string to the stack D34CDZs
D # Duplicate this string D34CDZs, D34CDZs
34C # Push chr(34), the double quote ", D34CDZs, D34CDZs
D # Duplicate this string ", ", D34CDZs, D34CDZs
Zs # Swap the second and third items ", D34CDZs, ", D34CDZs
# The flags join the stack "D34CDZs"D34CDZs
# Implicit output
Thunno, \$26\log_{256}(95)\$ ≈ 21.35203072707557
bytes
"D34CXx+xs+s+"D34CXx+xs+s+
It's one of those ones which has one of itself.
Explained
"..."D34CXx+xs+s+
"..." # Push a literal string
D # Duplicate that string
34CX # X = chr(34)
x+ # append " to the string
xs+ # prepend " to the string
s+ # prepend that to the original literal string
SQL - Snowflake, 26 bytes
Using CURRENT_STATMENT function:
Returns the SQL text of the statement that is currently executing.
SELECT CURRENT_STATEMENT()
Output:
SELECT CURRENT_STATEMENT()
Functional(), 904 880 846 768 716 692 684 662 605 602 bytes
),$,$$,($(8,( $(($(<,$(,,,)),($(4,$(9,,)),($(9,$(,,0,,)),($(0,$()),$ 4)(((0,9,,$)(((,)(( $(($($$,( 9((()(9($ <($ 4(8(, 4))))))$$),, $))(( $(,(,$),,(),, 9,, 0,, $,, 4,,(,())))))),(()($$())(8(9(9(8(4(4(8(9(8(8(<(9(9(9(9(9(9(9(8(<(8(<(<(4($,0(<(<(4(0(<(<(0($,0(<(<(9($,0(<(<(9(8(<(<(9(4(<(8(<(8(4(0(8(8(9(9(4(0(<(<(9(4(4(9(9(9(9(9(9(4($,0(<(8(8($,8(4($,0(4(8(<($,0(4(8(9($,8(9(8(8(8(9($,0(8(<(4(4(8(4(8(8(4(0(8(8(9(<(8(8(8(9(4(<(<(9($,<(0($,8(8(8(9(4($,0(4(<(9(9(8(4(<(0($,8(4(8(<(9(9(<(<(0($,<(<(8(4(<(9($,8(4(8(<(9(9(<(<(9($,8(4(<(4($,8(4(8(<(9(9(<(<(<(8(4(<(<($,8(4(8(8(4(0(8(<(8($,8(4(8(<(4(4(<(4(<(9(
Try it online!
Try the 605B version online!
Try the 662B version online!
Try the 684B version online!
Try the 692B version online!
Try the 716B version online!
Try the 768B version online!
Try the 846B version online!
Try the 880B version online!
Try the 904B version online!
This code comes from a generator code below;
),1,P,
:(h,
& 1(
:(l,1(>,>)),
:(d,1(i,>)),
:(i,1(>,`,>)),
:(`,1()),
1 d
)(
&(`,i,X)(
&(>)(
& 1(
:(P,
& i(
&()(
i(1 l(1 d(h(> d))))
)
)P
),
> 1
)
)(
& 1(
>(X),>(),> i,> `,> 1,> d,>(>())
)
)
)
)
),
&()(
P()
)(
h(i(
i(h(d(d(
h(i(h(h(
l(i(
i(
i(
i(
i(
i(i(h(l(h(l(l(d(1,`(l(l(d(`(l(l(`(1,`(l(l(i(1,`(l(l(i(h(l(l(i(d(l(h(l(
h(d(`(h(
h(i(
i(
d(`(l(
l(i(
d(d(i(
i(
i(i(i(i(d(1,`(l(h(h(1,h(d(1,`(d(h(l(1,`(d(h(i(1,
h(i(h(h(
h(i(1,`(h(
l(d(d(h(d(h(
h(d(`(h(
h(i(l(h(h(
h(i(d(l(l(i(1,l(`(1,h(h(
h(i(
d(1,`(d(
l(i(i(h(d(l(`(1,h(d(h(
l(i(i(l(l(`(1,l(l(h(d(l(i(1,h(d(h(
l(i(i(l(l(i(1,h(d(l(d(1,h(d(h(
l(i(i(l(l(l(h(d(l(l(1,h(d(h(
h(d(`(h(
l(h(1,h(d(h(
l(d(d(l(d(l(i(
Try the generator code online! ( Try the encoder script online!)
Try the 605B generator code online!
Try the 662B generator code online! ( Try the 662B encoder script online! )
Try the 684B generator code online!
Try the 692B generator code online!
Try the 716B generator code online!
Try the 768B generator code online! ( Try the 768B encoder script online! )
Try the 846B generator code online!
Try the 880B generator code online!
Try the 904B generator code online!
The core part of the code is encoded with `,d,h,i,l for space,1,(,),comma respectively.
Other characters &,>,:,P,X are treated as (,comma,(1,11,,1
The actual characters in the quine code,
- 1 is converted to $
- `,d,h,i,l are converted to 0,4,8,9,<
The encoded string forms a long long call chain with encoding rules below;
Z->z(e.g. 1 -> d(z->z(1,e.g. h -> h(1,
pl – Perl One-Liner Magic Wand, 22 bytes
Very late to the party, just for fun. This decades old Perl wrapper, was only released into the wild when Corona went viral.
The 3rd quine in the blog is the actual golf. Of interest here is the 2nd 1-letter alias variant. It's essentially the same as the Perl one, which it beats by 6 bytes. As on many examples on that page, hover the ▶ button, or the blue code box, to see the result.
&f(qw(&f(qw(%s)x2))x2)
Javascript 6 Characters 13 Characters
Working Version
f=_=>`f=${f}`
Previous Bad Version
f=_=>f
This quine is only 13 characters long
This code defines an anonymous function that outputs its own source code to the console when it is called. The source code of the anonymous function is defined as a string inside the function, and this string is used to output the source code of the anonymous function when it is called. This means that the code outputs its own source code, but it does not just read its own source code directly.
Whitespace, 333 330 bytes
Try it online!
Try the 333B version online!
This is the same code as I posted to "Anarchy golf" ( http://golf.shinh.org/p.rb?Quine )
To be a bit more readable, substitute space,tab,newline to "s","t","n" like below;
sssttstssstttttttsttsstsstttssstststttsssstttststtstttttsttssssssstttstttttttttstttssstssstsstssstttststtstssttsstttsssststttsstststtttttssttsssssstssstststtttststtsststttssstsststtssssssststsstssssssssssnssstsssssnsnstnsstnsssnsssstsnnstnsssttnnssnsntstsstntstssnsntssnsnsstsstsnnstnnsssnsnttsttsstttsssntsttssstsssssntssstnssntn
or disassembled code with my original interpreter/disassembler;
push +2636263872820036273590233982665123397718151559108318308901888(201b) # 0000: sssttstssstttttttsttsstsstttssstststttsssstttststtstttttsttssssssstttstttttttttstttssstssstsstssstttststtstssttsstttsssststttsstststtttttssttsssssstssstststtttststtsststttssstsststtssssssststsstssssssssssn
push +32(6b) # 0205: ssstsssssn
dup # 0215: sns
putc # 0218: tnss
putc # 0222: tnss
dup # 0226: sns
push +2(2b) # 0229: ssstsn
call null # 0235: nstn
push +3(2b) # 0239: sssttn
mark null # 0245: nssn
swap # 0249: snt
copy +1(1b) # 0252: stsstn
div # 0258: tsts
dup # 0262: sns
jzero +0(0b) # 0265: ntssn
dup # 0270: sns
copy +2(2b) # 0273: stsstsn
call null # 0280: nstn
mark +0(0b) # 0284: nsssn
swap # 0289: snt
mod # 0292: tstt
push -24(5b) # 0296: sstttsssn
mod # 0305: tstt
push +32(6b) # 0309: ssstsssssn
add # 0319: tsss
putc # 0323: tnss
ret # 0327: ntn
The key idea is to decode the same encoded number as binary digit for the 1st time, and as ternary digit for the next, with recursive operations like a Python code below;
def decode(x,b): # b=2 or 3
x //= b
if x != 0:
decode(x,b)
print("stn"[x%b], end="") # "s" for 0, "t" for 1, "n" for 2
This code decode a number as a binary or ternary digit, then add 0 at the top and remove the last digit, finally substitute 0,1,2 to "s","t","n" respectively.
For example, if you want to encode a Whitespace code "sstn", use an even number 502=200121(ternary)=111110110(binary). At the 1st decoding as binary, "stttttstt" is created, and the 2nd decoding as ternary, "snsstn" is created. Finally, concatenate "ss" and these, the decoded code will be "ssstttttsttsnsstn", which is "ssstttttsttsn" ( "push 502" in Whitespace ) + "sstn" and thus what you want.
In addition, the conversion from 0,1,2 to s,t,n ( ASCII 32,9,10 ) is implemented with a formula y=mod(x,-24)+32.
MySQL, 167 characters
SELECT REPLACE(@v:='SELECT REPLACE(@v:=\'2\',1+1,REPLACE(REPLACE(@v,\'\\\\\',\'\\\\\\\\\'),\'\\\'\',\'\\\\\\\'\'));',1+1,REPLACE(REPLACE(@v,'\\','\\\\'),'\'','\\\''));
That's right. :-)
I really did write this one myself. It was originally posted at my site.
Bash, 35 28 20 bytes
trap -- 'trap' EXIT
@Dennis pointed out that even the -p flag is not necessary, and trap will print the trap strings unqualified, which helped save another 8 bytes, and brought about another quine:
Zsh, 18 bytes
trap -- trap EXIT
Zsh trap does not print the single quotes, which makes it incompatible with the bash version, but also allows you to save another 2 bytes for the zsh-only version. Again, though, bash does not show this behavior and trap does not print anything.
Bash, 19 bytes
Another, just barely shorter, and much less interesting bash quine:
echo $BASH_COMMAND
Thankfully the lack of single quotes mean that in zsh, trap is still shorter, which is important because the $BASH_COMMAND variable does not exist. Additionally, I'd be tempted to count this as 'reading the source' but that might be because I like the trap one so much.
Bash 28 byte submission
trap -- 'trap -p EXIT' EXIT
Just realized that the echo statement could be cut out entirely, trap -p simply prints the trap statement in this format (saved another 7 bytes).
Compatibility: This must be in a script file, trap does not work as expected on the command line, and its bash-only: bourne shell/ash/dash does not support the -p flag to trap (obviously instrumental to the quine).
Original 35 byte submission:
trap -- 'echo `trap -p EXIT`' EXIT
A much farther golf of @ormaaj's trap-based solution. Shaves off 1 byte by switching to backticks, 2 more because the quotes around the echo body are not necessary, and 9 bytes by switching to echo. The real magic though, is switching from a DEBUG trap to EXIT. This saves 2 bytes just because EXIT is shorter, and 3 more because you do not need to call : or print it (and it drastically simplified the escaping needed for echo).
I'm not 100% sure whether this counts as 34 or 35 bytes, as echo prints a trailing newline and I'm not sure whether its a true quine if I don't include a trailing newline in the source. I called it 35 bytes to be more safe/truthful, but I'd love to know what a real ruling on this is.
Link to @ormaaj's original solution. (If I had enough reputation to post these golfs as a comment on the original post, I would have. My apologies if any of this breaks convention.)
Knight (v2.0-alpha), 35 bytes
O S=s"O S=s5F++A34sA34"5F++A34sA34
Expanded:
OUTPUT SET
: = s "O S=s5F++A34sA34"
: 5
: F
: ++ ASCII 34 s ASCII 34
Atari BASIC. 4 bytes
1 L.
Well known since the release of the language, and the result of two quirks of this BASIC dialect. Most BASICs only let you run outside commands in immediate mode, but Atari BASIC allows a line number here. Secondly, there's a full list of abbreviations for the common commands.
Malbolge, 59851 Bytes
I take no credit for this quine, all credit goes to this person
Newlines are significant, Compressed into a code snippet because otherwise this wouldn't fit.
var byteArray = pako.inflate(atob('H4sIAN89UFkCA5Rb+zty79P9/f4vSJRDKJFzFEJyCKXoQHKqRIoif/u7Zu7D3ru25/N9f3yuyzPXfc2eWbPWmun2Y3wrurmxvra6sBxZWgwvhILzc7OBmempSb9vYtw75hkd+e3/rPW6X5+d9ke9djG3/X1ao3/4JryF5mu+Xty++b4Q3a9Op31x/t5svtbrtf7Pt/wfE15v4QZ/VHv57vKfnLbm8CfO8J1274bDt95fRDPdwF8/Pz0+VO8TN7flXDGbuczn0tnMyvJ5+uz04Dh1lNw5iCX2dnfiE/z6pbX+N8J/frbbrdbb2yte8PIiniZ+HxC/+1vWj/loXb40Xx/rVQpfrt5X9nbLpWLh5npjY21tZSUSWVxcWAgG5+YCgWmE3/RNbCO8oOysqOxMU3bM8+/x/Nt+R4Z//WjV3pqvjdPaPb3+oFi5uy2XYtmb63zuau308kKk0snwCT8/sJ/YiuL521seJP93daUXXFr8XAi1EL45M10b8/uedPifwkf3K4/XX76/nb826scv4vnoENkp3NHzEX8zt3aWubyIpM8OkZ355GF8P7E36YvH1saiHrw+vNKLzC+GO6Fgy/ltBbL/+fNdkPFb7/R8Tv7hw8H93s1tvhSj7JxfrSH8+eJZOHScONo9xOv3/Jtxzs4IXv8dEoiP5wffJ+n5U5PPvqcH74+nR8//vmnJ8Bf8/Frq+Yi+7R6/vhDF66+ymWV6/elJUCTw/IP9qSmOP7ayGRlZ+/lZ7nYXO51Qi2pnpl6ffH6eeHgYq4yOfPV/ir3utaydt/Rr40SWzkFRIPvxHH3czXOOT7WzcJzao/D4uH5kh55PtbMcXJr7XPgItt5mfTPjdXr9eBWvv/stlb7Fzc1XLtfOZN7Pz19PT2upFLJT3a/cXce5dvIbV9nVy2MKz9/28GB6e29yZ2J9e3VscwSvX/nuLs2FA23RmnqffX2drtX8T4hf9dxxfArfaWdb7xfNJ1P5CVk7hZvoxQbXTorDBxE+HhNU+r4Ysr8cQWn+cGkGZoLz7/LjelRpdqk0C938W+c127q4aJ6d1Y+Pn5PJh/39yu5uORYTyL58/oXpLE7+rs8X83o9yxt4/sJy8I/k33LyqfKFrh1bfCR/+2bzIpdeyywvny8unoZCqbm5w5mZxCS/3kuws2gaS4YXOv799yiy0/n+GEj+81OSk4/S5G+bu6LK18mfnQUuTPl3NmJizRsd/dfzKyPl8k+Ba+dKvv6sXj3m8PeJ3Vsqzcw1ki+yMv4Cx98J4OOidiYQfnOUk99bWuxI1GzONCj5Twxrdxp2rvBtL16aT+LsBPGTj4fVROHueid2hewg+aunl8eRdBilOb9HuKCTHx0dXe/30bhLX2hcwM4bf9sX35Pg+Ldf5WKbnp8DKqN2qLOOj45uD6v7BaqdYnYLyV/PrpxcpJbOFhB+PhkIOEpToLOAO1/h9kxwsDRH8Px2gbKTRfgXlXzATum+sHcbL8W2bi7z5wh/iW8rkqcH5uMiPhoX8dfX+ivfBGudj4/WnD/w2piqvfhGxh+qngrNFIkL2UarJkvzJfUkDsvVYuJuB9kpbBHunK1eApWTpwvBlMqOHRdWviNf1FnBd/P6ifGHsfvRrvgtlwjWPq9eP+qXAIazE6DyHZUmYG2ntJ29uQRqqtJcOEBnzWKmTO/5d3zj26vRZZn83pL4BDB8ANYA+vVJ/+jTo7fKM6tIMyvXbDdkadZPUs93j+UDgrV46aqQiebX1/FtEV4mR7hlB6U/22lrVH55eUJ2xiq9kS+UJhoX2fnIXLw9vz5K2EHpJO7EDp6P2tlcp5EoYXM/eISZNcMjcR0j0bMx8sudBVgLfWhcGGgswZ3VQnaeGg8nL0dHSD4a97qcizEqY6ac2Bt3PzFFqEmwM6pfT407L96bgYlpL9XOQ3/s/g6o3Cn2rq9N6RPuHN3pyi9tF7Y28+rbpsPhkyCSPzuDgS4mJazRRF/9IcKg+IhvplGffHlWhOGrXyqqgX55qUZW5Sl5yLgA2MluCZroZ8jO0tHZoSr9oc7qLYEwMGo29UjsV/n1aNzrd4ysRku8E2E4pfiSMKB2imokrgD0jyg7aNxZAv2oPz4OWBuNrC9S4wJ2AqFpwE7gtT4lxlA76Cx83NvST7vXQnau6PnpdONEJf8+cbebjwM1o3kaiTI7of3U/CwG+rZ6vXCg8sc0nv9qSz5wQSYfpeme/O3oJcOOkLhzEgJhID6iP66aWfbOqnsnX8CmvD8If4vaKVx/qZmC0jkVx8jOLdUmaie+LWFzdXX5+HwpjJmS0Ljjiyvc6YdXgJr4tjMfGjWfaWSJMQADEQbwnc/c1UcGqHz2SKicTB6UkJ2dfIlQUzUuvi1qB3wEyZ+ejKJ0vLJxVwUIwzw6ywb6vgnZuPRxCzeK7pw/A/SPbbgQKypcAGoiOYeCOmv2EGxwC2ww5t0aG0VphomPfM4utInu+IA7tuz0i7LyrzJ1YmtnNNDvHh/Ewf6eIpvI/np2dUVN3OA8aof4CHABz/ds/C6uLiD5AGWEB+g3xqfGXnyPj+AjGFmfglA5D9DPGFSWwFABnYozH0FprgJ30u7J12xK/M/PR+VbrweXxUAH7CxpuiPiM6p2NFv7a6YYukMDHaWJ8CeK6FdudsuCawelv3qK7BwRrKX25g6Z6W/GY+NjYx6Ep4nbtcPai8fG1kCVr3OiMwT6ld0h0HfA2ga47Njo6MgalWYXI4snruDaJGCQjUug33LCmirN3VtHaZrwgTiHF8j+1phnhFA5FAGsAfTnQZV5pvge3TqreQYhkVKNdacxX+j4xGWDpINmpjHRuXEZ1r4R/jNs4Y6EHRsuKNgRCneeHiVs5uMxTFzGnX91ltVYb34ZXoz+++NiJCaI6W8XpA7KqMoPpY7mWEhgZDFqCgmbhMpExeeamoqzkHCEx8QFLtSOpZCg2gEf2VKoeSwizPSD85LpR6k0vayDWGZZpWmHtd9yEbDz7pi4gjprvwjQ56GCmQJY0zPL9nyauCCDNHFVdmygTMkX9uyjsy7SrwrWDBUvRKOYKVluXO4s0ikz05NU+RCJNHFRmiSzED84BcIwMT1Ve35+opk1egemXyxoHST5yMuR5CN4fby4hZkCvoDGWloKH56ERGpu9zBOfMS3ERtH/I0lyLjvLqk4zJRJ4E4DIhSEoT/2Ddwhpn/z9Za7ymQwcZ/o26aQ/NK+cB+JsvT5+ciOx2OXWR/zbxQedAew5r2n5Pchs8DW3nLoLDXRSSUeSLKJ57txWftAB2piZHWJjwhk563ZaNSlyP25x0xRVLx5pcMD9P8Oj8qfCxxAZm0ZtmYXoUTFlQPw+1CtVO5+pdvxRiPL8JGjJCR0hUeWYKa/lnVj+uNrf8yUITaFgS6yl++2ib5/b010PF+pOIys+dlZVZoxAn2UZt/4Fy16vZDPf8BIvOv+fqKzUDuGKpuRaEfN7OryBfsXzNaAC3t+/8S6AKyxDuL4KM2PdzB9RmWwtf6YpzdC4XstJJ/sl/PzNLGpFNhaad8aWetpgedHVHyUpsvEXfrqLNga16CmGVnMpl4FYPO4gto8SCT2SCVub11vbpBKXI6kF+XMcuogNjAi83LivgN2GjWouBEha9MRH4SBwtNEVyMROiVKAz1zQiOR3J2hxhLUWZEvq7MA+s+jZE5VKsCFEumgNycTfzyQjVuSZDBNfCGSFgQMRDZn9iXZHMfEBSqHV0KKy7qg5k/xpvuOypevl99W4OO6zawFdo+Ij2xN+qW9Q3zkx4K1AaIv3Ji+E9bIYGD3CLjAI4tA2Qk7yySzZokNvmnceRyXuGN0kDIwTqovaNxDgD6NrCJGFrlHtsYV1LncuCAMUQVroFOg4gjvD0zYcUd+W3BNsl+ocR9oZHHj7gq2AJD9jSvpACTJf9FsbeD5ttcPhRdDdAoaGqW/Q/bOppxZy+eGThFhYLbG5hTzBTQWhRfcWd5JoPIjdJBp3JyiO0pI6NohWOORxeEhoUPz83MozWnILD9Q2T4SXTvrt0zOoxyJRJUfHQ5AHLggohs5NVTsqOwntgZciIDuSHPKfaBbpSlcnr/NxiZ1Fp4fDi8gO+Aj+6A7fglrkEEEa0qnSKosiCtbGtoh0W0amuiU/rYIn6bSlNadhLVtyKzNQRnXRHyU/ggmrufOIoN2FafZFElo9XpBxmlyGPTJeTSg35pXoA9cQO18k3VXdJDBs7rQnQWhUiaVSHSKYW1xMaxrZxpk00joPptTJKGRndcZLSQElMTt7ycLiTxA33zcVPJW2b5OwmD7tux9cfj1RcgsHrltuTKQXJYk+nfFMr8cuDMks9j2tWTW/pQE/QHzS24kxus1v3IAbjk72thEY50+1O7p2wolQotbUoRmViLngw4Akk/+iLb0UTts+5I/AiqL0iSRKABrqE2yAMDW0mcEDMCdg2Li7pYbl3UKa9yzBSWzhgc6GkssuOigMnvu1wB9JP+iCbZWBWFA5SfI0o9J98hiU8fBueSOUO6UpuLM9E1pDviyJZLQ+Vw2CwmN5GNkpci/2CcmLkqUHU3FwfT/QGUX1Bx/uPdY5pRwQeUbCWvu1t2w/SLJoHglLis/7neFn9+T1p1VmlLj7u2UDRN3cXcEEQbzcTHRF9hb06Vv89au3y0JbaPKO7TwAJsS5Gz+BWuMmiHqLNAdLk0namohkb2svYnzs4asTfCRiuysf3FZe2nOonFbbE7VJv2COksbp0Q2O+0s107jRNaOZd1FeV+zbDFxaFyLiYuNX/VxwXdaU8p/UY2L2uHnf312sg2unUfmsjSy2FUmmYXXo3SWRSoN3AlZKwM3X9aGOwNsSk3Eh9qxSCWTh9Ui2NpOHB9XT1wSobxuAtmEhkZprnmHNS4q34CycIhQWqikMdG1SlSusnEe/+EqiyFb2dm4n4Q7xGXB9PFtCfQTCvTl61Xyj4XNVjaNSzNlWKI7JHS2IV9vwgveB8mJbjc2IUJnYlqnDLpH8vWaL9AiVMqsnNyWaT5ye0gSncNnHLbvscvrDRkUQwuV2y+pEnlPfEmoadwjs2i92GCdspRWGwOIRGFq0+Ky4c4HVJxfhUdnuegUwxeq0mAoChl/VXlrJ4TKs+SPsA7aWvEowrC0aIc1S+PSPuUmD50ijKc/BAxy42Gebyx9ZEc5AGamvDVnhLGVeR9U0mtoPN9suQ9IJcp1E5j++iqEBG2byB/ZRWMx0Y8JWlVGlOn+H7UzsCyjNfTuTiy2zcajICVhGjegbGUHH1nsuDqDA+aUsJi+5iMUn5N/ROHJnAqQM7gjncG/dIpweHfm42KiI/ztQ+lP6y4JvjAtl/S8ShRrdio+22yAKnv0xqPcV6tEdNawzJJUWZtTIhlmU/xQyyzL0+8BF6CDTGnazCl2Hp1MXMj4O/mS9vTJ2JQqEajJm1CEX6PS/MW37f3ljwgySApcO4TKqB1o6CNpnGr7JU9b7hUjJBymtf62S+IPDV3quNKpQap8KW1ZfFsxB64sHQYzEpd518cjUZlfFpclmWV2fY1Ta2Mg/l9sDSPxgztLN9aYcXcEZ6d1eaE6i7isnrgD5peW6Lv+idhw8oUz+8Adk3y6T2mm2VVG8veJDOb1njh7KrNjsSnBdMqIUPLW2iHlrbnu+sySntlUaT+xCzYFhS7YYTglC8AYGMMXEgPG5rCKy7aEPT4tWnfjccwsdBaVPnQQnacEMVMO9IGHPXzHorLiz9rRdMdyrY05BbojsxOQCw8fSkdEKb7y7kx27M5j2bFoPXscAGW9hhZ/s7VFAv2uvq6BhK7j9ewM0h5Xg3KGGgtcUxAqJw8OWMZR9hVVXlbeGn9c7bm7XEgYkSgUYUDpK/9lANacFxL/2GZpZ5OyT94aU+WqPJ0ypVnnEwYyp56sJb0eWTI5wip9NbM8I+uKMNBIJOtuQpemYfpElc0NAFQcZopQM+uKz1+08+i+RV/96UUGTfGJx+oY44JweHdput5J8QUGa2iyXzbX5YHHIpVmghYeNLJ2NmIIv7kx0ofGDXa/wqLTRnbYl33xu3hrGRdTHDNlGBfEv01xmXxt+3aI7uRzPNAlmzoyNwBCHwEMCwk700fyu5+fpHERfoYvJAxfYKKfE7ZFLrLjeiEht+h235SPd/qrtjVxU7gu6WlPbHeVHyQZNFzWbumTkAAuCKkk7EKCyabVWR7aSLirONqnaBUnJN9ROsjBZY3nTmdxbXYAJqaVAzDsjwh9QKKzI7dlLsYmcGdjQo+sASGBgS7+dXukDr/2bh1cdqDy/c5tloMwOFaVA2xNdpadDPLG4EKcp8OH6m6Ns8PW4PLG+u/Pzzc+LonQlqodqeIqdi5rUDMlnl24rJu9I0+bFJftDG8khOPGwNTOH9ssGonMpnimsLemrTXhMDDs3tq/LiS0527JLNpm6dr8j9LkZdmvPPBwLtGZLwhDGGzGphM1dWmqEwYGZduaWDmDwjzfYX6Z7EhciKTSZ1pCo3aUtzZqFqGQQeIPHeTG9O+tkaU897TaZqGxhDLFh13rv6iyvfKRHV35LLPAZXklIc/iFBWXa2gqTes46B++qfi4hMg9G96E2p5PNwBHc7zwoD0xlWaEb5Wp8gOEmrOBV1Gv19BZj97qfY/YoDwOGmD6bqdNtonLjSus2unyvewHrRLNx7W26HYuq5f0dnNKrNpvmw4PSAdBqHi9wJ0lyk7PHH5Z5pTdWyPUpDW0kKa7WVXaZxbIYIgvJKy7MtW4oZ41U14JNX0T4pfu4txL387WbKipuazzvkPITej/4lrTcZBbdmRyBN826S36ps+5pNdkE8kHao6oPbHDW9M6RQw+35zFEWGYDUxPTykHYHN0hExxLs0Z5a3p8J7KiCgrU9wZf9C6s42sP3SKAOi3Wy11diePBplsIvmt67w6OHVwWbWkN7Aj+YjQQkWrRDus2a073nJLZzDXucq0am/Plj+CyhfKGnTykSPyRxI2f6QvfwXQCfB5Cp0YoDQnftkZ/OXGEmaomNr560JCX/VN7vjUTaLMzqeSWXh+XeKOE9YcjWu/SXQam/rqTrBEN2voIP/KQK8M6F72Uf7K4LP0bbuQGEz+39usQV8WKpErP0Bn+jI7snHZN222PzJCevps7/A57oAprq76/rJfrLM1YU42yRTHRL/O5a7IW4MIBWpqquw0p/TBqXWTOD4mUPq/a8p/GXIYJNlsF27yxGUJ1tKN0xN2BiXoW/saIYWK9mUdQsXh6RuNq0xrosoyPMFOAzKLVhIPVftCxXGxCTo1M7UXBVsbOsBwHPWJqvq4Pb7qc5b+wCbUSr453oGQ8MrSEXS9Qzoo2FK31hASj4SaIzYy+Oe5LOkU6ZuK0D+tQesc10kGIaHBF+TrpUgUpUHCANA3hEGeNk14AWtAzR8IiaU5/oEKkcFxfv24fH1f/Ay4U7XjoyclQp3hVeUj+aRxGZQ9nlEjoUWH2Jq166v+GH+E7mX1NktXfuXuuiwPMOQ9a4pgjQ0GwVd9frIAoqPSPZJ0is7uNKw99OnqTuKO28JjD+GFC6yZxjXmVJgmrjwm1ndrg76p+JPpZ6K8yJUi1F47xDVl7ej7ERD9N2FONofvRySXxUjUe2Jt+9qExFxSCQmBznXjsnZPn2ZKmxwAluhvSD5tKu9u9VncFf36SChnc1Fag3g+ofIg2XT4svbfSFjmlEDp0+WXOX/Jmesa4zw6RKi8zDIOgFNm2X+DkTPW3bG8COXk52LSNzW/kdD7GnO8I0agg1as653hHzHQHldtQq27Nfa+1O0RnTZdRoS5bbLW0LbLrIFfkICJKzbFv5HIyV8fPZGxKf7rFhoTd1LCmvu+Rv+IQciPi+xYhMGpEod0kP0Q3SodMRD/2QKGIT6if8TggponQSEvv3iiyxuDdcpO74tXleisJp+n+Jjpj3bV60129JqYjgZV9pX5xUcAAzcANtfa7jw6jokLgn8Zd8ULFXNNbHcYLLZ2Epo/+tv2Ff+xMjhv2kCfcCfnuNi0boPElKRTXvXDO74mlj+MUxraZorbfwBjN8WpdISuHRc6xVx2w/W6ZtC/6JDMch2J6j7lktdBoZA0NrenEF4eeCzZVRyhpnC/JqZ7Vq3ibL8ycBESKnxMbA/98M7l2tcxshy+qRlZ4v/aO7OuKq4tCr/PfxEjSowY5NoBNtjESGMXosYoEsWIIiKgxp7ffmuutds6dQCt+XTHfYxJ9ij3qdp7NXPNr30lNuHUT4cPp4nWz6YfCcEga1/Njbtqp+bf9WAcOgoYdqfczTV3vju++Qd9+aSuOe7DTbyycIiHfmjSN2mWheJ2Z91swimb2Wx2hzObD+K7k2T6lUICdTgVFBI/PI8f7kCzLF7o7WYZysG7Mh458fnThw/voyKUk2trYUbicYc2aO06SuXXbkloiNZ8ovWdJ6GvLAnlPG6TZlnD5o0N3lnRnTd6XdismvRROVUPMTTLI3U8qiyxVvU1bz4PfW+WlbvDEY9Tv9uxg5b2aIjmMZ874djh8q8ZKjfLzz1bfrqE/O5w9iv2ibtOZTuUc6zp9Qu/0B89eoiO6lRWZlVZYjzWujcfpXSq69zpEhN3TSWiUO8krTVf/c1UeazqptWpmRqhzeZgeOXxUvnh8tC3VqINVVoS+tSmlW06qLnQsX7Hpq1v3lixoc2VNMzdFge1BnKrC52iQWaJNis+qFsrJkj2mmg9dBEMxdvHJoe5q2BziGIztYkXm79aCKcmdkuzuqO1eOOub/2xuOHdrOcdj1+2m3xi9uzQaI3LIyShSeiePtyF52XNfc+JVpSqvuZKfPUyzvV9tHnipZCiW5bIblasfbVzXEQFRvPh7tFFL5RT6dhZ9En3Jh7Bs47Cad0nrssvpZI7dZuazUeKlZsb15v0azHHdcXmecuDijvFyr70ARjhJL0Hg02a1e4Tl6XBok/MG3c1inesI2Fi4tMWjzRP/wvmrHBqP24onHon1L6sfWkAPJpCDKe6dGuWZk0eyFncW79xeS4c4G9bFKdQ5dAvFuzY5KlZao+KAoPVZcOp+SU8vZ0L2MxJqE3GhcG42KociGWHqe4QssTTbEP7lcj5ms1QON2pHr/19Iw1l0LR+gJyCaC4cUfPV8Gg12XTNLQ1y9pyWRQtg2Lqsblx0wxGUT3qksty+fX1l8hy3L+rAZhU2Ix3SkfpzjY/vJqwSD8P5Pqh/9JNJD6t7HTV3Ivd4W/rm4Pqx61HyzrPneLYcdWdW2D8g7A7aYiBu5MmSLoTiTKLs0n6ZIHB6tEDm1Bp4p0mYKBBiIVTVsCgEP3cubO3bYLkZDWzWbSJMZDGtdS+/97/826T475wOe4Q1d2JuZtIJYBqFr1b7VvOZoVDOTVC0e4TZ7Hy8Npac2X5hZ5jzWCBUd7o+cPd40oMJg/hw8LAMPfH1qB+0NHXX9bgh4XqyzLt0Yf37969Dd41B5vln6+m+kjnvK8F+ssYdiWWgtN04xaz4jtuYxA7leVsVnsmtHw162HutPyH8aBVPuaiwSZgsEPfIv0lKyu/8lj2mc0Tx7qsFTDO/TmdhxhyGxrDx4P2klRSwsCybHPmPzh/FmeneaOHoUrOiucKQHHj7paEelkWQ0Y8KItLMxhNjps3fzAe+Xl9bfQH7D2DUVUeQx93sAIAXirD5neiuoY1/aD2DT4D16ryCyuDIc0qi+671NyffUmxpiWJYWyQJX0sxOkmG8iNr/4QcVB7CsB2xzZnBcOmrYOwzEWD55K0qTkXYmGTTfpsY4AkkSgbuZ2C07JPTF2ZRVNR1EfRYJdYecjIaRnutKIpVNWj/cSyx7stKrBLXdZlcVPu7POfWRu2nvXCpmmPaFHx6dNHfrhvj2N7a3TsaJpQab6szlblfNd8TU6hZ4/+hg4Jg2WJ5fKe49bVo3ajFQM3urehk/xl6Lnw9EB1LmBQjlvM7wyMuqeR02nGI0yDQsNjBEX9ZejjV+M7g/EI9SMXEXp9nMFIh/4hBoMvaC5zwNtNKUWvGq3ZnaX5bVE6eKShyjCuvHsiwUM5JxJYz2OJQbdmtbVyorUoMFSiwarAgPxlPWDHI05DU3A6b21oCxg8S/Snp0Ji4ddak/h1GqXy61gxi16U7vYwCLEs7iSGtiqtwnD0DR3fuLzduMX4TuvNT7NZlx4N+3E92Jzku/NlsjkXLNYMN26qj0QLjPaXtWsb2k/NK4ej6ZSHsjhhEonNsTAr3i0OKt+dOJtVVXfG5zE2TBzky7PX1yFtGlS/YIg4KNgYmJjY2k2fbCbUI3EWrcvpIH5YqHyVYoqeN79Lal1N0tuxtr29Ba9Orfn6KymH7h7UrySVtXIKw1R9LJymblbHFEDRqVy+NPPwDrqCzXYweIoCjF2b9Nt3kHuJ1eBd2PzyVO7WlUXHL6zlhkrHGEBXGzqGO5xo9VNzJDgNhurRsf8M6lNSjru7eKfJcRGnDK7OdxmEVBOtna9mfHpcD7uTmvSLQ4Rf0wezwKND8ggf+I1a6OLVbzv7FHVZa3i0LnScyQYkWfPY5LiP03zNBvvEi2nYejbPSJSWXAgeFfHHzdFaMX1UKjaLSfpKk4hUeWR1anpy8ky0Agy2SmWzrCi/FEVrxgtf2M1qT1t/o/ArSJvQXIk2eGfmMqvmwuDdLMtxWZy6ffsWW4mMZTm+M8T8BUNS9FY4lWVx99/lqnI5HYRL9x6G8SCfPpqgjWQ5HpQ3v1suG84FpC+rCRhSltiRhPqr2Tx9p+qOaVZHsBlld887v6ygK5s/EaaD3IEUdqmc3gn9oMr3qJTFDfNhpEml5SkoRzwq+UsTiucuNzUGgxOtpdoXnfFOrrlPXEvCL/M94qn59XM2CImytcPglEGz+2mI4V5pEDJXBoPnvI/rH+54u3QXLTDcyXDzWFm1rmT6TTyymA7lQRuDRdixOe5XYhCWmYGqd0LfjUWrvoNenPpnxaxx7Fwwd5Y1nw66jhCtXfmL1Skr+97yPKj6cfnbngnHWixavz684f6s/LCaNMtKg1Z0v+v1F283mcnD4zT6dW/yJrtZvryrXypfoo+0wEix8hGL9JO5jBuoNsfaH9Hsrmh4XLjDkdDkIfEbrDr180/JCGDH67Lh3Bl9fTQVvyoXyTeukFh/afO4zdPDRzyY5J6dLuS46dAfmearma0AJ8I4cWwHxZFQhOEpzqJ7XZb+r6ZPMTFx8+5YmhXEQcVkWQwGw2+L9OPa7q94TZ/lndd/xolZjn4xGDSJgRcwzobpI27+uNXckatTX09WrcqgFF/1eCRoj2x3OpZ/tIS7VmHouBLNwaMwSnx7tLyyvh78MRio+sDsXazfCeoaa1U+spaBHwzTroXOXW57d/IQQ1k9OkqnQf64oTplV2LyN3nFRmvKcS+ZRWiy5KJcdjwkiTyUMcU8qGpzN/GIdTw4ZfCJAzDu7HPf7hS618Zh66s0OLVXp/ltEToeEzfS8NT5y8M+3NpAdcmHm0z4FWazOh//+qkobZpl5ZHhjieJ7mqdPDabYJCaRARRou9OrL+s2uhXLu/Uw01MEuvf9oevXxHMd5mobEURAIPNVNP/a7Myf6EG4JrFIxdtsiw6fiGIlYd8WSaLS55WBz/bfE00wXzFc8GXn3+MKlrjWGJhEFIJPKzRmmVxDAbTuUDR4L/LJuWmcTObcavmZNjcKZaE3s8zoaevx/maqBQf8eX59MctzcpefUk6xZr74KnJ5QtXKAaDHsrSFhr+bh72Y82HuY+fsvrLwPKmPeJsVvPm/+GWXEEu2zw9UrwzdYvxTtSnZFkcfY8YKudOpRWtW+fCezDY9JYEZ78YyxYDuefOTk0lOzf/skIkfiEYGXqb+OftTYym4ancCfWDoT4Xou/RBZv3paTSfZstzWriBZitdQzFP4xHh9OcZj31mj51a2bJtZXfnfTq3KNo8FzUp9i7YwFDyKHTnZWurGDgUS9v87hb6Fifh37H8haPdC1v4h2sPQ81/aD29TurFHg0d0oKp1gfaQ7lJG26dvEq3/wmGHRDd/64MQndOMRg83BSYJjq7v794tSk+UuYzfozVneaNKutCG02P9g8hlD87ZvxrdJeNhUYGGu+ia8OgsmmVa0fzdw1W2saAfjUI40Akj/rgTPRQJV2a9ydDV+eT880K82ENtFaMiyja7YbloUud3El+rjyjNXW7NRs8hSEV397PI+cponZgeXDh/ukw9MK18Kh333jjrv1zk9rh7uvrOfepF99Zk6DYXcK5+ObtvzYtaAf+dFH0ZM85Yi1oXOB4fH7LBpM6/PdsWZcMnSP00fupp+vxPpGhI8fMZx68SLLcT8txWAzuOmvWKyZfRKZhFYaANj6+5ByP/Y2dPP02QfAFBI5zZp5MKD29eGpy4c6vqyw+e1o6h02uDuLWVLJ0t3fdmrauTPZvtDdTf9AdtgI3jLY8Mcf8Vd/+XMMxcPmF0MM2fHL7O5PnpgIFp4XmULj0MjMgJS7urPYSnz0KIAk1nkl3o4VgDJURhErN0nu8Fh2O9o8Nil01Yb2ed/f4QHDfL4Sc112sStPiSn6+19YlqXqzovW6IhlO0/lrt/WRkJDIoH2qWzxyMCPm/ziX3Zu/s0/TiOsHzzFz4eAoYnWPgd/kyTwqCP9ZFHBC/3GjSbNClfu36EofjZ56d0YHu6MheULbZCnWUsP6QudD4Zo+j0Yy87aqzl29MiR4Gpt+g46Daay8utkIuGheHXu3F5ty/TdB8DPBb6aCCAJjpAkC4ycZvmHGy3L8zR0SxvUBPp4EpXoA+2mS7/FdpOBHkK7aSLZGKzZfE28ceHSqSZaC+64T1bT43fMYFxJM5t26H/xK4t3CizST5eK293TCMA/3LXoXTM/675HyyGamr5rta9wajZXFgburBDLOssgnJqR0NIca7b5L8LuFL8tih93PuRBYz+HcGoqyHHP2J3yNm3+qB/6VSSOOhT3FL0Jpy4U/iYeDOZobbJcPsYLaAcMHzyHzr5HqQLwyGYkChfJ6wu7pVnxzhp9sboaf1ymWTEJjcs/W87L87dF+ePOhQmV8Gqa1NqTUL9xTZMYzO6+LC8tUZ4STKFu45mHU7MDN+51ryrbuXAxzPvmG9ddswvAjKVZ/mU92EqmVqvx1Q+ME9/825ni4WnWkUBoOe+zWWH3qzTOAob3me5jj3/r1s1A94myOB5rZgq1wDQrNlSOdMcjPxV8nObKClXlrYzHuWXutSYafBgt0T2NiwMwhUzf3530ZW1vb2VCiycSyJrH9YTfWVjN4qDKF3o2Pj3DHStshlD2lHezbBY9Oh/Hd2fpw/AJEn/6e1NFho7cS/RzJxa/otlde4IkbP4dqyonQ/cndBpsVY88WvNYtjPN8tpX6GY98d/2wRb+cn8T0x5Z9Yiv/pUrka1kfvQL6Ups3ykTsQ29SdHgSDzWnq74+g+7Dn27si4tzZx3b1+/0CciWulXdFaP/EqkKbd76TFUXnIyVGeatcRuFh//THj1j4fyjm/+j47lih6eYfQrKDZXPtaTZRiwIDWL0HNmOnWjVoqXvkQ+vsPyS+hyoz259tfJ5sfd+Vp+Zs17ujPwJ6/Snzy5PMDN6qSKtf7/6lyIH5alWZmtFG2t042elx9d2Gt5xFPZ0rgvcf28PMu+M0+LY20yFzbj0+9ccdFgk6i8ncrWO+XjPzxgRfFPsXS3sJmffqY8NScxcff9yWO/x915afHI5R9bX5YnoUefesBwkB+uPf2ihcrbv8+/noVNqDy/k/+Pne4N9j+t/l31D9jrx93v8uhe/9uXx7c8/m7L42Pv3fHl0X938l+t5+74H6D/7vifoP/u+J+g/+748ui/O748+u+OL4/+u1N8a/12x/8B/XfH/xT9dycs1H93fHn03x3/D7Hn4xNnOWz51UtpeQyuPzeytXn1h2/dfOz38Zvlrx7oevrxcWoS2c2yNC4Fm+9/+XesuHFfXJnY3+ZDc6zxryY51lxZ1/NYezr65K05DfannNJbBArKKVuJUFBOCTmFgnKa06yelFNKHqGgnJI1AAXllB0DKCinhJxCQTn1bpaAckoFAxSU02EWGN9MOSXkFArKKd98KCinNBSDgnLKzYeCcrqn0+B+KaeUxUFBOY1pVm/KKSGnUFBOfTZLQDnlNDQUlNMoGuxNOe2czfoeymk0dO9NOX1vFhgCymmczepNOaXqDgrKKT8sKCinlDxCQTlNFhh9Kae80KGgnBJyCgXllFVlKCinPJShoJzy2IGCckp3Figop26BIaCc0qICCspptMDoTTmlKRQUlFMeylBQTvn0UFBOKW2CgnLKVwcKyum/YTarN+WUryYUlNMrNpsloJwGp8H+lFMeO1BQTg/Us1nfTznlqQkF5ZQ3IhSUU5vNUlBOuflQUE45ZAAF5XQfhu77o5zyRoSCckrIKRSUU0JOoaCcUj8CBeWUgT4UlFMO0kNBOeXTQ0E5ZRMdCspp6TTYi3JK1R0UlFO+mlBQToMFRn/KqYkGFZRT+oNAQTnlqwkF5ZQ2A1BQTjOeuCflNBi696ecmqG7gnLKDwsKyikhp1BQTmm3BgXllE8PBeWUoTIUlFOSGKCgnJoFhoJyyg8LCsopIadQUE4JOYWCctrlNPhdlNNv52YNoZxyMA4Kyik/LCgopzabpaCcUjkFBeU0c7N6Uk5p4QkF5ZTxAhSU0z24WfunnJL6BQXlNIkG+1JOOagPBeWU08pQUE45VAkF5ZQ5KBSUUz49FJRTVpWhoJzyToGCckrIKRSUU5bWoKCc8tWEgnJqokEF5ZTxAhSU05Bm9aecslMJBeWUiQQUlFPGI1BQTpMFRl/KKSGnUFBOCTmFgnLK5aGgnLI+AgXllPEIFJRTjqJDQTllsAYF5dREgwrKKTcfCsopoykoKKczhicWUE6joXtvyimXh4JyOmPcLAHllL8tFJRT00MqKKfmNKignE55mtWfclpws/pRTueyBUY/yuly22nweymnhJxCQTnl5kBBOaUGAArKKfu4UFBOWbqDgnLKYA0KyinDHSgopzw1oaCcRkP33pTT2M3qTTml4ToUlFPKU6CgnOZuVk/KKesXUFBO3WlQQDllvAAF5ZRPDwXllGkQFJRT72YJKKdhNqs/5ZRed1BQTgk5hYJyylcHCsop28RQUE55akJBOd0xbpaAcspDGQrKKaVNUFBO+fRQUE6proGCckrIKRSUUx47UFBO+eZDQTnlnQIF5ZSQUygop8zQoaCcDulmfTvllGVZKCinjEegoJzSRRIKyinzFCgop+xIQEE5pagPCsopxTtQUE4Zj0BBOWWSCAXllBUAKCinhJxCQTmlqA8Kyik3HwrKKcMdKCinbENDQTllPAIF5ZT1Cygop7Rbg4JyammWgnJKyCkUlFOfzRJQThnuQEE5dTyxgHLK5aGgnPJCh4JySuEXFJRTdrmhoJwyHoGCckrIKRSUU746UFBOeadAQTnlqQkF5dQsMBSUU575UFBOi25WP8rpIRMNCiinjKagoJzyXICCcsqqMhSUU/ZroKCcsuEBBeWUxw4UlFO+OlBQTpmhQ0E5NUN3BeWUryYUlFPmKVBQTgk5hYJyyiQRCsopI3EoKKeMpqCgnFo3S0E5ZQ4KBeWUoj4oKKdzMc3qSzlNhu59KacMlaGgnLIRCgXllPoRKCingZvVn3LKFBoKyilnp6CgnPLpoaCcsgIABeWUHQMoKKcmGlRQTvn0UFBO+dtCQTnl5kBBOTULDAXltJ1mfTfllBUAKCinPJShoJy6BYaAcmp4YgXllB8WFJRTPj0UlNNiNqsf5dREgwrKKcu+UFBOCTmFgnKauVk9KacsMEBBOeWdAgXlNKRZ/SmnBMxAQTllrAkF5ZQKCSgop2xDQ0E5ZekOCsqpzWYpKKeEnEJBOaWCAQrKKS90KCinNpuloJyuR0P3vpRTLg8F5ZTSJigopyU3qxfltMAT96OccnkoKKfsVEJBOY2zWb0pp26BIaCccnkoKKdjJhoUUE4vF92sXpRTflhQUE6Nm6WgnHJzoKCc8syHgnLK+gUUlFNCTqGgnNKOHgrKKYcMoKCc8umhoJyypA8F5TRYYPSnnPLKgoJyyngECsop4wUoKKeEnEJBOeWpCQXllJBTKCin/LCgoJyyLAsF5ZR3ChSUU/62UFBOGe5AQTnlkAEUlNNogdGbcspTEwrK6fOQZvWmnAZD9/6UU7KJoKCcsjgFBeWUOS4UlNPkVd+XcsrfFgrKKYtTUFBO7xqeWEA5JcwQCsrpQUuzBJRT0negoJyy4QEF5dS7WQLKKTcHCsopnx4Kyik3HwrKKYM1KCinhJxCQTllBQAKyumcOQ0KKKcMd6CgnDLWhIJyyuoOFJRTzopDQTllVRkKyimXh4JySsgpFJRTN3QXUE4pCIWCckqXBCgopzyUoaCc8s2HgnJ6LXKz+lJOWVWGgnIaRYO9KadcHgrKKZeHgnJKyCkUlNMNM3QXUE43rJsloJweGnFuVm/KKUNlKCinvBGhoJxy86GgnPK3hYJyak6DCsopD2UoKKeeZgkopwFP3J9yyt8WCsrpE+9m9aecPvQ0qz/llIE+FJRTXllQUE7520JBOeWHBQXllPECFJTTgTTreymn/G2hoJwySYSCcvosGrr3pZxOWZoloJxyeSgopyYaVFBOeWpCQTm1bpaCcsoLHQrKKTcHCsopHTagoJyyUwkF5ZSvDhSUU5/NElBO24bu3005pfoFCsppxc3qQznl5kBBOeXyUFBO2amEgnJKyCkUlFPDEysop/wPoaCc8t9BQTlNcCkFxxMKymkbmdqLVAkNDtByEQ3HEwrKaUamCjieUFBOQ6dGw/GEgnJq35qCcvp/PLECT7xPymkHnvj7KKf7xhPvRTnljQgF5fR/Ek/8dBT4L9wxn4vN6QAA'));
var byteString = "";
for (var i = 0; i < byteArray.length; i++) byteString += String.fromCharCode(byteArray[i]);
document.querySelector("code").textContent = decodeURIComponent(escape(byteString));
<script src="https://cdn.rawgit.com/nodeca/pako/master/dist/pako.min.js"></script>
<pre><code></code></pre>
RASEL, 11 bytes
<@,Yj5#?:,"
Pyxplot 0.8.4, 62 bytes
q="'";Q='"';s='pr"q=",Q,q,Q,";Q=",q,Q,q,";s=",q,s,q,";@s"';@s
This quine makes use of the macro expansion operator @ to execute the code stored in the string s. Both quote characters have to be extracted to variables because there is no way to get one without the other (not counting backslash escapes, which don't help here).
Fun fact: replace pr with print and @s with eval s and you have a not-so-golfy Ruby quine.
Scratch, 542 bytes
when gf clicked
set[s v]to[when gf clicked/&set[s v]to[/&set[i v]to(0/&set[q v]to[/&repeat(length of(s/&change[i v]by(1/&if<<(letter(i)of(s))=[/]>and<(letter((i)+(1))of(s))=[&]>>then/&say(q/&set[q v]to[/&change[i v]by(1/&else/&set[q v]to(join(q)(letter(i)of(s/&end/&if<(i)=[28]>then/&set[q v]to(join(q)(s/&
set[i v]to(0
set[q v]to[
repeat(length of(s
change[i v]by(1
if<<(letter(i)of(s))=[/]>and<(letter((i)+(1))of(s))=[&]>>then
say(q
set[q v]to[
change[i v]by(1
else
set[q v]to(join(q)(letter(i)of(s
end
if<(i)=[28]>then
set[q v]to(join(q)(s
Try it on Scratch! (link is to a project that uses lists as output for better readability.)
This uses a classic method of storing the data in a container and uses it to make a quine. Because Scratch doesn't allow to initialize a list in just a single block, I have to use a variable of string and encode /& for a newline.
Explanation:
when gf clicked // when green flag is clicked (the start of the program)
set[s v]to[when gf clicked/&set[s v]to[/&set[i v]to(0/&set[q v]to[/&repeat(length of(s/&change[i v]by(1/&if<<(letter(i)of(s))=[/]>and<(letter((i)+(1))of(s))=[&]>>then/&say(q/&set[q v]to[/&change[i v]by(1/&else/&set[q v]to(join(q)(letter(i)of(s/&end/&if<(i)=[28]>then/&set[q v]to(join(q)(s/&
// the above variable `s` is used to store the content of the whole code, apart from the content of itself, which we'll try to tackle using the below code.
set[i v]to(0 // set the counter to 0
set[q v]to[ // this is like a buffer for what we'll say on a line
repeat(length of(s //repeat for the length of s
change[i v]by(1 // increment i by one
if<<(letter(i)of(s))=[/]>and<(letter((i)+(1))of(s))=[&]>>then // if we hit the newline
say(q // then say what is in the buffer
set[q v]to[ // clear the buffer
change[i v]by(1 // and increment i, to avoid parsing &
else /// else
set[q v]to(join(q)(letter(i)of(s //add the letter to the buffer
end // end the if-else
if<(i)=[28]>then //if we hit the 28th character, which is right after the initializion part of the variable s
set[q v]to(join(q)(s // then we add the whole content of s onto the buffer
Perl 5 + -p0513, 29 bytes
s<><s<><@>;s/@/lc/e>;s/@/lc/e
Explanation
s<>< >; # Working with `$_` by default, `s`ubstitute (`s///`, but using
# `<><>` instead of `///` to allow nesting) the empty string...
s<><@>;s/@/lc/e # ...with the body of the quine.
s/@/lc/ # Then, again working with `$_`, replace the first `@` with `lc`...
e # ...and execute the result (calling the sub `lc` which returns its
# argument, or `$_` if no argument is passed) `l`ower`c`ased, which
# in this case is the body of the quine.
# `$_` is then finally `print`ed because of `-p`.
!@#$%^&*()_+, 1128 1116 1069 960 877 844 540 477 407 383 33 bytes
Edit: Woah... -304 B with space
Edit 2: Bruh.
Edit 3: Thanks Jo King for the idea! I outgolfed ya!
A stack-based language(The first on TIO's list!)
It's a big pile of unprintables though
N0N (!&+$*)^(!&@^)!
(Spaces are NUL bytes)
Here's the code, but in Control Pictures form:
␙N0␖␑␘N␙␚␔␛␀␖␑␘␀␐(!&␐+$*)^(!&@^)!
Explanation
␙N0␖␑␘N␙␚␔␛␀␖␑␘␀␐ Data
(!&␐+$*) Push the stack, reversed and +16 back on top
^(!&@^)! Print everything reversed, including the length (Hence the final `!`)
It does error on overflow though...
tinylisp, 2 bytes
Very simple quine, and (one of) the shortest possible quine(s) in tinylisp. All top-level statements implicitly output whatever they evaluate to, and integers evaluate to themselves. Any 1-digit integer from 0 to 9 works fine for this, and a 3-byte quine is also possible using ().
1
Joy, 32 bytes
[put "x." putchars 10 putch] x.
Joy is a stack-based language. It has an interesting operation, x, which means executing a block without popping it. So [P] x is equivalent to [P] P. This is useful for writing quines.
Python 3, 34 Bytes
print((s:='print((s:=%r)%%s)')%s)
As far as I'm aware this is shorter than any other published Python 3 quine, mainly by virtue of having been written in the future with respect to most of them, so it can use :=.
Insitux, 171 103 85 bytes
(#(join(char-code,34)[%,%(char-code,41)])"(#(join(char-code,34)[%,%(char-code,41)])")
Note: Commas are treated as whitespace.
Try it! (The Insitux REPL replaces commas with spaces, but it still works.)
Explanation:
(
#(join ;Function to process string
(char-code 34) ;Join the following with '"'
[
% ;String (first half)
% ;String (second half)
(char-code 41) ;Code for ')'
]
)
;Same as above, but in a string
"(#(join(char-code,34)[%,%(char-code,41)])"
)
7, 1⅝ bytes
7 is an Underload derivative that I've been working on over the past few days. Being an Underload derivative, it's particularly good at quines, so I thought I'd come to this challenge first. (Unlike Underload, though, it has support for input. Like Underload, it's Turing-complete, thus meaning it can handle all the tasks required to be an actual programming language.)
The program itself can be expressed either in octal encoding (there are only 8 commands, named 0, 1, 2, 3, 4, 5, 6, and 7, that can appear in a 7 source file):
23723
or packed into bytes (the language sees them as raw octets; I've expressed them as codepage 437 here):
Oº
(The interpreter ignores trailing 1 bits, so arguably this program can be golfed down to only 13 bits = 1⅝ bytes long via removing the language's equivalent of "trailing whitespace". Languages like this are a little hard to count.)
Here's how the program works. 2 encodes "duplicate", 3 encodes "output and pop twice", thus the combination 23 means "output and pop". The program will thus start by pushing two 23 units on the stack (these are initially inert, but become active as they're pushed). Because the end of the program was reached, it's replaced by the top stack element, without disturbing the stack; thus the text of the second 23 gets output and popped. (As it's active rather than inert, what actually gets output is a string representation, 723, but the first 7 is interpreted as a formatting code that specifies "the output should be in the same encoding as the program itself", meaning that the quine works in both encodings.) Then the same thing happens for the first 23; this time, the whole 723 gets output, leading to an output of 23723 (or Oº).
This is a true quine via all the definitions we commonly use on SE. For example, the first 23 encodes the second 23 and vice versa, meaning that part of the program encodes a different part of the output. Likewise, this quine could handle a payload just fine. If you didn't require a true quine, you could use the following ⅜-byte program:
3
which is a proper quine by some definitions, but not others. (The stack starts with two bars on it, meaning that the extra pop that occurs after the output is printed is harmless.)
TypeScript Types, 149 bytes
//@ts-nocheck
type Q<A='`',B='$',C=Q<'${A}','${B}','${C}'>>=`//@ts-nocheck
type Q<A='${A}',B='${B}',C=Q<'${B}{A}','${B}{B}','${B}{C}'>>=${A}${C}${A}`
TypeScript Types, 209 197 bytes
Without @ts-nocheck to suppress compiler errors
type Q<X extends string[]=['`','$',Q<['${X[0]}','${X[1]}','${X[2]}']>]>=`type Q<X extends string[]=['${X[0]}','${X[1]}',Q<['${X[1]}{X[0]}','${X[1]}{X[1]}','${X[1]}{X[2]}']>]>=${X[0]}${X[2]}${X[0]}`
Zsh, 40 bytes
s='s=\47%s\47;printf $s $s';printf $s $s
Until recently, this was the shortest universally trivially modifiable quine. Uses no external commands (printf is a builtin).
(Lesson learnt: don't describe your answer as the shortest possible.)
OIL, 77 bytes
Quines are one of the things that aren't that hard in OIL, because of the whole "unified memory" thing. The quine exists since a long time, but I hadn't posted it here yet.
The following code needs to be stripped of the comments to work:
0 # do nothing, these two fields are just placeholders
0
1 # copy the line above to itself
1
1
4 # output line 1
1
11 # and a newline
4 # and output line 1 again
1
11 # and a newline (now we printed 0 and 0)
1 # copy line 2 to line 2
2 # *
2
1 # copy
12 # line 12 (the one marked with the star)
18 # to line 18 (marked with $)
10 # ^, if the next line (currently 2) is equal to the line afterwards (1)
18 # $
1
32 # jump to line 32 (essentially quitting, because it's out of bounds)
22 # otherwise to the next line:
1 # copy from 18 ($) to 26 (&)
18
26
4 # output from the cell with the number in the next line
26 # &
8 # increment line 18 ($)
18
11 # newline
6 # jump to line 17 (^, beginning of the loop)
17
Vyxal 2.6.0, 4 bytes
`I`I
Posting this as a separate answer because it's using overloads not available at the time of the other answer.
Explained
`I`I
`I` # The string "I"
I # prepend a quoted version of that to itself and implicitly print
Ruby, 26 bytes
printf x="printf x=%p,x",x
Not the shortest Ruby quine, but I think it's quite cute so I'm posting it.
Ruby, 27 bytes
p S if$><<S="p S if$><<S="
Ruby, 28 bytes
printf *["printf *[%p]*2"]*2
Ruby 2.7, 34 bytes
".tap{puts p _1}"
.tap{puts p _1}
Ruby, 35 bytes
END{p$0};$><<$0="END{p$0};$><<$0="
K (oK), 9 bytes
`0:"`0:"
Posted with permission from @Bubbler.
So, oK has this cursed bug feature where prettyprinting of the output still occurs even if you print something else. `0 is the output symbol, and calling print to it with : prints the string, but returns the string as well, which is implicitly prettyprinted, with quotes to show it's a string.
K (oK), 34 bytes
{a:"0x7b613a22,a,0x223b2e617d";.a}
My attempt.
In K, hexadecimal literals represent byte values. 0x7b613a22 is {a:", and 0x223b2e617d is ";.a}, both of which are added to the string. So we set the value a to a string that when evaluated, returns itself wrapped in the boilerplate, and evaluate it.
ErrLess, 34 24 bytes
Thanks to Jo King for saving 10 bytes
S'R1+,$:@:?.S'R1+,$:@:?.
No trailing newline.
Explanation
S'R1+,$:@:?.S { Put the rest of the program in a string: ("'R1+,$:@:?.") }
'R1+, { Add a one-element string containing `S`: ("'R1+,$:@:?." "S") }
$: { Swap & concatenate: ("S'R1+,$:@:?.") }
@: { Duplicate & concatenate: ("S'R1+,$:@:?.S'R1+,$:@:?.") }
?. { Print & halt }
ErrLess is a stack-based language I made for fun over the last few months. You can read the docs here, and I also started a tutorial.
JsonLogic, 631
{"reduce":[[1],{"cat":[{"reduce":[{"var":"accumulator"},{"cat":[{"var":"accumulator"},{"substr":["\\\",:[]1abcdelmnorstuv{}",{"var":"current"},1]}]}]},{"var":"accumulator"},"]]}"]},[21,1,16,11,10,19,9,11,1,3,4,4,6,5,2,21,1,9,7,18,1,3,4,21,1,16,11,10,19,9,11,1,3,4,21,1,20,7,16,1,3,1,7,9,9,19,13,19,12,7,18,15,16,1,22,2,21,1,9,7,18,1,3,4,21,1,20,7,16,1,3,1,7,9,9,19,13,19,12,7,18,15,16,1,22,2,21,1,17,19,8,17,18,16,1,3,4,1,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,1,2,21,1,20,7,16,1,3,1,9,19,16,16,11,14,18,1,22,2,6,5,22,5,22,5,22,2,21,1,20,7,16,1,3,1,7,9,9,19,13,19,12,7,18,15,16,1,22,2,1,5,5,22,1,5,22,2,4]]}
Try it online by pasting it under "Rule" here. (Note: the "Output" section is JSON-encoded. The raw unquoted string is logged in the console which can be viewed with F12)
Grok, 42 bytes
iIilWY!}I96PWwI10WwwwIkWwwwIhWq``
k h
It is very costly to output anything in Grok it seems.
ed(1), 45 bytes
We have quines for TECO, Vim, and sed, but not the almighty ed?! This travesty shall not stand. (NB: See also, this error quine for ed)
a
a
,
,t1
$-4s/,/./
,p
Q
.
,t1
$-4s/,/./
,p
Q
Stolen from here. It should be saved as a file quine.ed then run as follows: (TIO seems to work a bit differently)
$ ed < quine.ed
Alumin, 350 bytes
hhhhhhhhhhhhh hhhh hhhhhhhhhhhhhhhhh hhhhhhhh hhhhhhhhhhhh hhhh hhhhhhhhhhhhhhhhhhhh hhhhhhhh h hhhh hhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhh h hhhhhhhhhhhhhhh hhh hhhhhhhhhhhhhhhh hhhhhhhhhhhh h hhhh h hhhh hhhhhhhhhhhhhhhhhhhh hhhh h hhhh hhhhhhhhhhhhhhh hhhh hhhh h h h hhhhhhhhhhhhh hhhhhh hhhhhhhhhhhhhhh hhhhhh h mdqhldthadtlaocpladadtdadoddaaamfof97
Alumin is a stack-based language that only executes the lowercase alphabetical characters.
Explanation:
hhh... Each series of `h`s represents a single alphabetical character. h=a, hh=b, hhh=c etc.
m Map each element to
d Duplicate the element as a loop counter
q While that element is positive
h Push 1
l Push length of stack (3)
dt Square (3*3=9)
ha Add 1 (9+1=10)
dt Square (10*10=100)
la Add length of stack (100+4=104)
o And output ('h')
c And subtract the first 1 from the counter
p End loop
la Add length to the end result (0+2=2)
da Double (2+2=4)
dt Square (4*4=16)
da Double (16+16=32)
do Dupe and output (32)
ddaa Triple (32+32+32=96)
a And add to the original value to get the ascii character
m
fof And print each value
97 The program prints the last remaining value automatically
ALGOL 68 (Genie), 70 bytes
STRINGa="STRINGa="";print(a[..9]*2+a[9..]*2)";print(a[..9]*2+a[9..]*2)
It's fascinating how modern feeling the syntax of this language (or at least the parts I've used), despite being over 50 years old. I wrote this without looking at any documentation, simply guessing at the features like string indexing (with ranges even!) and string multiplying.
Explanation:
STRINGa="STRINGa="";print(a[..9]*2+a[9..]*2)"; # Assign this string to `a` #
# This escapes the " by doubling it #
print(a[..9]*2 # Print STRINGa=" twice #
+a[9..]*2) # Followed by ";print(a[..9]*2+a[9..]*2) twice #
Agony, 243 bytes
<[.<]>[{(<(<){*}*{(>)}~)<(<){-.+(*}*<{)>(>)>}]${(@]@){,{.{[{*{]{)+*<}>[>*+)+]{@$${<{<<$+(@[{({.{({,>]@(>]+[>){,{({.+(@[+({,+(@(+({]+({)+({.<$@[<${-+({<@[+[>]{.>]{->]{.+(>){,+[{,{-{({]{[+({.>){->){.+]+[{.>]{-+({,+[{,+({.>){->){-+(@(>]@[>){]@(>)
This looks like a bit of a mess, but this language is actually a brainfuck derivative, similar to SMBF. The self-modifying part is not used to read the executed code though (especially as each instruction is not mapped to one character). Agony splits up each brainfuck cell into 4 bits each (with two cells being a "character"), with special instructions to manipulate individual cells.
Explanation:
The code is split up into three sections; Code, the printable list of characters (offset by one to avoid the zero cell in @) and the data section (which is the printable version of the other two sections backwards).
Code
<[.<] Print out the data section printing the code and the list of chars
>[ Loop over each 4 bits of the data section
{( While the current cell is not zero
<(<){ Go to the start of the character list
*}*{ Move it over one cell to make the next character the new start
(>)}~ Go back to the current cell and decrement it
)
<(<){ Go to the start of the character list
-.+ Print it offset by one (`@` is 0010 0000, so we store it as 0010 0001)
(*}*<{) Move over all the other characters by one to restore the list
>(>)>} Move to the next cell in the data section
]$ End the loop and halt
This section is modified or read (except the $, which separates it from the character list section).
Character list
The character list is the section between the $ and the $$
{( @] @) {, {. {[ {* {] {) +* <} >[ >* +) +] {@
$ } { > < @ ~ + - . , ( ) [ ] *
Each pair of characters represents 8 bits each, which is the ordered list of the 15 instructions in Agony (offset by one).
Data section
Similar to the character section, each pair of characters in this part represent a single character in the code section. You can have it more efficient by just duplicating the code section entirely (thus being one to one), which is actually how the reference quine works. However, I think that even golfed, this would still take more code to handle duplicating the data section than it would save (but I'm not too sure about that, so feel free to prove me wrong).
Agda, 160 bytes
open import IO;open import Data.String;main = run(putStr(r ++ show r))where r ="open import IO;open import Data.String;main = run(putStr(r ++ show r))where r ="
Agda is an interesting Haskell-like language with some interesting ideas and a lot of imports. Luckily I've managed to avoid most of those (though my early attempts weren't so successful). The version on TIO is a bit out of date, which led to some frustration with the docs, but I think this code should still work with the latest version.
Explanation:
open import IO -- Import the IO library for `run` and `putStr`
open import Data.String -- Import Data.String for `++` and `show`
main = run(putStr -- with main, print the string
(r ++ show r)) -- r appended with the string representation of r
where r = -- where r is
"..." -- the string of the rest of the program
Javastack, 64 bytes
"34 char swap add 2 repeat print"34 char swap add 2 repeat print
No TIO yet, watch this space!
Javastack aims to combine the verbosity of Java with the stack-based paradigm to create a truly horrible programming experience. I'm planning to make up for the verbosity with a truly immense library of functions, but it's all a work in progress.
Javastack doesn't have any way to get the character " aside from 34 char, so that's what we start with. We prepend it to the string currently on the stack (which is part of the code) with swap add, double it with 2 repeat, and print it, resulting in the source code.
-12 thanks to Aaron Miller - outgolfing me in my own language!
Vyxal D, 12 bytes
`q\`:Ė\`+`:Ė
What differences this from the other quine is an eval quine so is easily payload-capable - that is, all the processing code you need can go after the + and only needs to be iterated once.
Will be 9 bytes once parsing bugs get fixed.
` ` # String of code to be executed
q # Quotify / uneval
\`:Ė\`+ # Append a `:Ė`
: # Duplicate
Ė # Run on itself
Pxem (esolang-box notation), 21 bytes.
I originally posted this as a cheating quine, which I noticed it disqualified for the problem.
.fak.-.f.p
.fak.-.f.p
How it works
In this notation,
- 1st line is main routine.
.fis forpush its own content from 2nd to final lines.
ak.- is an idiom to push LF; .p pops each item to print them.
Nim, 87 bytes
import strutils;let s="import strutils;let s=$1$2$1;echo s%[$$'$1',s]";echo s%[$'"',s]
Shakespeare Programming Language, 6060001 bytes
Disclaimer: I do not take credit for this, the generator was made by Florian Pommerening and Thomas Mayer.
An Epic Never-Ending Saga.
Paris, a stacky person.
Pinch, impersonates Paris.
Venus, the opposite of Paris and Pinch.
Puck, continuously speaking.
Ajax, constantly complaining.
Page, perpetually blabbing.
Ford, incessantly talking.
Viola, ceaselessly communicating.
Act I: Prelude.
Scene I: Best things last.
[Enter Venus and Paris]
Paris:
Let us proceed to act V.
Act II: Remembrance.
Scene I: Forgetful Venus.
Paris:
Remember nothing.
[...]
Translated C Code (requires spl.h and libspl.a from a bugfixed SPL version to compile)
Klein, 13 + 6 = 19 bytes
Martin Ender has made a shorter Quine here
+6 from the 000 topology and the -A flag, (also works in the 001 topology)
<:3+@+3:<"
Explanation
Like described in my earlier not so Quine the " character cannot be made with a string literal so we need to make it by doing math on a similar character, in this case the unit separator character for reasons described later. The difference between this Quine and earlier attempts is that this we can get around the restriction of having to read the string forwards by making the string itself a palindrome. This way reading backwards is the same as reading it forwards.
So when the program starts it passes through a unit separator, then hits < which turns it around, it goes through the " and pushes the entire line. :3+ turns makes a " out of the final unit separator and @ terminates the program causing it to print.
Unix Executable, 10 bytes
#!/bin/cat
When run with something such as ./file, it will actually call /bin/cat ./file (because of the shebang), which prints the file's contents.
Knight, 22 bytes
E=s"O+'E=s'++A34sA34"
Includes trailing newline. Try it online!
Finally figured out how to do an EVAL quine, after definitely not adapting the Ruby quine example on Wikipedia.
It is pretty standard. Create a string containing code to print itself, and eval it. A34 is used to generate a double quote.
I am keeping my original idea here as well.
Knight, no eval, 56 45 bytes
O S S=p"O S S=p7F=qA34 7F+q p"7F=qA34 7F+q p
Updated for the new ASCII function.
Includes trailing newline.
Removing the quine string and expanding the keywords/variable names, this is basically the printf quine:
OUTPUT
: SUBSTITUTE(
# insert closing quote for quine_str
: SUBSTITUTE(
: (= quine_str "...")
: 7
: 0 # we use FALSE to save a space
: (= quote ASCII(34))
)
# insert opening quote + quine string
: 7
: 0
: (+ quote quine_str)
: )
Red, 21 bytes
do s: "prin{do }?? s"
Explanation
?? is usually used when debugging, but it's also great for quines. Take the following code:
s: "foo"
?? s
It outputs s: "foo". Let's see what happens when we combine this with a do:
do s: "?? s"
As expected, we get s: "?? s". Ignoring the do, it's pretty much already a quine. We can easily fix this by adding a prin{do } before the ?? s:
do s: "prin{do }?? s"
Pxem Pxem (esolang-box notation), 162 113 109 bytes.
Eventually as in meta discussion I had to change the language. The following program equals to filename with same name and empty content in original notation.
Be!?BzBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBsBp".e!?.z.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.s.p
With comments
XX.z
# represents programs from first .m
# every dot has to be replaced with B, for example,
# because dots are syntaxically special
# append " to it
.aXX(long)".z
# essentially double entire stack
.a.eXX.z
# loop begin
.a!?.zXX.z
# move every character to bottom
# HOWEVER B is replaced with DOT
# when exiting from loop, the stack will be:
# "(original data)"(modified data)
#
# push dummy F if B is not top
.a.c!!.+.zXXF.aXX.z
# replace B with dot, and push F if F is not top
.a.cF.z.sXXF..aXX.z
# remove dummy
.a.sXX.z
# move to bottom
.a.t.v.m.vXX.z
# get out if "
.a.cAc.-.aXX.z
# finally; discard top
.a.s.p
Previous version
- 113 bytes:
Bm!?BzBcBoBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBp".m!?.z.c.o.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.p - 162 bytes:
XXx\è\ô\Ú\î\Ú\Þ\Ú\Þ\Ú@\V\Þ``\Z\Â\Æ\Æ\Þ\è\ì\Ú\ì``\Z\è¢\Â\ì\æ\ì°\î\Æ\Æ\ô\È\Â\H\Þ°\ÂQ.t.z.m.w.m.o.m.o.m .+.o00.-.a.c.c.o.t.v.m.v00.-.tQ.a.v.s.vX.w.c.c.z.d.a.$.oX.a
05AB1E, 13 bytes
2096239D20BJ
Beats all the string-based 05AB1E quines.
Explanation:
2096239 # integer literal
D # duplicate
20B # convert the copy to base 20, yielding "D20BJ"
J # join with the original
Alternative 13 byter:
11959189D₃BJ
Vyxal, 10 8 bytes
`:qp`:qp
-2 thanks to a stone arachnid
Explained
`:qp`:qp
`:qp` # the string ":qp"
:q # surrounded in backticks
p # and prepended to itself
05AB1E, 13 bytes
"34çì«"34çì«
"..."34çì« # trimmed program
"..." # push literal...
ì # prepended with...
ç # character with codepoint...
34 # literal...
« # concatenated with...
# (implicit) itself
# implicit output
Python 3, 48 bytes
s='print(f"s={s!r};{s}")';print(f"s={s!r};{s}")
Python 3, 74 bytes
s=r"s=;print(f'{s[:2]}r\"{s}\"{s[2:]}')";print(f'{s[:2]}r\"{s}\"{s[2:]}')
First two attempts... I think this is the basic approach, just used Python's f-strings.
AWK, 56 bytes
BEGIN{printf a="BEGIN{printf a=%c%s%c,34,a,34}",34,a,34}
Vyxal, 57 bytes
2996557859220556162530996767470:`0123456789+:`\\\`\τ+++τ+
The big number at the front is the rest of the program encoded using the key 0123456789+:τ\ with a backtick (dammit markdown). The rest of the program constructs the key, decodes this, and concatenates the original number to the result.
Adjust, 21 bytes
`@96c$+.+O`@96c$+.+O
Basically just a port of the Adapt quine, but updated with Adjust's swap command ($ vs Adapt's s) and no longer implicit output
Jq -rn, 18 bytes
"|@json+."|@json+.
"|@json+." # the string
| # through the filter
@json # json encoded
+ # concatenated with
. # itself
PHP -r, 32 bytes
Saved 3 bytes thanks to Sisyphus' insight!
The content of this quine is mostly unprintable characters using the stringwise NOT operator so the test link is to Bash to rebuild the file from an xxd hexdump.
eval(~$_=.....................);
Explanation
In PHP it's possible to use the ~ operator to 'flip' all the bits in a byte to return a string that doesn't look anything like the original string, which works around the problem of having to encode, and then decode, things like quotes. This means it's possible to just call echo on the result.
Visual example of how ~ 'flips' the values.
This was built using the following approach:
$quine =
// plain beginning
"eval(~\$_=".
// flipped code with $_ interpolated
~'echo"eval(~\$_=$_);";' .
// plain end
");"
;
Groovy, 90 bytes
`s='s=\\\';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*`2
Edit
Works in GroovyConsole
convey, 54 bytes
'Z u u%+}12 !*]+| |0]!&[&&Z'[
v
v&,~23
"+^,}
}1^"'\''[
As a bonus, I even managed to avoid using any unprintable characters, though there are a few tabs in there.
Explanation
Here's an image of how the code is interpreted (the gif version would take too long, since it takes approximately 23*26=598 steps):
There are two starting conveyor belts here, indicated by the [s on the top and bottom lines. The one on the top line feeds the data string to the rest of the program, while the other one prints the leading ' for the string and adds the other quote to the buffered output.
The top row is fed through a duplicator ("), one side of which is just pushed to output, while the other one has each character incremented by one (+1) to be transformed into the rest of the program before entering a queue (&), which already contains a '. Each character in this queue is delayed by 23 steps (~23), so that it only starts printing after the initial data string has finished being printed.
R, 44 41 bytes
crossed out 44 is still regular 44 ;(
-3 bytes thanks to Dominic van Essen
Works on R Version 3.6.2 and greater (thanks to Giuseppe for figuring out the versions).
`+` <-
function(x)cat(dump("+",""),1)
+ 1
This is 3 6 bytes shorter than the previous shortest quine by JAD.
Note that TIO currently uses R version 3.5.2, and thus adds some spaces and newlines to the output, but my local install of R version 3.6.3 does not, and gives the exact correct output.
Swift 5, 202 bytes
While much longer than the shortest Swift submission, this has important aesthetic points for me since it avoids numerical ASCII references as well as any declarations at all, using an anonymous function, resulting in a single-statement solution.
import Foundation;({print($0+"("+String(data:try!JSONEncoder().encode($0),encoding:.utf8)!+")")})("import Foundation;({print($0+\"(\"+String(data:try!JSONEncoder().encode($0),encoding:.utf8)!+\")\")})")
Assembly (NASM, 32-bit, Linux), 620 bytes
section .text
mov di,1
mov ebx,1
m:mov esi,a
l:mov ecx,esi
mov edx,1
mov al,[esi]
add ax,di
cmp al,10
jne p
mov ecx,b
mov dx,2
p:mov eax,4
int 128
mov al,[esi]
inc esi
cmp al,96
jne l
dec di
jz m
mov ecx,c
mov dx,3
mov ax,4
int 128
mov ax,1
int 128
section .data
c db 44,57,54
b db 92,110
a db`section .text\nmov di,1\nmov ebx,1\nm:mov esi,a\nl:mov ecx,esi\nmov edx,1\nmov al,[esi]\nadd ax,di\ncmp al,10\njne p\nmov ecx,b\nmov dx,2\np:mov eax,4\nint 128\nmov dl,[esi]\ninc esi\ncmp dl,34\njne l\ndec di\njz m\nmov ecx,c\nmov dx,3\nmov ax,4\nint 128\nmov ax,1\nint 128\nsection .data\nc db 44,57,54\nb db 92,110\na db`,96
-149 bytes by using backqoutes
-26 bytes by simplifying jumps
C++, 117 bytes
#include<cstdio>
#define Q(S)char*q=#S;S
Q(int main(){printf("#include<cstdio>\n#define Q(S)char*q=#S;S\nQ(%s)",q);})
C (gcc), 70 bytes
#define a(b)*s=#b;b
a(main(){printf("#define a(b)*s=#b;b\na(%s)",s);})
Stax (packed), 43 bytes
å3o╞╝&∞╝7►JôyG♦◄╨s│*T→╢φY'┘ò☼≤⌠░▼e╓Δ█•Aφ/│.
Doesn't work because for some reason latin1 does not accept the C1 control codes.
For this version, the interpreter needs to be forced to output in latin1. Stax Encoding is used. There is an extra trailing newline, but this appears to be accepted here (judging from many other answers).
Explanation:
The unpacked source is:
"r{32-m2+c+95|EVB|EB128+s+"r{32-m2+c+95|EVB|EB128+s+
The first half simply pushes the string which is also the second half.
The second half builds the full unpacked source out of it and packs it:
r{32-m2+c+95|EVB|EB128+s+ Second half r{32-m Reverse and subtract 32 from each character (for packing) 2+ Append 2 (double quote - 32) c+ Concatenate with self 95|E Decode as a base 95 integer (for packing) VB|E Encode as a base 256 interager (for packing) B128+s+ Add 128 to the first byte (for packing) Implicit output
Stax (packed), 103 bytes (50 characters)
üö╖╞╖┘û■Å╣ß$æi7⌐ê↔T)ç¢┤,I_º>┐ó♫Z╪Æ≤◄▐0σ▓☻E.α╬TŶ7É
Source and output are UTF-8 here, so they are counted as such. Much longer, but UTF-8 is a little nicer to look at.
Labyrinth, 52 bytes
411096280599923751453245172184368156!
_
2/:@
" .
71_
Just beats out the previous Labyrinth quine by one byte, through using the modulo behaviour of ., and an unorthodox divisor.
Explanation:
This uses a similar setup to the other answer, but where that used a divmod of 98, this divides by 172 and modulos by 256. This first saves on the decoder section because the . instruction already moduloes by 256 before printing. But this alone isn't enough, so I started looking for a smaller divisor.
This is possible by brute-forcing the required number through rearranging the source code until it works, and only when the encoded string is really small (in this case 16 bytes). I wrote a Raku script to help brute force these variations of the code, with minor tweaks needed for different layouts.
The code itself is a simple loop
.....! Push number and print it
..... Then reverse direction, pushing the number in reverse
_ Enter the loop by
2/` Integer dividing the initial number by 2
` `
```
``: Duplicate and print value modulo 256
` .
```
2/` Integer divide by 172
" `
71_
```@ If the division results in 0, terminate
` `
```
The above code ended up being one of my first attempts at this method, and I only ever found a couple of others that were the same size, this one and this one, both with divisor 172. I'm not sure why this is the magic number.
Some thoughts on further golfing through this method:
- You can push
0through?or{(replacing_) - You can push
1through#or,`(replacing_1) - The wall in the center can be anything that isn't an instruction
"can be replaced with'or some other no-op and can be placed pretty much anywhere in the loop
I'm honestly not sure if this format can be golfed. It seems unlikely that there's a format that supports a smaller divisor than 172, but then again, I'm not sure why 172 was an island of stability in the first place.
beeswax, 17 13 bytes
According to the discussion on Does using SMBF count as a cheating quine? the original version at the bottom would count as a cheating quine, so I am wondering if a small change would make this a “proper” quine. The new version is 4 bytes smaller and does not modify its own source code:
`_4~++~+.}1fJ
Explanation:
lstack STDOUT
_ α[0,0,0]• create bees α,β, moving right and left
β[0,0,0]•
` 4 α[0,0,4]• push 4 on top of α lstack, switch β to print mode
β α β[0,0,0]• switch β to character output mode
~ α[0,4,0]• flip α lstack top and 2nd
+ α[0,4,4]• lstack top = top+2nd
+ α[0,4,8]• lstack top = top+2nd
~ α[0,8,4]• flip lstack top and 2nd
+ α[0,8,12]• lstack top = top+2nd
. α[0,8,96]• lstack top = top*2nd
} α[0,8,96]• ` ASCII(96) output char(lstack top) to STDOUT
1 α[0,8,1]• lstack top = 1
F α[1,1,1]• all lstack = top
J α[1,1,1]• jump to (x,y) = (lstack top, lstack 2nd)
`_4~++~+.}1FJ α[1,1,1]• _4~++~+.}1FJ output characters to STDOUT
This version should qualify as proper quine if the Befunge-93 program on Thompson’s Quine Page is listed as proper quine. The Befunge quine below does nothing else than read itself character by character, one character during each implicit loop, and output the character to STDOUT.
:0g,:93+`#@_1+
Correct me if I’m wrong.
Old (cheating?) version.
beeswax is a new 2D esolang on a hexagonal grid. It is inspired by bees, honeycombs and by the Hive board game (which uses hexagonal gaming pieces). beeswax programs are able to modify their own code. Thanks to this ability it is not too hard to create a quine. But the program does not read its own source code, as my explanation shows.
The first beeswax quine in existence:
_4~++~+.@1~0@D@1J
Or equivalently:
*4~++~+.@1~0@D@1J
IPs are called bees, the program area is called honeycomb. Every bee owns a local stack called lstack, carrying 3 unsigned 64 bit integer values.
Explanation:
lstack
• marks top of stack
* or _ create bee(same result in this situation)[0,0,0]•
4 1st lstack value=4 [0,0,4]•
~ flip 1st/2nd lstack values [0,4,0]•
++ 1st=1st+2nd, twice [0,4,8]•
~ [0,8,4]•
+ [0,8,12]•
. 1st=1st*2nd [0,8,96]•
@ flip 1st/3rd lstack values [96,8,0]•
1 1st=1 [96,8,1]•
~ [96,1,8]•
0 1st=0 [96,1,0]•
@ [0,1,96]•
D drop 1st at row=2nd,col.=3rd val. [0,1,96]•
This drops ASCII(96)= ` beyond the left border.
Dropping a value at a coordinate outside the program—in this case at column 0—grows the honeycomb by 1 column to the left. The coordinate system gets reset, so this column becomes the new column 1. So, growing the honeycomb in ‘negative’ direction is only possible in steps of 1. The grown honeycomb is always a rectangle encompassing all code.
This modifies the program to:
`*4~++~+.@1~0@D@1J
continuing...
@ [96,1,0]•
1 [96,1,1]•
J jump to row=1st,column=2nd val.[96,1,1]•
` switch to character output mode.
*4~++~+.@1~0@D@1J the following characters are printed to STDOUT.
GitHub repository of the Julia package of the beeswax interpreter.
√ å ı ¥ ® Ï Ø ¿ , 9 (possibly 11) bytes
79 87 OW
Notice the double space between the 87 and the OW. This is necessary because of the way √ å ı ¥ ® Ï Ø ¿ outputs.
The O command outputs the whole of the stack as numbers
The W command outputs the whole stack as Unicode interpretations of the numbers
The 11 byte solution
The above code will output
===== OUTPUT =====
79 87 OW
==================
-----Program Execution Information-----
Code : 79 87 OW
Inputs : []
Stack : (79,87)
G-Variable : None
Byte Length : 9
Exit Status : 0
Error : None
---------------------------------------
This is obviously not the code inputted but is outputted automatically by the interpreter. If this is disallowed, there is an 11 byte solution that only outputs the required output:
ł 79 87 OW
This will only output
ł 79 87 OW
I'm not sure if the 9 byte answer is acceptable, could someone please tell me in the comments?
anyfix, 29 bytes
“8221"’OƥO«"ƥ«”8221"’OƥO«"ƥ«
Another half finished golfing language. This is rather longer since the string quoting uses different starting and ending quotes, both with large ordinal values. There's probably a shorter way that I'm missing.
Explanation
“8221"’OƥO«"ƥ«” Push string
8221 Push 8221
"’ Duplicate and decrement
Oƥ Convert to character and print (starting quote)
O« Convert to character and swap with string
"ƥ Duplicate string and print
« And swap end quote back to top of stack
Implicitly print from top of stack to bottom
Add++ -i, 14 bytes
L,"L,%rd%%"d%
Takes advantage of Python string formatting with the % command. Uses the -i flag to run the function without having to call it.
Adapt, 19 bytes
`@96cs+.+`@96cs+.+
Explanation
`@96cs+.+` Push string "@96cs+.+"
@96 Push 96
c Convert it to the character "`"
s+ Swap the two and concatenate "`@96cs+.+"
.+ Duplicate and concatenate "`@96cs+.+`@96cs+.+"
Implicitly output
Whispers v2, 38 bytes
> "print('> %r\\n>> ⍎1'%a)"
>> ⍎1
Abuses the fact that there's an eval as Python command (⍎), which I can use to turn it into an arbitrary Python program. But of course, as a less cheaty feeling quine, there's:
Whispers v2, 270 bytes
> [62, 62, 32, 34, 49, 34, 10, 62, 32, 34, 62, 32, 34, 10, 62, 62, 32, 51, 43, 50, 10, 62, 62, 32, 69, 97, 99, 104, 32, 54, 32, 49, 10, 62, 62, 32, 39, 82, 10, 62, 62, 32, 79, 117, 116, 112, 117, 116, 32, 52, 32, 53]
>> "1"
> "> "
>> 3+2
>> Each 6 1
>> 'R
>> Output 4 5
Which encodes the ordinal values of the rest of the program on the first line, then prints the list then the list converted to characters.
Turns out I missed another way to make a slightly cheaty quine. In Whispers, the modulo command directly calls Python's %, which is overloaded with string formatting. This means you can forgo the eval command and do:
Whispers v2, 50 bytes
> '> %r\n>> 1%%1\n>> Output 2'
>> 1%1
>> Output 2
Acc!!, 270 bytes
936025123570680582070742833115365117904492153588422750562053064415808293823109091171562255866020953926270476903421472061856963432351191541604543106801928196867870451324872393884426634
Count a while a-183 {
Write 48+(_/10^(182-a))%10
}
Count b while _ {
Write _%128
_/128
Explanation
... Set the accumulator to a large number
Count a while a-183 { Loop from 0 to 182
Write 48+(_/10^(182-a))%10 Print the ath digit of the number
}
Count b while _ { Loop while the accumulator is not zero
Write _%128 Print the character of the accumulator modulo 128
_/128 Integer divide the accumulator by 128
ABC, 89 bytes
PUT {"0INa"; "1WRITE 'PUT',a"; "2FORbINa:WRITEb@2/"} INa
WRITE 'PUT',a
FORbINa:WRITEb@2/
This is one of those weird old languages, this one being "originally intended as a good replacement for BASIC". It has a few strange quirks, such as lists are iterated in sorted order, and you can only print newlines using a WRITE. At least the object to string conversion works well, and tokens can be placed right next to each other.
Explanation
PUT {"0INa";
"1WRITE 'PUT',a";
"2FORbINa:WRITEb@2/"}
INa Set a to the list of strings
WRITE 'PUT',a Print "PUT" and the list
FORbINa: Iterate over each string in the list
WRITE Print
b@2 The string excluding the first character
/ And a newline
I don't think this ir quite optimal, but I think it's pretty close. You can't have a two line quine, since both lines would have to encode themselves, and I can't think of a way to do a one line quine.
4, 3101 bytes
3.611102101111601492000010000000160111200001000000016010020000100000001601002000010000000160139200001000000016019520000100000001601842000010000000160199200001000000016019920000100000001601092000010000000160190200001000000016010920000100000001601912000010000000160111200001000000016019920000100000001601992000010000000160121200001000000016011020000100000001601092000010000000160193200001000000016010020000100000001601892000010000000160101200001000000016011020000100000001601102000010000000160130200001000000016013020000100000001601002000010000000160100200001000000016019920000100000001601002000010000000160100200001000000016010920000100000001601202000010000000160100200001000000016010220000100000001601312000010000000160199200001000000016019920000100000001601282000010000000160199200001000000016019920000100000001601902000010000000160111200001000000016019920000100000001601992000010000000160127200001000000016019920000100000001601992000010000000160191200001000000016011120000100000001601892000010000000160179200001000000016012120000100000001601192000010000000160198200001000000016019320000100000001601992000010000000160110200001000000016019920000100000001601102000010000000160119200001000000016019920000100000001601922000010000000160101200001000000016011020000100000001601992000010000000160131200001000000016010820000100000001601042000010000000160100200001000000016011020000100000001601092000010000000160190200001000000016013020000100000001601302000010000000160160200001000000016019920000100000001601602000010000000160110200001000000016013020000100000001601302000010000000160151200001000000016010320000100000001601032000010000000160105200001000000016011020000100000001601302000010000000160130200001000000016010220000100000001601822000010000000160103200001000000016010120000100000001601182000010000000160129200001000000016012220000100000001601312000010000000160152200001000000016018220000100000001601252000010000000160110200001000000016012520000100000001601222000010000000160151200001000000016015120000100000001601022000010000000160120200001000000016011320000100000001601152000010000000160112200001000000016011120000100000001601012000010000000160131200001000000016012920000100000001601452000010000000160194200001000000016015920000100000001601452000010000000160194200001000000016015820000100000001601452000010000000160194200001000000016015020000100000001601552000010000000160184200001000000016015920000100000001601452000010000000160194200001000000016015920000100000001601452000010000000160145200001000000016015120000100000001601052000010000000160115200001000000016015420000100000001601542000010000000160156200001000000016011520000100000001601152000010000000160160200001000000016015020000100000001601562000010000000160194200001000000016019420000100000001601682000010000000160148200001000000016014620000100000001648486494965050651516545455150155454954954954855054954854954954954921310112151310220151522520152282513229281103028200303015030301503030106990603030990010040801399011029999101990199398991129798111999997299991109999982999913200002900000990000030301011098003990011299991119900990999948599300001194
Explanation
3. Required boilerplate
6 11 10 Set cell 11 to 10
2 10 11 11 Set cell 10 to cell 11*cell 11 (10*10=100)
-- Data Section --
Every pair of digits in the program are represented by
6 01 49 Set cell 01 to the two digits joined together
2 00 00 10 Multiply cell 00 by 100
0 00 00 01 Add cell 01 to 00
This essentially makes cell 00 the rest of the program after the data section
6 48 48 Set each of the cells 48,49,50,51,54 to their respective values
6 49 49
6 50 50
6 51 51
6 54 54
551501554549549549548550549548549549549549 Print the initial section ('3.611102101111')
2 13 10 11 Initialise various powers of 10
2 15 13 10
2 20 15 15
2 25 20 15
2 28 25 13
2 29 28 11
0 30 28 20 Create the number '1000000010000200106', which is each data part backwards
0 30 30 15
0 30 30 15
0 30 30 10
6 99 06
0 30 30 99
0 01 00 40 Copy cell 00 to cell 01
8 01 Loop while cell 01 is not zero
3 99 01 10 Integer divide cell 01 by 100 and store in cell 99
2 99 99 10 Multiply cell 99 by 100
1 99 01 99 Subtract cell 99 from cell 01 to get cell 01 modulo 100
3 98 99 11
2 97 98 11
1 99 99 97
2 99 99 11
0 99 99 98 Swap the two digits of the modulo result
2 99 99 13 Multiply it by 1000
2 00 00 29 Multiply cell 00 by 10**19
0 00 00 30 And append a copy of a data part
0 00 00 99 And insert the modulo result in the correct place
3 01 01 10 And divide cell 01 by 100
9 End loop
Now we print the number in cell 00 in reverse
8 00 Loop while cell 00 is non-zero
3 99 00 11 Get the last digit of cell 00
2 99 99 11
1 99 00 99
0 99 99 48 Add the digit to '0'
5 99 And print
3 00 00 11 Divide cell 00 by 10
9 End loop
33, 24 bytes
"34cke12ketp"34cke12ketp
Explanation:
"34cke12ketp" Push the string 34c0ke13ketp to the source string
34c Put 34 in the accumulator
k Push a " to the destination string
e Append the source string to the destination string
12k Push a " to the end of the destination string
e Append the source string to the destination string
t Swap the source and the destination string
p And print the source string
2sable, 10 bytes
44186D15B
This uses the same strategy as its parent language 05AB1E, but beats it by not having to join afterwards.
Explanation
44186 Push 44186
D Duplicate
15B Convert to base 15
Implicitly print the stack
2DFuck, 963 853 bytes
!x^x>>x>x>x>>x>>>x>x>x>x>>x>>>x>>>x>x>x>>>>x>x>x>x>>>>x>x>>x>x>x>>>x>x>x>>x>>>>x>>>x>x>x>>x>x>>x>x>>x>>x>>>>>x>>>x>>x>x>x>>x>>>x>x>x>x>>x>>>x>>>x>x>x>>>x>x>x>x>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>x>>x>>>x>>>x>x>x>>>x>x>>x>x>x>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>>>x>x>x>>>x>x>x>>x>>>>x>x>>x>x>x>>x>>x>x>x>>x>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>x>>>>>x>>>x>x>>x>x>>x>>>x>>>x>x>x>>x>x>>x>x>>x>>>>>x>x>x>x>>>x>x>x>x>>x>>>>x>x>x>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>x>>>>>x>>>>x>x>x>>x>>>>x>x>x>>x>>>x>>x>x>x>>x>>>>>x>x>x>x>>x>>>>>x>>>>x>>>x>x>x>>>>x>x>x>x>>>x>x>>x>x>>x>>>x>x>>x>x>x>v[<r!x]..!.!....!.<^x[r[!.!....!...]v.r!.!.vr^!....!.>r^]![r.v<r^]
Just a plain binary encoding beats out the huffman style encoding.
Explanation
!x^ Leave a marker at the start of the data string
x>>x>x>... Push a binary string where 'x>' is 1 and '>' is 0
v[<r!x] Move to the start of the data string
..!.!....!. Print the leading '!'
<^x Add a leading 1 bit to the data string
[ Loop over the data string
r[!.!....!...] If the current bit is a 1, print 'x'
v.r!.!.vr^!....!. Print a '^' if the current bit is the first bit, else '>'
>r^ Move to the next bit
]
![ Loop over the data string in reverse
r.v<r^ Print each bit of the data string
]
And my previous longer but more interesting answer below:
2DFuck, 963 bytes
!xv>x>x>>>x>x>>x>x>x>>x>x>>>>>x>>>x>>x>x>>>x>x>>>x>x>>>>x>x>x>>>x>x>>>x>>>>>x>>x>x>x>>x>x>x>>>x>>>x>>>x>x>x>x>>>x>>x>>x>x>x>x>x>>>x>x>>x>x>x>>>x>>>>>x>x>x>>x>x>x>>>x>>>x>>>x>x>>>x>>>x>>>x>x>x>x>>x>x>>>x>x>>x>x>x>>>x>>>>>x>x>x>>x>x>x>>>x>>>x>>x>x>x>>x>x>x>>x>>x>>>x>x>>>x>>>x>>>x>x>x>x>>x>x>>>>x>x>x>x>x>>>x>>>>>x>x>x>>x>>x>x>x>x>x>>>x>>>x>>x>x>x>>>x>>>>>x>x>x>>>x>>>x>>>x>x>>>x>>>x>>>x>x>x>x>>x>x>>>x>x>x>x>>>x>>>>>x>x>x>>x>>x>>x>x>x>x>x>>>x>>>x>x>x>>x>x>x>>x>x>x>>x>>>x>x>>>>>>>>x>>>x>x>>x>x>x>>>x>x>x>x>>x>x>>>>>x>>>>>x>x>x>>x>>x>>x>>x>>x>x>x>>x>>x>x>x>>>>x>>x>>x>x>x>>x>>x>>x>>x>x>x>>x>x>x>>x>>>x>x>>>>>>>>x>>>x>x>x>x>>>x>x>x>x>>>x>>>x>>>x>x>>x>x>x>>x>>x>x>x>>x>x>x>>x>>x>>x>x>x>>x>>x>>x>>x>x>x>>x>>x>>x>>x>x>x>>x>x>x>>x>x>x>>x>>x>>x>>x>x>x>>x>x>x>>x>>x>x>x>x>>>>>x>x>>>^x!..!.!....!.!.!....!....!...!.!..!.![<r!]![vr[!.!....!...]..!.....!.>^r!].![vr[!.!.!.<r!...!.>r!]r![<r[<r.>r..<r!..!.>r!.]r![<r[.!.!..<r.!.>r.!]r![<r[<r.!.>r.!]!...r![<r.!..>r].]]]<<^r.!]
I'm glad I got this below 1000 bytes. I think it still could be shorter though, maybe through encoding multiple or partial characters rather than one character per binary string. In particular encoding .. and/or !. as tokens but while that may make the data string shorter, the increases to the decoder may not be worth it. Here's the helper program to generate the program.
Explanation
!xv Leave a marker at the start of the data string
>x>x>>>x>... Create the binary data string where 'x>' is 1 and '>' is 0
Here we encode the characters of the program as
'.' => 10
'!' => 11
'<' => 010
'r' => 011
'[' => 0010
']' => 0011
'>' => 00010
'^' => 00011
'v' => 00000
'x' => 00001
^x Leave a marker at the end of the data string
!..!.!....!. Print '!xv'
!.!....!...
.!...!.!..!.
![<r!] Move to the start of the data string
![ Loop over each bit of the data string
vr[!.!....!...] Print an 'x' if the bit is 1
..!.....!. Print a '>'
>^r!]
.! Print a zero bit for use in the first character
[ Loop over the data string in reverse
vr[ If the current bit is a 1, print
!.!.!.<r!...!.>r! '.' if the next bit is a 0, otherwise '!'
]
r![ Otherwise
<r[ If the next bit is a 1, print
<r.>r..<r!..!.>r!. '<' if the next bit is a 0, otherwise 'r'
]
r![ Otherwise
<r[ If the next bit is a 1, print
.!.!..<r.!.>r.! '[' if the next bit is a 0, otherwise ']'
]
r![ Otherwise
<r[<r.!.>r.!]!... Print '>','^','v' or 'x' based on the next two bits
r![<r.!..>r].
]
]
]
<<^r Move to the next bit in the data string
.! And print a zero bit for the next character
]
ShapeScript, 16 bytes
'"%r"@%"0?!"'0?!
Verification
$ shapescript quine.shape | diff -sq - quine.shape
Files - and quine.shape are identical
How it works
' Push a string that, when evaluated, does the following.
"%r" Push this formatting string. %r gets replaced by a string
representation of the corresponding argument.
@ Swap the string that is being evaluated on top of the stack.
% Apply formatting to the string on top of the stack.
"0?!" Push that string.
'
0?! Push a copy of the previous string and evaluate it.
ShapeScript, 32 bytes
'"'"'"'1?3?+3*2?+@+@+@#"0?!"'0?!
This version does not use string formatting. It's not particularly short, but I find it rather interesting.
How it works
'"' Push a double quote singleton string.
"'" Push a single quote singleton string.
' Push a string that, when evaluated, does the following:
1?3? Copy the second and fourth topmost stack items.
This pushes a copy of the single, then the double quote.
+3* Concatenate both and repeat the result three times.
2?+ Copy the third topmost stack item and append it to the string.
We now have a string of the first seven characters of the source.
@+ Swap with the string on the stack (the string that is being
evaluated) and concatenate.
@+ Swap with the original single quote and concatenate.
@# Swap with the original double quote and discard it.
"0?!" Push that string.
'
0?! Push a copy of the above string and evaluate it.
Pushy, 9 bytes
95 34 _"
Although writing functional programs in Pushy is sometimes difficult, the quine is relatively simple:
95 % Push 95 to the stack (ASCII code for _ )
34 % Push 34 to the stack (ASCII code for " )
_ % Print representation of the stack: 95 34
" % Print stack converted to string: _"
Notice that, although Pushy ignores newlines, it is needed here because the default separator for printing is \n - and there needs to be a trailing newline, hence making it 9 bytes
Alternatively, an 11-byte solution that does not require a newline:
78 95 34N_"
Works similarly to the one above, but N sets the separator an empty string.
V, 4 bytes
2i2i
Explanation:
2 " Two times:
i " Insert the following:
2i " The string '2i'
This is pretty straightforward. In fact, this almost works in regular vim. There is just one minor thing in the way: The string '2i' isn't inserted twice until you hit <esc>. In V, this is solved by implicitly ending every program with an <esc> (Really, that's an oversimplification, but it's close enough to the truth).
Old versions of V always added a newline to the output, which is why I didn't post this earlier. However, in commit b6c238d, this was fixed.
This answer works just because of luck. The approach doesn't extend well to general purpose quines/quine-variations. The shortest quine I'm aware of that can be trivially modified is
ñéÑ~"qpÿ
Explanation:
ñ " Start recording into register 'q'
éÑ " Insert 'Ñ' (uppercase so that the recording doesn't stop here)
~ " Toggle the case the character under the cursor (the 'Ñ')
"qp " Paste the contents of register 'q'
ÿ " Stop recording and play it all back
The reason the ÿ is needed, is because it is implicitly added to the end of macros, a feature that is unfortunate for quines, but very convenient for golf.
The nice thing about this quine is that we can do almost anything inside of the recording and it is still valid since it will be pasted later anyway.
,,,, 15 bytes
"'%r:%%1⊢":%1⊢
Commata is a very underdeveloped golfing language. This makes use of the string formatting command to format the data with double quotes.
Explanation
"'%r:%%1⊢" Push '%r:%%1⊢ to the stack
: Duplicate the string
% Format one string with the other
'%r Python's string repr with double quotes
1⊢ And drop the leading '
*><>, 14 bytes
"#ooooooo;!-1:
*><> doesn't offer much more than its parent language ><> apart from file input and some new movement commands, neither of which are useful here. In fact, this is longer than the ><> quine, since *><> outputs the error to STDOUT, meaning we can't exit with an error.
Explanation:
" Wrapping string, pushing the code to the stack
# Mirror, reverse directions
" Pushing the code to the stack in reverse
-1: Duplicate the top of the stack (#) and subtract one to get "
;! Skip over the terminate
ooooooo Print seven characters
# Mirror
ooooooo Print the other seven characters
; And terminate
(()), 3560 bytes
Let
(
=()
Let
)
=(())
Let
=(()())
Let
L
=((()))
Let
e
=(()(()))
Let
t
=((())())
Let
=
=(((())))
(((()(()))(()))(()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()(())()()(())()(())(())()()()()(())(())(())(())()(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())()()(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()(())(())()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()()(())(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()(())()(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()()()(())(())(())()()(())()()(())(())(())()()(())(())()()()(())(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())()()(())(())(())()()(())(())(())(())))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((((()))(()(()))((())())(()())()(()())(((())))()(())(()())((()))(()(()))((())())(()())(())(()())(((())))()()(())(())(()())((()))(()(()))((())())(()())(()())(()())(((())))()()(())()(())(())(()())((()))(()(()))((())())(()())((()))(()())(((())))()()()(())(())(())(()())((()))(()(()))((())())(()())(()(()))(()())(((())))()()(())()()(())(())(())(()())((()))(()(()))((())())(()())((())())(()())(((())))()()()(())(())()(())(())(()())((()))(()(()))((())())(()())(((())))(()())(((())))()()()()(())(())(())(())(()())()()()()(())()()(())(())(())()()(())(())(())()((()))(()(()))(())((()))(())(())()()()()()()(())(())(())()()()(())(())(())(())()(())(())(())()()()()()(())(())(())()(())(())()()(())()()(())(())()()()(())(())(())(())(())()()()()()(())(())(())()()(())(())(())()()(())()(())()()(())(())()()(())(())()()()(())(())(())(())(())()()(()(()))(())))
This probably isn't the optimal strategy (since it was the first one I thought of), but I've golfed this down enough that I feel confident posting it. I wrote a helper program to generate this program
(()) is a string re-writing scheme designed to only use parentheses. The top lines of Let x = (()) are to assign characters to the sets of parentheses so that input and output can make sense, but otherwise the entire program is that 3400 byte string at the bottom. Essentially it boils down to a series of string rewrite rules:
"e)" -> "large data string"
"LL" -| "" (terminate on this substitution)
"L(" -> "()L"
"L)" -> "(())L"
"" -> "Initialisation (((()(()))(()))(Le)L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((e)"
First we start with the input, which is empty. Only the last rule matches the empty string, so we replace the current string with the result from that:
Initialisation (((()(()))(()))(Le)L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((e)
The first rule to match this string is the e) rule (which is constructed to avoid matching anything in the initialisation section). This matches twice, and we substitute the first and then the second, since none of the other rules before it apply:
Initialisation (((()(()))(()))(L large data string L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))(( large data string
The large data string is the parentheses representation of the original empty string substitution, which means that this is almost the final product, except that the first copy of data string needs to itself be translated to the parentheses version. We use the L( and L) rules to turn each character into it representation. Once we run out of those, the output looks like:
Initialisation (((()(()))(()))(large data string representation LL))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))(( large data string
So we finally execute the LL rule, replacing LL with nothing and terminating the program.
!@#$%^&*()_+, 38 bytes
4K6j364K3645/1,3(!&$*)+(@)+(_+@)
Uses quite a few unprintables to abuse the behaviour of pushing the ordinal value of that character.
Explanation:
4K6j364K3645/1,3 Push data section to stack (0,data)
Push zero, then the counter (0,data,0,19)
(!&$*) Push the reverse of the data (0,data,0,atad,0)
+(@) Print the data (0,data,0)
+(_+@) Print the data again, in reverse and offset by 11
MAWP, 60 bytes
Thanks @JoKing for saving a whopping 55 bytes!
48923792915350878792773358929392915992930\%\[52WW\M!:\]\[;\]
It's finally done!
Explanation:
The quine is essentially split into three parts. The first part is the data, and is represented by the big blob of numbers in the start (excluding a 0). It represents the ASCII codes of the rest three parts of the code. The second part is the decoder that both turns the long stack of separate numbers into a smaller stack with multi-digit numbers and prints it as numbers without destroying it. The last part loops over the stack and prints it as ASCII. Note that we don't have to preserve the data in stack any more.
Old solution:
115 bytes
481263753508787774753508787775350878777479153508787774793479133584793479159930~%52WWM/52WWM52WWM/[52WWM/]/[!:/]/[;]
Bubblegum, 105 Bytes
Hexdump:
00000000: 0000 00ff ff00 0000 ffff 0000 00ff ff00 ................
00000010: 1400 ebff 0000 00ff ff00 0000 ffff 0000 ................
00000020: 00ff ff00 1400 ebff 4288 21c4 0000 1400 ........B.!.....
00000030: ebff 4288 21c4 0000 1400 ebff 4288 21c4 ..B.!.......B.!.
00000040: 0000 1400 ebff 4288 21c4 0000 1400 ebff ......B.!.......
00000050: 0000 00ff ff00 0000 ffff 0000 00ff ff03 ................
00000060: 1300 0000 0313 0000 00 .........
(You might want to verify it offline - since the input is hexdump and the output is raw.)
This relies on the fact that Bubbleugum tries to DEFLATE decode its input first:
...
o = zlib.decompress(code, -zlib.MAX_WBITS)
...
So if we can find a fixpoint in DEFLATE compression, such that x = zlib.decompress(x, -zlib.MAX_WBITS), we are done. But how to do this?
Part I: Generic Compression Quine
Say we have a compression programming 'language' that has two operations:
Pn: Print the followingntokens as literals, and skip interpreting themRn: Print the lastntokens printed
Let's write some simple programs in this to understand how it works.
Input | Output
P1 P0 | P0
Input | Output
P1 P0 | P0
P1 P1 | P1
Input | Output
P1 P0 | P0
R1 | P0
Input | Output
P4 P0 P0 P0 P0 | P0 P0 P0 P0
R4 | P0 P0 P0 P0
Now the question is: Just with these two instructions, can we create a quine? The answer is yes, thanks to Russ Cox:
Input | Output
P0 |
P0 |
P0 |
P4 P0 P0 P0 P4 | P0 P0 P0 P4
R4 | P0 P0 P0 P4
P4 R4 P4 R4 P4 | R4 P4 R4 P4
R4 | R4 P4 R4 P4
P4 P0 P0 P0 P0 | P0 P0 P0 P0
(The tokens are not on the same line, but you can check they're the same).
This gives us hope we might be able to write a DEFLATE quine. But we're not close to done yet, since we have to deal with actual file formats and not made up tokens. Read on!
Part II: Zlib and DEFLATE
Zlib usually appends a 2 byte header and a 4 byte checksum to everything it compresses. The 4 byte checksum would make the creation of a quine much more difficult. But luckily, Bubblegum is designed using to utilize the -zlib.MAX_WBITS flag, which skips the header and the checksum! So we just have a raw DEFLATE stream. How does DEFLATE work? The full thing can be a bit complicated, but luckily we only need to pull out the bits that allow us to have our Pn and Rn building blocks.
Part III: The Pn building block
A deflate stream is made up of a series of blocks. Each block starts with the following:
BFINAL: 1 bit, set to 1 if it's the last block.BTYPE: 2 bits. All we need to know is that it's00for 'no compression' (iePn) and01for 'fixed compression' (which turns out to map toRn).
If we have a 'no compression' block, the rest of the bits in the current byte are set to zero and the next bytes look like:
+---+---+---+---+================================+
| LEN | NLEN |... LEN bytes of literal data...|
+---+---+---+---+================================+
Where LEN is a 2-byte little endian unsigned number of bytes in the literal data, NLEN is the complement of LEN (also unsigned little endian) and we then have N literal bytes. Keeping in mind the first byte is packed from LSB to MSB, this means we can encode the following:
P0 = 00 00 00 ff ff
00000 00 0 | 00000000 | 00000000 | 11111111 | 11111111
^ ^ ^ ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
| | | LEN = 0x0000 NLEN = ~LEN = 0xFFFF
| | |
| | \- BFINAL = 0 (not final block)
| \---- BTYPE = 00 (no compression)
\---------- 5 bits padding in block
P4 = 00 14 00 eb ff
00000 00 0 | 00010100 | 00000000 | 11101011 | 11111111
^ ^ ^ ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
| | | LEN = 0x0014 NLEN = ~LEN = 0xFFEB
| | |
| | \- BFINAL = 0 (not final block)
| \---- BTYPE = 00 (no compression)
\---------- 5 bits padding in block
Why is P4 printing 0x14 = 20 bytes, you ask, instead of 4? Well, the previous token 'quine' had the units of 1 byte ~ 1 token, but we don't have that luxury. So instead, we have a fixed length of 5 bytes per token, since this is the minimum size of a print token. So 4 tokens is 20 bytes.
Part IV: The Rn building block
The BTYPE = 01 allows us to make queries of the form REPEAT(n, q):
Starting from
qbytes away in the output, printnbytes.
It shouldn't be hard to see that REPEAT(n, n) gives us Rn. But there's a problem, since it turns out that R4 = REPEAT(20, 20) only takes up 3 bytes instead of 5! Since we are assuming all our tokens take up 5 bytes for our quine to work, this is no good. However, we can introduce some redundancy - it turns out if we define R4 = REPEAT(10, 20), REPEAT(10, 20), then we do the same thing but now the instruction takes up 5 bytes total!
The way these blocks are actually encoded as bytes is a little complex. I'll annotate the block, and to fill in the gaps read the RFC. For compressed blocks, the data is turned from bits into bytes LSB to MSB with a couple of exceptions.
P4 = 42 88 21 c4 00
01000 01 0 | 1 00010 00 | 001000 01 | 11 00010 0 | 0000000 0
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | [5] | | | | [8] | | padding [8]
[3] | \- [1] [4] [3] [6] [5] [7] [6]
\---- [2]
[1]: BFINAL: 0 (not end block)
[2]: BTYPE: 01 (fixed compression)
[3]: Literal code 264 (print 10 bytes...)
[4]: Distance code 8 (starting from 17 + ... )
[5]: Extra distance code bits ( ... 3 bytes back) (= 20 total)
[6]: Literal code 264 (print 10 bytes...)
[7]: Distance code 8 (starting from 17 + ... )
[8]: Extra distance code bits ( ... 3 bytes back) (= 20 total)
So we've got all our building blocks! P0, P4, R4 right? Are we done?
Part V: The final tweak
Well, not so fast. Remember we had a bit saying which block was the end block? It turns out, for Python at least, that we need to include this on the last block, else it messes up our program. And unfortunately, if we let P*0 be a P0 end block token, the following is NOT a quine:
Input | Output
P0 |
P0 |
P0 |
P4 P0 P0 P0 P4 | P0 P0 P0 P4
R4 | P0 P0 P0 P4
P4 R4 P4 R4 P4 | R4 P4 R4 P4
R4 | R4 P4 R4 P4 <-\
P*4 P0 P0 P0 P0 | P0 P0 P0 P0 |
^ |
\--------------+----------------+
|
Not the same!
However, if we introduce an R*1, we can fix this quite easily:
Input | Output
P0 |
P0 |
P0 |
P4 P0 P0 P0 P4 | P0 P0 P0 P4
R4 | P0 P0 P0 P4
P4 R4 P4 R4 P4 | R4 P4 R4 P4
R4 | R4 P4 R4 P4
P4 P0 P0 P0 R*1 | P0 P0 P0 R*1
R*1 | R*1
It turns out we can encode R*1 = 03 13 00 00 00, so we are done. Use the following Python program to assemble and verify our DEFLATE quine:
import zlib
P0 = b'\x00\x00\x00\xff\xff'
P4 = b'\x00\x14\x00\xeb\xff'
R4 = b'B\x88!\xc4\x00'
R1_F = b'\x03\x13\x00\x00\x00'
comp = b''
comp += P0
comp += P0
comp += P0
comp += P4 + P0 + P0 + P0 + P4
comp += R4
comp += P4 + R4 + P4 + R4 + P4
comp += R4
comp += P4 + P0 + P0 + P0 + R1_F
comp += R1_F
print(zlib.decompress(comp, -zlib.MAX_WBITS) == comp)
Well done! You are now a certified deflate quine expert™.
APL, 22 bytes
1⌽22⍴11⍴'''1⌽22⍴11⍴'''
This is part of the FinnAPL Idiom Library.
'''1⌽22⍴11⍴''' ⍝ The string literal '1⌽22⍴11⍴' (quotes in string)
11⍴ ⍝ Fill an 11-element array with these characters
⍝ But the string has length 10, so we get '1⌽22⍴11⍴''
22⍴ ⍝ Do this again for 22 chars: '1⌽22⍴11⍴'''1⌽22⍴11⍴''
1⌽ ⍝ Rotate left (puts quote at the back)
FEU, 56 bytes
At first, I thought it was impossible.
Then I remembered __DATA__.
s/(.+)/\1\n__DATA__\n\1
__DATA__
s/(.+)/\1\n__DATA__\n\1
Explanation
It's just your usual quine. __DATA__ onwards is read and fed into the regex substitution, which takes the input, and puts it in this format:
input
__DATA__
input
Aceto, 66 bytes
£"24«cs%55«3+cp24«2+cdpsdpsppn"24«cs%55«3+cp24«2+cdpsdpsppn
Kind of a classic quine, but having to deal with a few quirks of Aceto to make it work. I had attempted this in the past but had failed.
This mostly follows the good old "source code in quotes, followed by printing a quote character and the source code twice" method.
Explanation:
£"24«cs%55«3+cp24«2+cdpsdpsppn"24«cs%55«3+cp24«2+cdpsdpsppn
£ # (1)
"24«cs%55«3+cp24«2+cdpsdpsppn" # (2)
24«cs% # (3)
55«3+cp24«2+cdpsdpsppn # (4)
Because of the development process of a quine, I decided to ignore the Hilbert curve in this case, because otherwise I'd need to scramble the source code to match the formatting. Therefore we write everything in a single line, exploiting the fact that it will be well-ordered still (just walk over a bunch of nops (spaces) in-between).
- I just realized getting an empty string is not really trivial in Aceto (oops). Character literals (starting with
') are always 1 character long. You could use string literals, but just doing""will only work sometimes, depending on where on the hilbert curve you are currently. Since we're trying to avoid the curve for this (as described above), this will usually just turn into a string containing a couple of spaces. But when the stack is empty (such as at the beginning of the execution), we can "implode" (£) the stack into a single string, which will then be the empty string. - This is, as usual, just the remaining source code after this, as a string literal.
- I will need to remove all spaces from the source code that have agglomerated there due to the Hilbert-curve. I can't use a space literal for several reasons (Hilbert curve, and it should be trimmed later), so I instead construct it (and other characters later) using arithmetical operations. An ASCII space is 2, bit-shifted to the left 4 times (
24«c). We then use the regex substitution operator%to remove the spaces. - Now we're ready to print things: We construct the pound symbol (
55«3+c) and print it, followed by a double-quote (24«2+c), followed by the space-trimmed source code, a quote, and the source code again. Finally, we print a newline (n).
Minecraft Java Edition, 241 bytes
This can be run as a function in a datapack, or by running each of the commands:
data modify storage z x set value ['["data modify storage z x set value ",{"nbt":"x","storage":"z"},"\\ntellraw @a {\\"storage\\":\\"z\\",\\"nbt\\":\\"x[0]\\",\\"interpret\\":true}"]']
tellraw @a {"storage":"z","nbt":"x[0]","interpret":true}
Explanation
data modify storage z x set value ... # set the variable x in the storage minecraft:z
['...'] # to a list containing a string (in JSON rich text format) of
"data modify storage z x set value " # (a literal part of the source code),
{"nbt":"x","storage":"z"} # this variable (this will only be evaluated
# during the tellraw command when it is interpreted), and
"\\ntellraw @a {\\"storage\\":\\"z\\",
\\"nbt\\":\\"x[0]\\", # the rest of the source code
\\"interpret\\":true}" # (\ and " must be escaped because this is part of a string).
tellraw @a {"storage":"z","nbt":"x[0]", # then interpret the JSON string and print it to the chat
"interpret":true} # (this will place the variable inside)
The list is necessary so that when it is printed, it will contain the quotes and double backslashes.
Common Lisp, 58 bytes
Lisp is perfect for quines because of using code as data, but terseness is not its strong suit.
(FORMAT T "(~{~S ~}~:*'~S)" '(FORMAT T "(~{~S ~}~:*'~S)"))
Excellent expert explanation.
(FORMAT T -- print
"( )" -- between parentheses
" ~{ }~ " -- looping over the list argument
" ~S_ " -- each item followed by a space
" ~:* " -- use the FORMAT sublanguage's *very* fancy
-- "~*" directive (skip argument) with the ":"
-- modifier to back up and reuse the argument
" '~S " -- print the argument again with a quote before it
'(FO.. -- the argument is the same thing but with a quote
-- in front to show that it is data
Alternative 9 bytes, that only works in the REPL
(prin1 -)
(use print for a trailing newline)
This prints the value of '-', which is the current expression being evaluated. You can try it here.
Python 3, 190 216 bytes
s='s=\\\'\'+s.replace(\'\\\\\',\'\\\\\\\\\').replace(\'\\\'\',\'\\\\\\\'\')+\'\\\'\\nprint(\\\'\'+s+\'\\\')'
print('s=\''+s.replace('\\','\\\\').replace('\'','\\\'')+'\'\nprint(\''+s+'\')')
An old solution of mine following the standard pattern. It only uses the most common commands though.
tq, 8 bytes
New high-level language! (Technically inspired by Jo King's Symbolic Raku quine.)
etq'etq'
Explanation
'etq' # Define the second item of the list
# As a string
q # Surround the string with quotes
t # For the first item of the list,
# Access the last (tail) item in the list,
e # and un-quote the accessed value.
# The list becomes etq, 'etq' (comma is for readability)
# , which then becomes foreach-printed without any separator.
```
Hexagony, side length 11, 314 bytes
164248894991581511673077637999211259627125600306858995725520485910920851569759793601722945695269172442124287874075294735023125483.....!/:;.........)%'=a':\....................\...................\..................\.................\................\...............\..............\..$@.........\$><>'?2='%.<\:;_;4Q
Note: Currently the shortest program is only 261 bytes long, using a similar technique.
Older version:
Hexagony, side length 11, 330 bytes
362003511553420961423766261426252539048636523959468260999944549820033581478284471415809677091006384959302453627348235790194699306179..../:{;+'=1P'%'a{:..\.....................\...................\..................\.................\................\...............\..............\.............\!$><........\..@>{?2'%<......:;;4Q/
Encoder: Try it online!
The program is roughly equivalent to this Python code: Try it online!
Unfolded code:
3 6 2 0 0 3 5 1 1 5 5
3 4 2 0 9 6 1 4 2 3 7 6
6 2 6 1 4 2 6 2 5 2 5 3 9
0 4 8 6 3 6 5 2 3 9 5 9 4 6
8 2 6 0 9 9 9 9 4 4 5 4 9 8 2
0 0 3 3 5 8 1 4 7 8 2 8 4 4 7 1
4 1 5 8 0 9 6 7 7 0 9 1 0 0 6 3 8
4 9 5 9 3 0 2 4 5 3 6 2 7 3 4 8 2 3
5 7 9 0 1 9 4 6 9 9 3 0 6 1 7 9 . . .
. / : { ; + ' = 1 P ' % ' a { : . . \ .
. . . . . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . \
. . . . . . . . . . . . . \
! $ > < . . . . . . . . \
. . @ > { ? 2 ' % < . .
. . . . : ; ; 4 Q / .
Two .s takes 1 bit. Any other characters take 1 bit and a base-97 digit.
Explanation
Click at the images for larger size. Each explanation part has corresponding Python code to help understanding.
Data part
Instead of the complex structure used in some other answers (with <, " and some other things), I just let the IP pass through the lower half.
First, the IP runs through a lot of numbers and no-op's (.) and mirrors (\). Each digit appends to the number in the memory, so in the end the memory value is equal to the number at the start of the program.
mem = 362003511...99306179
! prints it,
stdout.write(str(mem))
and $ jumps through the next >.
Starting from the <. If the memory value mem is falsy (<= 0, i.e., the condition mem > 0 is not satisfied), we have done printing the program, and should exit. The IP would follow the upper path.
(let the IP runs around the world for about 33 commands before hitting the @ (which terminates the program) because putting it anywhere else incurs some additional bytes)
If it's true, we follow the lower path, get redirected a few times and execute some more commands before hitting another conditional.
# Python # Hexagony
# go to memory cell (a) # {
a = 2 # ?2
# go to memory cell (b) # '
b = mem % a # %
Now the memory looks like this:
If the value is truthy:
if b > 0:
the following code is executed:
# Python # Hexagony
b = ord('Q') # Q
b = b*10+4 # 4
# Note: now b == ord('.')+256*3
stdout.write(chr(b%256)) # ;
stdout.write(chr(b%256)) # ;
See detailed explanation of the Q4 at MartinEnder's HelloWorld Hexagony answer. In short, this code prints . twice.
Originally I planned for this to print . once. When I came up with this (print . twice) and implement it, about 10 digits were saved.
Then,
b = mem // a # :
Here is a important fact I realized that saved me about 14 digits: You don't need to be at where you started.
To understand what I'm saying, let's have a BF analogy. (skip this if you already understood)
Given the code
while a != 0:
b, a = a * 2, 0
a, b = b, 0
print(a)
Assuming we let a be the value of the current cell and b be the value of the right cell, a straightforward translation of this to BF is:
[ # while a != 0:
[->++<] # b, a = a * 2, 0
>[-<+>] # a, b = b, 0
<. # print(a)
]
However, note that we don't need to be at the same position all the time during the program. We can let the value of a be whatever we are at the start of each iteration, then we have this code:
[ # while a != 0:
[->++<] # b, a = a * 2, 0
# implicitly let (a) be at the position of (b) now
. # print(a)
]
which is several bytes shorter.
Also, the corner wrapping behavior also saves me from having a \ mirror there - without it I would not be able to fit the digits (+2 digits for the \ itself and +2 digits for an unpaired . to the right of it, not to mention the flags)
(details:
- The IP enters the lower-left corner, heading left
- It get warped to the right corner, still heads left
- It encounters a
\which reflects it, now it heads right-up - It goes into the corner and get warped again to the lower-left corner
)
If the value (of the mod 2 operation above) is falsy (zero), then we follow this path:
# Python # Hexagony # Memory visualization after execution
b = mem // a # : # click here
base = ord('a') # 97 # a
y = b % base # '%
offset = 33 # P1
z = y + offset # ='+
stdout.write(chr(z)) # ; # click here
mem = b // base # {: # click here
I won't explain too detailed here, but the offset is actually not exactly 33, but is congruent to 33 mod 256. And chr has an implicit % 256.
brainfuck, 392 bytes
Like this 755B answer, this quine is accompanied by an additional character, which appears in both source and output. I tested this using BFO in the windows terminal emulator ConEMU.
->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>+++>>>>>+++>+>>>>>>>>>++>+++>+++>+>>+++>>>+++>+>++>+++>>>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>>>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>>>+++>+>>>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>++[[>>+[>]++>++[<]<-]>+[>]<+<+++[<]<+]>+[>]++++>++[[<++++++++++++++++>-]<+++++++++.<]
The source and output have no linebreaks. The last character is a \x1a (SUB ctrl code).
Invented by Daniel B Cristofani. (That's an overstatement; I'd say Erik Bosman invented it and I just polished it a bit. His version was 410 bytes.)
How it works
Like many other brainfuck quines, this code first inputs a list of values that are later used to recreate the actual code, then it builds up a list that contains the "+" and ">" symbols needed for the input and then all characters are printed out.
Each character of the actual code (starting with +[) is stored in two cells. Let's call them x and y. The formula to calculate the current character is (x+2)*16 + (y+2) + 9, so the characters are encoded like this:
char ascii minus9 outX outY inX inY
+ 43 34 2 2 0 0
- 45 36 2 4 0 2
. 46 37 2 5 0 3
< 60 51 3 3 1 1
> 62 53 3 5 1 3
[ 91 82 5 2 3 0
] 93 84 5 4 3 2
All values are stored in reversed order. For example the starting ->++>+++>+>+>+++>> (2 3, 1 1, 3 0) encodes the .<] at the end of the code.
[tape: End Marker/EM(-1), [in values], Between Lists Marker(0), [out values]]
- set EM
read list of in values
[>++>+++>+>+>+++>>>>>>>>>>>.... ]
build out values to generate list
+[ while input (for each gt)
append pluses to out vals / always runs one extra time
[ while value gt 0 (for each plus)
>>+ copy in value to out value
[>]++>++ append out values 2 2 (plus)
[<]<- decrement in value
]
>+ new out value 1 (for adding 2 to each in value / one by the extra loop and one by this)
[>]<+<+++ add 3 and 1 to last out values (change plus to gt)
[<] go to old in value
<+ repeat if not on EM
]
>+[>]++++>++ append out value 4 2 (minus)
>[instead of ">+", we could also use ">>",
but a ">" is encoded as "+++>+>", while a "+" is encoded ">>",
so it saves four bytes, when using "+>".]<
printing loop
[
[<++++++++++++++++>-] add 16 times out value(X) to next out value(Y)
<+++++++++ add constant 9
. print char
< go to next out value
]
The `` in the end appears, because the copy routine leaves the extra values 1, 1 at the end of the list, which will be encoded 16+1+9 = 25. If we wanted to avoid that, we had to replace the >+ by the code >>->. The input code of that section would change from >>+++>+> to +++>+>++>>+++>+>+++>+>, so the code would be 15 bytes longer.
Ral, 1389 1043 bytes
1111111101011101011101010101111101011101010101111101010101111101011101010101111101010101111101011101010101111000111000111000111000111000110101010000110101110111011101011101010101111101011101010101111101011101010101111101011101010101111101011101010101111101011011010101111111111101011101010101111101011101010101111101010101111101011101010101111101011101010101111000111000111000111000110101010000111011010101010000110101111111010111011101011101010101111101010101111101010101111101010101111101011000111101011000111000110101110101010101111101011000111111111101011101010101111101010101111101011101010101111101011101010101111000111000111000110101010000110101111011010101011011010000111000111000111011111011111011010000111000110101111011110000110101111101010101111011011101010101111101010101111101010101111101010101111101010101111101010101111101011101010101111101011101010101111000111000111000111000111111:++:++:+:+:+:+:+:+-:+:0=:10-==110-*-:0*111:++:++:+:++?1+:*:11+1+:+:+:+:++./:0*-0*1111:++:++:+:++:++?:-+:++:++:++:++:++.:0*11111:++:+:++:+:++:+++?
Explanation
All characters in Ral (except the no-op) are in the range 32-63, which is 001xxxxx in binary. By omitting the leading zeroes, every character in the code can be stored as a group of 6 bits. (A hexad? hextet? Hextet will do.) The one is still included in the payload to make decoding easier.
Here is a short summary of what each part of the code does. I have omitted the value juggling on the stack and inner workins of the loops from the explanation, as they would make the explanation too complicated:
111111...100011 Push the payload data to the stack.
1111:++:++:+:+:+:+:+:+-:+:0= Load the value 894, which is the length of the payload
and is used as a base pointer for the jump destinations.
:10-==110-*-:0*111:++:++:+:++? Move the payload data to memory.
1+:*:11+1+:+:+:+:++. Loop through the payload, printing 48+n for each value
/:0*-0*1111:++:++:+:++:++? and push each value to the stack again.
:-+:++:++:++:++:++. Decode and print each hextet.
:0*11111:++:+:++:+:++:+++?
Javascript, 133 bytes
a="\\";b="\"";d="throw b+'HELP!'+b+'a='+b+a+a+b+';b='+b+a+b+b+';d='+b+d+b+';'+d";throw b+'HELP!'+b+'a='+b+a+a+b+';b='+b+a+b+b+';d='+b+d+b+';'+d
Unary, ~6.1*10^4391 bytes
000000000...(more 0s than fits in the observable universe)...000
For reasons that may be somewhat obvious, you can't try this one online.
What the hell is Unary?
Unary is a joke(?) esolang with a pretty basic premise: the only valid symbol is the number 0. To interpret Unary, the 0s are first counted, then that number is converted into binary, then that number is converted into brainfuck (000 corresponds to +, 001 corresponds to -, and so on), then the brainfuck is run.
It's worth noting that you can't distinguish between the numbers 000001 and 001 even though they represent different brainfuck, so in all cases, Unary requires us to include an extra 1 bit at the top of the binary representation: we instead write the binary numbers 1000001 or 1001, which are distinguishable.
Basic overview/comments
Whew, this was a huge pain. As a forewarning, I'm almost certain it's not optimal (there are quite a few structures that are pretty space-inefficient used in the brainfuck) but I'm also almost certain there's no way this is ever fitting on any real computer, so I don't feel too bad about it.
The basic idea for this is probably about what you expect: there's a big array that represents the rest of the code (with a cell set to negative one at the start for navigation), and there's a bunch of code which takes an array and prints out unary code representing the code initializing the array (and the negative one flag), then the code represented by the array.
Obviously it's impossible to test this thing, but I tested the actual quining part on the smallest possible array input ("->+>>" representing "-++"), and it correctly output exactly 19,407,936 0s (corresponding to "->+>>-++"), which is good enough for me.
Finally, I'd like to point out that this is technically a Unary/Lenguage polyglot quine (as all Unary code is also valid lenguage with the same function), though a proper Lenguage golf adapted from this one would probably be a couple hundred orders of magnitude smaller.
Detailed overview
The core idea of this code is to use our array as a base-8 "number", with each entry being another base-8 "digit". We can cascade this downwards (subtract 1 from an entry and add 8 to the one directly after it), and then print a 0 for every entry in the last array entry. Doing this process on the original array prints Unary code for whatever brainfuck the array represented (the representation is as you might expect: every entry is a different symbol, and every entry contains a number 0-7, one corresponding to each brainfuck command).
You'll note that technically, we're doing this "backwards": printing all the 0s for the code before we print the 0s for the array. I'm not certain that this is necessary, but it does enable us to use some clever constructions later on to save quite a bit of work.
This process, incidentally, will destroy whatever array it's run on. Thus, before we do that, we need to copy the array (actually quite an obnoxious task given that the arrray is variable-length).
Thus after we print the code itself, we have data looking like this:
-1 flag | [original array] | -2 flag | [empty array with the same length] | -3 flag
This means we only need to print the Unary for the array itself, the -1 flag at the start of the array, and the 1 bit at the top of the binary representation which Unary requires.
Fortunately, we can actually use similar code to do this! In order to encode further data, we need to print out 0s in chunks of some very large power of 8: ie, if our code so far was 50 characters long, in order to encode a "-" before the code, we would have to print 8^50 0s.
The power of 8 we have to use is exactly the length of that big empty array. This means that if we put a 1 in the top register of that array, it will increment the last symbol encoded by 1, and if we put an 8 in the top register it will encode a new symbol (specifically a minus).
Furthermore if we move the flag at the end of the array to the right by 1 it'll print out 8 times as many 0s, and thus start editing the symbol before the last symbol encoded!
Since a plus is just "000", we can just move the flag to the right by the value of the last position in the array. This adds as many "000"s to our binary output as there were plusses in the original array representation. When more stuff is added to our array and cascaded down, this will correctly encode the plusses.
We then move the flag at the start of the empty array to the left by 1: this means we start editing the symbol before the plusses we just added. Conveniently, the space it moves into will have been emptied by the operation that moved the end of the array just before now.
All this means that if we put a 2 in the top register of the empty array and then cascade it'll actually print a right carat, and the blank spaces left from moving b will interpret to an appropriate amount of plusses.
We can then repeat this for every single entry in the filled array, thus encoding all of the array representation.
Memory now looks like this
-1 flag|-2 flag| [huge empty array, 2 times as long as the original array]| -3 flag
We now need to add one last minus (to initialize the -1 flag we just got to). All we need to do this is change the minus 2 to a plus 1, then cascade. This both performs the appropriate multiplication by 8, and encodes a -.
Finally, we just need to encode the 1 at the top of the binary representation. To do this, we move b over by 1 one last time and add a 1 at the top, then cascade.
And there it is! We've now printed out 0s representing every part of our original code.
Thank you, and I'm sorry.
Source code
The brainfuck is a little bit long when fully commented (~200 lines), so I'm not certain if I should post it, but I figure y'all can at least have the un-pretty source:
->++>+>+>++>++>+>+>++++++>+>+++>>+++++++>+>++>++++++>>>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>>>++++++>+>+++>>+++++++>+>++>+++++++>>>>++++++>+>+>+>++>>>>+++++++>++>+>+>++++++>+>+++>>+++++++>+>++>+>+>+>+>++>>>++++++>+>+>+++>++>++++++>>>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>>>>>>++++++>+>+>+>+>+++>>>>>+++++++>+>+>+>+>++>+++++++>>>>++++++>+>+>+>++>>>>+++++++>++>>++++++>+>+>+>+>+++>>>>>+++++++>++>+>+>+>+>++>>>+++++++>+>+>+++>>>>>>>>++++++>+>+>+>++>>>>+++++++>+++>+>+>++++++>+>+++>>+++++++>+>++>++>+>+>++++++>+>+>+>++>>>>+++++++>+>+>+>++>++>+>+>++++++>+>+>+++>>>+++++++>+>+>++>++++++>>>>>++++++>+>+>+>+>+>+++>>>>>>+++++++>+>+>+>+>+>+++>>>>>>++++++>+>+>+>+>++>>>>>+++++++>+>+>+>+>+++>>>>++++++>+>+>+++>>>+++++++>+>+>++>+++++++>+>++++++>+>+>+>+>+>+++>>>>>>+++++++>++>+>++++++>+>+>+>+>++>>>>>+++++++>++>>>++++++>+>+>+>+>+>+>+++>>>>>>>+++++++>+>+>+>+>+>+>++>++>>>>++++++>+>+>+>+++>++++++>>>>>++++++>+>+>+>+>+>+++>>>>>>+++++++>+>+>+>+>+>+++>>>>>>++++++>+>+>+>+>++>>>>>+++++++>+>+>+>+>+++>>>>>>>>++++++>+>+>+>+>+>+>+++>>>>>>>+++++++>+>+>+>+>+>+>++>+++++++>>>>>>++++++>+>+>+>+>+>+++>>>>>>+++++++>++>+>++++++>+>+>+>+>++>>>>>+++++++>++>>>++++++>+>+>+>+>+>+>+++>>>>>>>+++++++>++>+>+>+>+>+>+>++>++>>>>+++++++>+>+>+>+++>+++>>>>>>>>>>>>>>++++++>+>+>+>+>+>+>+>+++>>>>>>>>+++++++>>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>++++++>>++++++>+>+>+++>>>+++++++>+>+>+++>>>>>>++++++>+>+>+>+>++>>>>>+++++++>+>+>+>+>+++>>>>>++++++>+>+>+>+++>>>>+++++++>+>+>+>+++>+++++++>++>++>++++++>>++++++>+>+>+++>>>+++++++>+>+>++>>>>>++++++>+>+>+>++>>>>+++++++>+>+>+>++>+++++++>>>++++++>+>+>+++>>>+++++++>+>+>++>++>++>+>+>+>++++++>+>+>+>++>>>>+++++++>+>+>+>++>+>+>+>+>+>++>++>>>>>++++++>+>+>+>+>+++>++++++>>>>>>++++++>+>+>+>+>+>+>+++>>>>>>>+++++++>+>+>+>+>+>+>+++>>>>>>>++++++>+>+>+>+>+>++>>>>>>+++++++>+>+>+>+>+>++>+++++++>>>>>>>++++++>+>+>+>+>+>+>+++>>>>>>>+++++++>++>+>++++++>+>+>+>+>+>++>>>>>>+++++++>++>+>+>+>+>+>++>++>>>>>+++++++>+>+>+>+>+++>+++>>>>>>>>>>>>>>>++++++>+>+>+>+>+>+>+>+>+>+++>>>>>>>>>>+++++++>>++++++>+>+>+>+>++>>>>>+++++++>+>+>+>+>+++>++++++>>>++++++>+>+>+>+++>>>>+++++++>+>+>+>+++>>>>>>++++++>+>+>+>+>++>>>>>+++++++>+>+>+>+>+++>+++++++>>>>++++++>+>+>+>+++>>>>+++++++>+>+>+>++>++>>>>>>>++++++>+>+++>>>>>>>>>++>+++++++>+++>++>+>+>+>+>+>+++>+++>+++>++++++>+>++>++>++++>+++>+++>+++++++>>>>++++++>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>+++>++++++>+>++>++>++>++++>++++>++++>++++>++++>++++>++++>++++>+++>+++>+++>+++++++>>++++++>+>++++++>++>+>++>+++++++>+++>>+++++++>+++>+>++>>>>>>>>>+++>>>>+++++++>+>+>++>+>+>+>+>++++++>+>+>+>+>++>>>>>+++++++>>>>>>++++++>+>+>+>+>+>+++>>>>>>+++++++>>>++++++>+>+>+++>>>+++++++>+>+>+++>>++++++>+>++++++>>>++++++>+>+>+>++>>>>+++++++>+>+>+>++>++++++>+>++>>+++>+++++++>+++>>>>++>+>++++++>+>+>+++>>>+++++++>+>+>+++>+++++++>++>>>+++>+>+>++>>>>>>++++++>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>+++>++++++>+>++>++>++>++++>++++>++++>++++>++++>++++>++++>++++>+++>+++>+++>+++++++>>++++++>+>++++++>++>+>++>+++++++>+++>>+++++++>+++>+>++>>>>>>>>>+++>>>>+++++++>+>+>++>+>+>+>+>+>+>++++++>+>+>+++>>>+++++++>+>+>+++>>+++++++>+>++>>>>>>++++++>>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>+++>++++++>+>++>++>++>++++>++++>++++>++++>++++>++++>++++>++++>+++>+++>+++>+++++++>>>++++++>+>+>++++++>++>+>+>++>+++++++>+++>>>+++++++>+++>+>++>>>>>>>>>+++>>>+++++++>+>++>+>+>+>+>+>++++++>+>+>+>++>>>>+++++++>+>+>+>++>++++++>+>++>>+++>+++++++>+++>>>>++>+>+>++++++>+>+++>>+++++++>+>++>>>>++++++>>++++++>+>+>+>++>>>>+++++++>+>+>+>+++>+++>++++++>+>++>++>++>++++>++++>++++>++++>++++>++++>++++>++++>+++>+++>+++>+++++++>>>++++++>+>+>++++++>++>+>+>++>+++++++>+++>>>+++++++>+++>+>++>>>>>>>>>+++>>>+++++++
>-->>--[-<+]->[++[--->+++]---<++[-<+]->]+++[--->+++]>--[-<+]->---->++[--<>[++[--->+++]---<+++++[----<++++]---->]+++[--->+++]>+[----<++++]>---->++]--<+++++++[--->+++]<--[-<+]->>--[--->+++]--->>--[--<++]-->[++++[-----<+++++]-----<+++++[---->++++]----<+++[--<++]-->]-[-----<+++++]>-[---->++++]>++[------<++++++]------>>+++[---<[++++[-----<+++++]-----<+++++[---->++++]----<+++++++[------<++++++]------>]+++++[-----<+++++]>-[---->++++]>++[------<++++++]>------>>+++]---<<+++++++++++++[-------<+++++++]+[--->+++]---<[+[--<++]--<+++++[---->++++]----<++++[---<+++]---<]>>[+[--<++]-->++++[--->+++]--->]++[--<++]-->>>---[--->+++]--->----->>++++[----<[+++++[------<++++++]------<++++++[----->+++++]----->]++++++[------<++++++]>-[----->+++++]>----->>++++]----<<++++++++++++++[---------<+++++++++]+[---->++++]----<[++[---<+++]---<+++++[---->++++]----<]+++[---<+++]--->>++++++[-<++++++++>]<>-----<<<[->>.<<]+++[[--->+++]---<<[->>>........<<<]+[-[>->]<+]<->++++++++<+++]-->----[---->++++]+++++[-----<+++++]++[--<++]--<+[-[++[--->+++]--->[->+<]<+++>-[--<++]--<]>++<-->+++++[[--->+++]---<<[->>>........<<<]+[-[>->]<+]<->++++++++<+++]-->------[--<++]--<+]->+++++[+[--->+++]---<<[->>>........<<<]++[--[>-->]<++]<->++++++++<++]->-----[--->+++]--->[->+<]<+++>--[-<+]->+++[+[--->+++]---<<[->>>........<<<]++[--[>-->]<++]<->++++++++<++]
The exact number of 0s used is
616143364761046940121393482224894339867345380201767130133313486919095927124457356445367231747521140266173370022946551757495986436536081196868045297628272330390384059772395971191779286883783813697712702083311380720802629542181528279259974270122382291334259076670078283456907144090063837123521728109038972289254725923131778417128787123839239037575809566518515144698909511013229597825122095407702198996899541417882553289474401282217717777845438435506256387112472797473268235689408744655098869728879606757978358505806156421963379547318142883884528468751816610374042589741195416986282360597637951748580316227437951083206547340002950237138353873683827224872420688269051148041914106540181545636126975204020515616888610209347943212212684032994981872040279134760921950441974664462626740824769006477972532358261625821022468550562561067773665916456352101740599621566669636512759138416019741339956533219082231457782020998061560188458949523569043543472825311694153186492127832152368263433627346401816742081184272285138868588737702544161051266511345401776302508848404989044851701234612868569930533447734786659774504348270829815069786996595352931052563253833910670459061338664835111006064026972821593395459376847379338727645638102959876509529598180508190944759740278032543135323831096032264282759700516599819159593380726609694016158768372040897232130064627016970719454234890810133557942103242082428193652525717784679766009840567745646644331050845934041815088097332504352438215802005681361724732417128846494405432135929762912067831306775322080038483165731774473085357566563624402414177907348890170209026776293825006497117681077216606902562225184543780956129658804093641090955334441702108200564658744439989789201224157261892503165643308457788492416371138829568712401818445624554600923862455172225972137155277042400428634635794267865563766239731245919228046855426376607293646700303578427596008362291239931429658436763436719678326692915408656227680419507941034924280704994802195387552837470839012206296262948274121554534825929221937317579576287409893717258523001476821273741591905466514991100795003027995820718624627560000685829593037893516218245771605918736777569490302646860116831211143429524438818972119953427472167111184521816913965170021208796837058611193110390517567196364486837447552746813630060986477162908564149642028449379763465797559696051374230746360712939114777230926431439196151657705180265020483638629061181115856223950249806419818375856529987900246040227082601855626646444080216637310658434683889414278770982063250184353729183793452944251724697854181617951614799763586644028479802980036647045105801552589931160634006431597294780772117688186110086846079813170103829768160563126247208942693587842950980471492950218296552846456932278774596999132699204842933464261728949352373762279520360130690593476460298502885309846199176184758132580237138986886575217114963071503275472309839043003811612480724199448586309349213643468070828586583244591263370384564485550086863984151080517206405235910197380819828141069270492593578986828345436437174028486982241355518138451897126139232242703752607826960024771549490116659322453183855123857138475614101348080310760135256588738232612996648332732281155595814319181966181574401320500067489163573212418944844484950259082074896272135947770797061836016279282123019467117684670513267319113631747092736545960755034809236690912731932588771491682676453979945982754468716932978590114642741630083944274379070387978397185461190324579966999262505612480431374579002240579057976399577489156724969889391725011201833796208889208642431523656036515892951544697280547449403879151875515288785339517008449261777065296448378328263083714549226346273500515673503831635754141766922846713000935292132391822069931132294405910519960461798776924488932623464859144582786720457864275598371518594949910770504649195142874620028228890448589489597208338562687621880437805894822197524541279873734273522403771848708628352939445662430217734644866430785751657273790572085485900108956813143322699032604055731135389248624818347278303261582515845621280853277496120155330289546717304073439125810011869192307295393119864362022104242206053603655047887527558361040028989920694801323274066616457054148538214643602629113440692125709885109559566032777838457552957583786148605526507117591555800832794105245862353696525934364943795116979478987279494334241959368528163214344004159915398916504737171079910682142420502023
Keg, 8 6 4 bytes
`④`④
Answer History
8 bytes
`:.,`:.,
Why did it take me so long to figure out how to write a quine in Keg? I really should have picked up on this sooner.
Basically, it pushes the string :.,, duplicates it, prints the string repr'd and then prints it nicely.
Pyth, 9 8 bytes
p+N
"p+N
Saved one more byte by using the newline operator
(Also I made this ages ago but forgot to edit this so yeah)
Symbolic Raku, 36 bytes
$_={$_~"<$_>)"}(<$_={$_~"<$_>)"}(>)
Explanation:
$_= # Set the output to
{ }( ) # The result of the code block
< > # With this string:
$_={$_~"<$_>)"}( # The first half of the program
$_~ # Concatenate this string with
"<$_>)" # The quoted string, and the extra bracket
BaCon, 54 bytes
Without using the SOURCE$ variable, the smallest Quine is 55 bytes:
s$="s$=%c%s%c:?34,s$,34 FORMAT s$":?34,s$,34 FORMAT s$
JavaScript REPL, 21 bytes
(_=$=>`(_=${_})()`)()
It technically doesn't read its own file.
… kind of seems like 0 is also a quine for JavaScript the way this is evaluated, though.
Poetic, 2100 1896 bytes
-204 bytes by using ASCII 255 and 1 instead of ASCII 122 and 123.
ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿÿ ÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿ ÿÿÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿ
(All of the space characters are actually ASCII code 1, or SOH. StackExchange doesn't seem to like unprintables all that much.)
Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.
This isn't a terribly Poetic program (it's only two distinct characters), but it's the most compact solution for writing commands that I was able to come up with.
Basically, the core of the program is code that takes tape values corresponding to Poetic commands in a line, adds values to the beginning that would put these values on the tape when executed, and then outputs the values as Poetic commands. The initial values on the tape are, of course, an encoded version of that code. (Standard stuff, surely, but it took me a while to wrap my head around it.)
Alchemist, 299 bytes
_->14733272090064622117723033634640281434301133345502153207896692199003336573010981052872005814325038964478266287468505274190371239580629370336756929651609657090021232407437472153714372752689076920028135a+Out_"_->"+Out_a+d
d+0e->118b
a+b->o
118o->c+d
0a+0e+c->Out'o+e
e+b->e+o
e+d+c->e+d+a
0c+e+d->d
I'm posting this as a separate answer to my existing one since it uses newer features (character output). This functions much the same but with less logic regarding the modulo values, countered partially by the number being in base 118 instead of base 9. Here is an encoder that can be used to encode the large number up front.
Wren, 287 bytes
var a="[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)"
[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)
Explanation
var a= // Define the variable a
"[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)" // As the string that processes the variable
// A literal newline is inserted and can be decoded literally.
[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))} // Output the string "var a=" to the console
System.write( // Output without a newline:
a // The string a
+String.fromCodePoint(34) // Plus a quote
+String.fromCodePoint(10) // Plus a newline
+a) // Plus the string again
```
Klein, 330 bytes
"![ .; =90*/[ .9(#; =[>[. >1# 98='9[ '7[.>; [*; ) =#0,*[ =.>9(. =*(#(#([ .0#8;#(#; [*9>[; => [*? [9(;;"\
/ <
>:1+0\
/:)$<
>\?\ /
?2 $
:9>(:\
(8\/?<
\+ <
*
>$1-+\
>/?:) /
>+)$)$)\
/1$9<$)$<
\+:?\<
>?!\+@
\:)<<
This works in all topologies, mostly by completely avoiding wrapping. The first list encodes the rest of the program offset by one, so newlines are the unprintable (11).
Tir, 24 bytes
Abandoned languages are my favorite.
«⤇℘↔»
⤇℘↔
Explanation
«⤇℘↔» Push a string onto the stack. Stack: [⤇℘↔]
⤇ Duplicate TOS. Stack: [⤇℘↔,⤇℘↔]
℘ Make top of stack in its string-represented form. Stack: [⤇℘↔,«⤇℘↔»]
↔ Swap top two items in the stack. Stack: [«⤇℘↔»,⤇℘↔]
Stack will be implicitly outputted.
Corea, 11 bytes
<0C>;"<0C>;
Alternatively, <0C>>"<0C>>
<0C>;"<0C>;
<0C>; set the contents to that literal string
" start command sequence
< push a copy of the contents to the stack
0C push a quote "
> append that to the contents
; and append the original copy and stop command sequence
Whitespace, 338 bytes
-3 bytes thanks to Dorian pointing out a mistake
Not really much to see, but the code is there. This terminates with a 'Can't return from subroutine' error, which is only about 10 or so bytes extra to remove. Translated from whitespace, the tokens are:
push 213928514417226051472880134683878051755207959239232598316788086
push 2
call PRINT_SPACE
call PRINT_SPACE
call DIV_MOD_PRINT
push 1
add
label DIV_MOD_PRINT
copy 2nd item in stack
copy 2nd item in stack
div
jump if zero to POP_AND_PRINT_SPACE
copy 2nd item in stack
call DIV_MOD_PRINT
mod
dupe
jump if zero to POP_AND_PRINT_SPACE
push 8
add
print as character
return
label POP_AND_PRINT_SPACE
pop
label PRINT_SPACE
push 32
print as character
return
This starts off by pushing a rather large number in binary spaces and tabs. This number represents the rest of the program in trinary (since Whitespace has 3 valid characters), with space being 0, tab being 1 and newline as 2.
The main part of this code is the DIV_MOD_PRINT function, which assumes that the large number and the divisor is on top of the stack. This makes a copy of the two elements, then divides the number by the divisor and recursively calls the function again, returning once the result of the division is zero. On the tail call, this takes the two copied elements and gets the remainder after division. Then it maps it to the representation above.
This function is reused twice on the large number we pushed at the beginning, once with the divisor 2 to print the number itself in tabs and spaces, and again with 3 to print the rest of the program.
There are a couple of caveats; for example, we can't represent leading spaces with leading zeroes, so we with have to print those manually before we call the function the first time. This is partially mitigated by the fact that we stop the recursion by jumping to the POP_AND_PRINT_SPACE label, which means that we print a leading space anyway.
However, that causes one of the modulo pairs not to be evaluated, therefore the last character represented is not printed. This is actually a good thing, for a couple of reasons. First, since the binary number representation is terminated with a newline which would have had to have been printed (since we print a leading space), instead, if we ensure the last character of the binary number is a space, the newline is now the first character of the rest of the program. We can make the last character a space easily, since we aren't printing the last character of the program by adding a space or tab when encoding the number literal.
For reference, my encoding program, my commented program, and I used WhiteLips to debug the program.
1+, 834 bytes
(|11+"*"+"1+\1+/)("|1/()11+^)(2|\""++1+/()""+^)++<+/(#|\##"\+;1#()\^\1#)+<+()()(")(2)(2)()()(")()(2)(")(2)()(")()(")()()()(2)(")()()()(2)()()(2)()(")()()()()(2)(2)(")()()()(2)()()(2)()(")(2)()(")(2)(")()(")()()()(2)(")(2)(2)()(")()(2)(")()()()(2)()()(2)()(")(")()(")()(")()()()(2)()()(2)()(")(2)()(2)()(2)(")()(")(2)(")()()(2)()(")()(2)(")(2)(2)()()(")()(2)(")()(2)(")(2)()(")()()()()(2)(2)(")()(2)(")(")(")(2)()(")(2)(")()()(2)()(")()(2)(")()()()(2)(")()(2)(")()(2)(")(")(")()()()(2)()()(2)()(")(2)()(2)()(2)(")()()()(2)()(")(2)(")(2)()(")()()()()(2)(2)(")()(2)(")()()()(2)(")()()()(2)(")(2)()(")(2)(")()()(2)()(")()()()(2)(")(2)()(2)()(2)(")(")(2)(")(2)()(")()()(2)()(")()(2)(")()()()(2)(")()()()(2)()()(2)()(")()(2)(")()()()(2)(")(")()(2)(")(")(2)()()(")(")()(2)(")()()()(2)(")()()()(2)(")(2)()(2)()(2)(")(2)(")(2)()()(2)(")(")(#)@
Defines all the subroutines before the data section, then calls the (#) subroutine at the end of the data. Instead of using 1s followed by totalling 1+s, we define subroutines for initialisation ((")), which pushes a 2 to the stack, incrementing (()), and doubling plus 2 (ironically, (2)). All of these also push the characters used to call the subroutine to the top of the stack to print after printing the rest. We also offset the data by 32, since all values are above that.
This is most certainly suboptimal, especially since I've been steadily golfing it down from ~2000 bytes. I suspect it can be sub-500 eventually, or even lower with a different strategy.
Here's my program encoder, though it needs some post-fiddling with the first value to make sense.
1+, 5424 4978 4808 4112 3962 3748 bytes
11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1111+1+1+1+1+1+1+1+1+1111+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+11+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1111+1+1+1+1+1+1+1+1+1111+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1111+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+11+11+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+1+1+1+11+11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+11+1+11+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+1+1+1+11+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+1+(|11+1<)\(1|1""+""*++"*;)($|1+11#(1)1""+""*+""*++;1#1+"//"\^\<11+*#()*+\)(%|()#(1)($)"1+1<#)\(&|()#11+"*"*"++;\"1+1<#)
Keg, 21 bytes
HBZLTXJMIC(":,48*-)#
The string of letters translates to the code section reversed and shifted up by 32. It's lucky all the characters used are in the correct range for shifting.
Explanation:
( ) # Loop over the stack
" # Shift stack left
: # Duplicate the letter
, # Print the letter
48*- # Subtract 32 from the ordinal value of the letter
# # Comment out the newline
# Print the shifted characters with a trailing newline
Keg, 49 43 bytes
\^\(\\\\\,\:\&\^\&\^\,\)\^\#^(\\,:&^&^,)^#
(note the trailing newline...)
-6 bytes thanks to Jo King reminding me that comments exist
This is a horrible mess, and I'm sure it can be outgolfed easily by someone comfortable with Keg's stack, and/or once "/' stop erroring. The first two thirds simply push each character from the last third to the stack in order (such that the last character is on top), and then the last third:
^ Reverses the stack (such that the first character is on top),
( ) then does the following for each item CURRENTLY on the stack:
\\, print a backslash,
: duplicate the top of the stack,
& pop it to the register,
^ flip the stack,
& push the register,
^ flip the stack again,
, and pop and print the top of the stack;
^ finally reversing what's left on the stack
#\n and commenting out the trailing newline,
so the stack is then implicitly printed bottom first,
with a trailing newline.
Essentially, it prints the first two thirds while copying itself onto the bottom of the stack, then flips the copy to be implicitly printed.
Hexagony, 261 bytes, side length 10
113009344778658560261693601386118648881408495353228771273368412312382314076924170567897137624629445942109467..../....%'=g':..\..................\.................\................\...............\..............\.............\............\!$/'?))='%<\..>:;/$;4Q/
Uses the same encoding user202729's answer, but terminates in a divide by zero error.
Formatted, this looks like:
1 1 3 0 0 9 3 4 4 7
7 8 6 5 8 5 6 0 2 6 1
6 9 3 6 0 1 3 8 6 1 1 8
6 4 8 8 8 1 4 0 8 4 9 5 3
5 3 2 2 8 7 7 1 2 7 3 3 6 8
4 1 2 3 1 2 3 8 2 3 1 4 0 7 6
9 2 4 1 7 0 5 6 7 8 9 7 1 3 7 6
2 4 6 2 9 4 4 5 9 4 2 1 0 9 4 6 7
. . . . / . . . . % ' = g ' : . . \
. . . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . . \
. . . . . . . . . . . . . . \
. . . . . . . . . . . . . \
. . . . . . . . . . . . \
! $ / ' ? ) ) = ' % < \
. . > : ; / $ ; 4 Q /
. . . . . . . . . .
Some python-like psuedo-code to explain:
n = ridiculously long number
base = 103
print(n)
while n > 0:
b = 2
if n%b == 1:
c = '.'
print(c)
else:
n = n//b
b = base
c = chr(n%b + 1)
print(c)
n = n//b
I'm using base 103 rather than the optimal base 97 just to make sure the number fully fits the top half of the hexagon and doesn't leave an extra . to encode.
Here's a link to user202729's encoder that I used to get the large number and check that the number actually fit in the hexagon.
Amazon Alexa, 31 words
Alexa, Simon Says Alexa, Simon Says
Alexa, Repeat That
Alexa, Simon Says Alexa, Repeat That Alexa, Simon Says, Alexa, Repeat That Alexa, Simon Says
Alexa, Repeat That
Alexa, Simon Says quiet
(each command is on a newline)
When said out loud to a device with the Amazon Alexa digital assistant enabled (I've only tested this on the Echo Dot though), it should say the same words back to you. There will be some different lengths of pauses between words, as you wait for Alexa to reply, and it says everything without breaks, but the sequence of words are the same.
Explanation:
Each line is a new Alexa command, one of either:
Alexa, Simon Says ..., which will prompt Alexa to say everything afterward the commandAlexa, Repeat That, which repeats the last thing Alexa said
(neither of these appear on most lists of Alexa commands, so I hope someone has actually learned something from this)
We can simplify this to the commands S and R respectively, separated by spaces. For example, SR will represent Alexa, Simon Says Alexa, Repeat That. The translation of our program would be:
SS R SRSRS R SQ
Where Q is quiet (but can be anything. I chose quiet because that's what Alexa produced when I tried to give it quine, and it fit, so I kept it). Step by step, we can map each command to the output of each command:
Commands: SS
Output: S
Commands: SS R
Output: S S
Commands: SS R SRSRS
Output: S S RSRS
Commands: SS R SRSRS R
Output: S S RSRS RSRS
Commands: SS R SRSRS R SQ
Output: S S RSRS RSRS Q
Total Commands: SSRSRSRSRSQ
Total Output: SSRSRSRSRSQ
The general approach for this was to get the output ahead of the input commands. This happens on the second to last command, which gets an extra S command. First we have to get behind on output though. The first two commands SS R only produce SS, leaving us to make up the R. However, this allows us to start a S command with an R, which means we can repeat a section (RSRS) multiple times, which allows us to get the spare S leftover. After that, all we had to do was use it to say whatever we wanted.
Fission, 6 bytes
It appears this is now the shortest "proper" quine among these answers.
'!+OR"
Explanation
Control flow starts at R with a single right-going (1,0) atom. It hits " toggling print mode and then wraps around the line, printing '!+OR before hitting the same " again and exiting print mode.
That leaves the " itself to be printed. The shortest way is '"O (where '" sets the atom's mass to the character code of " and O prints the character and destroys the atom), but if we did this the " would interfere with print mode. So instead we set the atom's value to '! (one less than "), then increment with + and then print the result with O.
Alternatives
Here are a couple of alternatives, which are longer, but maybe their techniques inspire someone to find a shorter version using them (or maybe they'll be more useful in certain generalised quines).
8 bytes using Jump
' |R@JO"
Again, the code starts at R. The @ swaps mass and energy to give (0,1). Therefore the J makes the atom jump over the O straight onto the ". Then, as before, all but the " are printed in string mode. Afterwards, the atom hits | to reverse its direction, and then passes through '"O printing ". The space is a bit annoying, but it seems necessary, because otherwise the ' would make the atom treat the | as a character instead of a mirror.
8 bytes using two atoms
"'L;R@JO
This has two atoms, starting left-going from L and right-going from R. The left-going atom gets its value set by '" which is then immediately printed with O (and the atom destroyed). For the right-going atom, we swap mass and energy again, jump over the O to print the rest of the code in print mode. Afterwards its value is set by 'L but that doesn't matter because the atom is then discarded with ;.
Javascript (REPL), 23 22 21 bytes
someone else posted this first
(_=x=>`(_=${_})()`)()
paste into chrome console or equivalent to test
JavaScript (V8), 49 48 47 bytes
@NieDzejkob saved 1 byte on both versions
console.log((_=x=>`console.log((_=${_})())`)())
Ruby, 27 bytes
eval s="$><<'eval s=';p s"
$><<'...' is equivalent to print'...' (outputs the string without a newline).
Note the newline at the end of the program.
33, 26 bytes
"34cktptptptp"34cktptptptp
Explanation:
"34cktptptptp" (The instructions)
34ck (Load 34 (") into destination string)
tp (Print it)
tp (Print the instructions)
tptp (Repeat)
C, 353 bytes
char q[]={125,59,109,97,105,110,40,41,123,112,114,105,110,116,102,40,34,99,104,97,114,32,113,91,93,61,123,34,41,59,99,104,97,114,42,112,61,113,59,119,104,105,108,101,40,42,112,41,112,114,105,110,116,102,40,34,37,100,44,34,44,42,112,43,43,41,59,112,117,116,115,40,113,41,59,125,};main(){printf("char q[]={");char*p=q;while(*p)printf("%d,",*p++);puts(q);}
C (gcc), 85 bytes
#define q(k)main(){puts(#k"\nq("#k")");}
q(#define q(k)main(){puts(#k"\nq("#k")");})
The q() macro expands into a program that prints out its argument on the first line, and prints out the argument called by q() itself in the second line. So:
#define q(k)main(){puts(#k"\nq("#k")");}
q(foo)
would expand into:
main(){puts("foo""\nq(""foo"")");}
and after string literal concatenation, becomes:
main(){puts("foo\nq(foo)");}
And executing and running the program would produce:
foo q(foo)
Replacing foo with the macro definition itself results in the quine.
Java, 515 bytes
In order to make this quine, I made strings representing every part of the code that needed to be printed. Then, I created and printed a string representing the code by adding the strings together.
This is my first time playing code golf, let me know what you think of my quine!
interface a{static void main(String[]a){String ce="interface a{static void main(String[]a){String ",e="=",c="\",",q="\"",cq="\\",ec=";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq",eq=");}}",ee="e",cc="c",qq="q";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq);}}
in readable form:
interface a
{
static void main(String[] a)
{
String ce = "interface a{static void main(String[]a){String ",
e = "=",
c = "\",",
q = "\"",
cq = "\\",
ec = ";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq",
eq = ");}}",
ee = "e",
cc = "c",
qq = "q";
System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq);
}
}
C# (Visual C# Interactive Compiler), 57 bytes
var s="var s={0}{1}{0};Write(s,'{0}',s);";Write(s,'"',s);
There is another C# answer that uses a console application with a Main method. This approach seemed a little outdated given most current C# answers use the Visual C# Interactive Compiler. This compiler allows for a much shorter variation using the exact same technique.
A Classic - Lisp - 78
((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))
A beautiful snippet, but give credit where credit is due.
Fob (135)
In Fob, a language of my own creation from some time ago, I present a rather interesting 135-byte quine:
$$#<&$::#<&$:#<&#<&$:#<=#<&$&//%<//<.&%<<%.%<&>/////%<<%.<&.%<.%/////<&.%<<&/.%%<&>%</%<////<&.%<<%/<&.%%<&>/%//<&.%<</&.%%%<&>>/>>#<=
Brian & Chuck, 211 143 138 133 129 98 86 84 bytes
?.21@@/BC1@c/@/C1112BC1BB/@c22B2%C@!{<?
!.>.._{<+>>-?>.---?+<+_{<-?>+<<-.+?ÿ
old version:
?{<^?_>{_;?_,<_-+_;._;}_^-_;{_^?_z<_>>_->_->_*}_-<_^._=+_->_->_->_-!_ ?_;}_^_}<?
!.>.>.>.+>._<.}+>.>.>?<{?_{<-_}<.<+.<-?<{??`?=
New code. Now the data isn't split into nul separated chunks, but the nul will be pulled through the data.
Brian:
? start Chuck
.21@@/BC1@c/@/C1112BC1BB/@c22B2%C@!
data. This is basically the end of the Brian code and the Chuck code reversed
and incremented by four. This must be done because the interpreter tries
to run the data, so it must not contain runnable characters
ASCII 3 for marking the end of the code section
{<? loop the current code portion of Chuck
Chuck:
code 1 (print start of Brian code)
.>.. print the first 3 characters of Brian
code 2 (print the data section)
{<+>>- increment char left to null and decrement symbol right to null
for the first char, this increments the question mark and decrements the
ASCII 1. So the question mark can be reused in the end of the Chuck code
?>. if it became nul then print the next character
---?+<+ if the character is ASCII 3, then the data section is printed.
set it 1, and set the next char to the left 1, too
code 3 (extract code from data)
{<- decrement the symbol left to the nul
?>+<<-. if it became nul then it is the new code section marker, so set the old one 1
and print the next character to the left
+? if all data was processed, then the pointer can't go further to the left
so the char 255 is printed. If you add 1, it will be null and the code ends.
ÿ ASCII 255 that is printed when the end of the data is reached
Golunar, 951 bytes (394.25 bytes as an integer value)
19370043316195921194914466480856680152267470323963447024756684537596068724128114478400203537500358028693578705195025299449504112473728653294217406768139954805008550643064305270958743186186490023003785512463398359429631224818444304976679217098389450981926661910005004089131207223929032173888419619738722341444212432611576207643452266161684471788295034889655803444137372629364500165719019777515305922257911642994836581634099155833200157295629218533465854143898419293035289733581625252699105530843807023973345521520887128012736565874423200184723012755626596238647926406709693583878890472621210970350861368171259284533764490596207310864352873729240842719608391238098412446205860013948766486129442046252306334230243913196704614648889659870117069927719874852423159076941049170045933025772364248625729725500550726133134993128102614696728457139079375133324957922066270555810085574853273966267981675757808791933974619299446035844180580831907739236954600685575
Golunar is the decimal representation of the number of zeros that a Unary code would need. It translates to this brainfuck code:
->+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>+[[>>+[>]+>++>+[<]<-]>>[>]<<-[<]<<+]+>+>-[>]++>++>++[[-<+]-<[-<[>++<-[>++<-[>++<-[>++<-[>--------<<[-]++>-[>++<-]]]]]]>[<+>-]+<<]>>[>>]<[>]<-[[-<+]-<<+>[>>]<[>]]<+]<[<<]>>[+++++++[<++++++>-]<.>>>]
I couldn't find an online Golunar interpreter, but you can use this Golunar to brainfuck converter to get the brainfuck code and then execute it.
This code is inspired by a brainfuck quine of Eric Bosman and Daniel B Cristofani. First it reads a list of bits that represent the bit-codes of the code part, then it builds up a list of bits that represent the ">" and "+" characters needed to print the first list. Those lists are merged and hold the binary value of the Golunar code. In the last step, the decimal value of the binary number are computed and printed.
[
tape: [decimal digits], value start marker/VS(-1)(starting cell), [input bits], between binary marker/BB(0), [binary output data]
input bits are 0 or 1, output bits are in reversed order and have the values 1(used) or 2(used and set)
input must be given in reversed order
decimal digits consist of two cells per value (value, digit used marker(DU)(1))
bit values:
> 000
< 001
+ 010
- 011
. 100
, 101
[ 110
] 111
]
- set VS
set input bits
>+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>
+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+
>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>
>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>
>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>
>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>
>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+
>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>
>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>
list rebuilding loop: append bits for "greater than" and plus symbols to the right of input data
+[ for each input bit
[ while bit is greater than 0
>>+ copy bit to out data
[>]+>++>+ append bits for plus (used markers plus 010)
[<]<- decrement in value
]
>>[>]<<- change most right character from plus to gt (010 to 000)
[<] return to BB
<<+ repeat if not on VS
]
+>+>- prepare binary to decimal routine: set VS DU and first 1
[>]++>++>+ append bits for minus (011)
binary to decimal loop: use "double and add algorithm" to calculate the digits of the decimal value
+[ if not on VS then
[-<+]- restore current bit value and go to VS
< go to first DU
[ digit doubling loop
-< remove DU and go to corresponding digit
[
>++<- decrement current value and add 2 to temp value four times
[
>++<-
[
>++<-
[
>++<-
[ if value was greater than 4 then
>---- ---- subtract 8 from temp
<<[-]++ set next digit temp = 2 (DU plus 1)
>- decrement current digit
[>++<-] set temp = remaining value * 2
]
]
]
]
]
>[<+>-] set current digit = temp
+ set DU
<< go to next digit
] end of digit doubling loop
>>[>>]<[>]< go to current bit
-[ if bit is 2 (used plus 1)
[-<+]- delete bit and go to VS
<<+ increment least significant digit
>[>>]<[>] go to current bit
]
<+ if not on VS then repeat
] end of binary to decimal loop
<[<<]> go to most significant digit
>[ printing loop: for each DU print corresponding value
+++++++[<++++++>-]<. add 48 to value (ASCII 0) and print
>>> go to next DU
]
Fueue, 411 391 381 376 bytes
(5(2(7(1(8(0(0(4(0(2(5(2(4(9(9(0(4(9(0(2(4(2(8(2(1(6(9(0(6(2(9(5(9(5(9(0(1(1(4(0(3(2(3(1(3(1(9(1(8(1(1(1(0(1(4(0(1(2(3(1(3(1(7(1(6(1(9(0(4(9(9(5(8(2(4(9(9(0(4(9(4(9(1(6(9(0(4(9(1(0(1(6(4(9(9(5(4(9(9(0(4(9(4(9(1(6(9(0(4(9(6(2(9(5(9(0(3(1(3(1(4(9(1(1(0(2(6(1(3(1(3(1(0(2(4(2(9(0(4(9(6(2(1(6(4(9(1(6[10(:91(H49~)~48<]):[[)+$7--32+*$5--10)~[<~)~~])~!]~[~)~~])~:[)--~+40--48)~:]~]
See also Ørjan Johansen's answer.
Basic idea (outdated):
(7(1(9(5(1(1(8(0... Data.
[9!(91[+(H~)]57<33] Begin the second pass and end the program on second pass.
):[ Duplicate and evaluate the block.
[)+$7--32+*$5--10)~[<~)~~])~!] On the second pass, print b*10+a+32 for each two digits a, b.
)()[~)~~]~:~< Copy a digit and evaluate the next line between copies.
[)----40+--~)48~:~~] Print "("+digit and duplicate and evaluate the whole block on the next digit.
]
Tcl, 47 bytes
puts [join {p \{ \}]} {uts [join {p \{ \}]} }]
Based on Joe Miller's quine on this page.
Brachylog v2, 12 bytes
"~k;?w₁";?w₁
Full program. Essentially a translation of Fatalize's (non-builtin) Brachylog v1 answer, although it also uses different SWI-Prolog formatting sequences, or rather, a single different one, which saves about 20 bytes (both [34:s, both :34]s, and both ~cs). It seems to have existed back in 2016, but it was probably bugged or something. The last two bytes saved come from using the implicit input, which Brachylog being Brachylog is useful even when the program receives no input, because it's a variable (so instead of explicitly unifying the string with S, we just let it be implicitly unified with ?).
w Print
"~k;?w₁" "~k;?w₁"
which is the input
₁ formatted with
;? the input.
~k (so that the ~k is replaced with the input's canonical representation, i.e. in quotes)
We don't actually need to use implicit input--"~kgjw₁"gjw₁ works just as well (and might even translate back to v1)--but doing so regardless manages to both more closely mirror the structure of the original and feel cleverer.
Tamsin, 67 bytes
main='->T&$:repr(T)->U&\'main=\'+U+T.'->T&$:repr(T)->U&'main='+U+T.
Ungolfed (isn't a quine, but outputs a quine):
main = '→T&$:repr(T)→U&\'main=\'+U+T.' → T
& $:repr(T) → U
& 'main=' + U + T.
Tamsin has a builtin that formats strings correctly, which makes this fairly easy.
Aubergine, 16 bytes
-a1+a1=oA:bA=iB
The program has a trailing null byte. Works similarly to my hello world.
Muriel, 36 bytes
A:"\";.\"A:\\\"\"+|A+A";."A:\""+|A+A
Since Muriel isn't on TIO (yet!), I've included the interpreter in the link. Thanks Dennis!
Quines are the base component of any complex Muriel program, since they're a requirement for any sort of loop.
Explanation:
A: Assign to A
" ... "; An escaped version of ";."A:\""+|A+A
. Print
"A:\"" A:"
+|A Escaped version of A
+A Then A itself
Clean, 123 102 bytes
module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="
Save as q.icl and compile with -b -nt.
Saved 21 bytes thanks to Οurous.
Attache, 69 57 53 41 bytes
Printf[s:="Printf[s:=%s,Repr@s]",Repr@s]
Try it online! Surprised I didn't think of this sooner.
Print!Format[x:="Print!Format[x:=%s,Repr!x]",Repr!x]
In the end, the standard quine framework was most efficient :( . The 57-byter below is significantly more interesting.
BUT I found a cooler one, also for 53 bytes!
Print!Join[q:=["Print!Join[q:=", ",Repr!q]"],Repr!q]
57 bytes
Print!Format<~_,Repr!_~>["Print!Format<~_,Repr!_~>[%s]"]
This uses sneaky curried functions with blanks. When a function is called using
f<~...~> syntax, it denotes a curried function. _1 represents the first curried argument, _2 the second, etc. _ is an alias for _1, so this saves us some bytes without duplicating our string.
69 bytes
Save["Save[%c%s%c]Print[Format[_,34,_,34]]"]Print[Format[_,34,_,34]]
Try it online! The trailing newline is significant.
Explanation
Save updates the abstract variable _ with the string
"Save[%c%s%c]Print[Format[_,34,_,34]]"
Then, this string is formatted with the arguments _, 34, _, and 34. This prints the string, the character 34 (a quote), and then those two again, which is the program.
Alchemist, 720 657 637 589 bytes
-68 bytes thanks to Nitrodon!
0n0n->1032277495984410008473317482709082716834303381684254553200866249636990941488983666019900274253616457803823281618684411320510311142825913359041514338427283749993903272329405501755383456706244811330910671378512874952277131061822871205085764018650085866697830216n4+Out_"0n0n->"+Out_n4+nn+n0n
4n0+4n0+n->Out_"n"
n+n+4n0+n0+n0+n0->Out_"+"
n+n+n+4n0+n0+n0->Out_n
4n+4n0+n0->Out_"4"
4n+n+4n0->Out_"\""
4n+n+n+n0+n0+n0->Out_"->"
4n+n+n+n+n0+n0->Out_"\n"
4n+4n+n0->Out_"Out_"
4n+4n+n->Out_"\\"
nn->4n0+4n0+nnn
n0+n4->n
nnn+4n+4n+n4->nn+n00
nnn+0n4->n+n40
n40+0n00+n4->n4+nn
n40+0n+n00->n4+n40
Warning, takes far longer than the lifetime of the universe to execute, mostly cause we have to transfer that rather large number on the first line back and forth between multiple atoms repeatedly. Here's a version that outputs the first few lines in a reasonable amount of time.
Here is the encoder that turns the program into the data section
Everything but the large number on the first line is encoded using these 8 9 tokens:
0 n + -> " \n Out_ \ 4
That's why all the atom names are composed of just n,0 and 4.
As a bonus, this is now fully deterministic in what order the rules are executed.
Explanation:
Initialise the program
0n0n-> If no n0n atom (note we can't use _-> since _ isn't a token)
n4+Out_"0n0n->"+Out_n4+nn4+n0n
NUMn4 Create a really large number of n4 atoms
+Out_"0n0n->" Print the leading "0n0n->"
+Out_n4 Print the really large number
+nn Set the nn flag to start getting the next character
+n0n And prevent this rule from being called again
Divmod the number by 9 (nn and nnn flag)
nn->4n0+4n0+nnn Convert the nn flag to 8 n0 atoms and the nnn flag
n0+n4->n Convert n4+n0 atoms to an n atom
nnn+4n+4n+n4->nn+n00 When we're out of n0 atoms, move back to the nn flag
And increment the number of n00 atoms
nnn+0n4->n+n40 When we're out of n4 atoms, add another n atom and set the n40 flag
Convert the 9 possible states of the n0 and n atoms to a token and output it (nn flag)
n+4n0+4n0->Out_"n" 1n+8n0 -> 'n'
n+n+4n0+n0+n0+n0->Out_"+" 2n+7n0 -> '+'
n+n+n+4n0+n0+n0->Out_n 3n+6n0 -> '0'
4n+4n0+n0->Out_"4" 4n+5n0 -> '4'
4n+n+4n0->Out_"\"" 5n+4n0 -> '"'
4n+n+n+n0+n0+n0->Out_"->" 6n+3n0 -> '->'
4n+n+n+n+n0+n0->Out_"\n" 7n+2n0 -> '\n'
4n+4n+n0->Out_"Out_" 8n+1n0 -> 'Out_'
4n+4n+n->Out_"\\" 9n+0n0 -> '\'
Reset (n40 flag)
n40+0nn+n00->n4+n40 Convert all the n00 atoms back to n4 atoms
n40+0n00+n4->n4+nn Once we're out of n00 atoms set the nn flag to start the divmod
Gol><>, 8 7 6 bytes
"r2ssH
Hopefully this is not a previously used quine, I was messing around for another challenge having to do with quines, and I ended up creating this!
2nd program (the most recent), 7 bytes
":P}rH!
Courtesy of JoKing, who knocked an entire byte off the original!
1st program (the original), 8 bytes
":P&r&H!
I know this isn't the smallest, but it is my first quine in Gol><> (I did it entirely on my own!). Link to the interpreter in the title!
Code Breakdown
":P&r&H!
First, the " command collects all of the chars and rewraps around the program
Then the : command doubles the last symbol in the program, the !
Then this is incremented, and saved by the register
The stack is then reversed and the value is put back
Then the entire stack is outputted as characters and then the program halts
!@#$%^&*()_+, 76 bytes
40Kjiiiiiiiiiiij,306j,6641,iK31,i,6j,,!!_+!^!&(@^!&)++!_+%(!_^^^^^^^^^^^_@%)
The code can be decomposed into two sections: the data and the decoder. The data is this:
40Kjiiiiiiiiiiij,306j,6641,iK31,i,6j,,
Each character pushes itself, and corresponds to a command (shifted up by 11).
The decoder is this:
!!_+!^!&(@^!&)++!_+%(!_^^^^^^^^^^^_@%)
This can also be divided into two parts, one which prints the data raw, and one which decodes the data. This part prints the initial data segment:
!!_+!^!&(@^!&)++!_+%
!!_+ push 0 (duplicate twice then subtract)
this is our delineator
!^ push 1 (duplicate and increment)
this is our pointer
!& push the entry at that index in the stack
( ) until the dilineator is found:
@ output the stack entry
^ increment pointer
!& refresh entry at index
++!_+ pop top two (add twice, duplicate, subtract)
% push 0 underneath stack
Then the decoder:
(!_^^^^^^^^^^^_@%)
( %) For each character:
!_ _ subtract
^^^^^^^^^^^ 11
@ and output it
Tidy, 71 bytes
q:=34|chr|str;a:="q:=34|chr|str;a:=%swrite(a%%(q.a.q))"write(a%(q.a.q))
q:=34|chr|str gets a quote character, and a:=... defines the format string. Finally, write(a%(q.a.q)) formats a with a surrounded by quotes.
APL (Dyalog Unicode), 18 bytesSBCS
@ngn's updated version of the classic APL quine, using a modern operator to save four bytes.
1⌽,⍨9⍴'''1⌽,⍨9⍴'''
'''1⌽,⍨9⍴''' the characters '1⌽,⍨9⍴'
9⍴ cyclically reshape to shape 9; '1⌽,⍨9⍴''
,⍨ concatenation selfie; '1⌽,⍨9⍴'''1⌽,⍨9⍴''
1⌽ cyclically rotate one character to the left; 1⌽,⍨9⍴'''1⌽,⍨9⍴'''
Julia 1.0, 32 bytes
".|>[show,print]".|>[show,print]
And here is a 35 byte quine that works in version 0.4 (And beats the previous answer):
x = "print(@show x)"
print(@show x)
Symbolic Python, 30 bytes
_="_='_='+`_`+';__(_)'";__(_)
Yet another eval quine. The lack of being able to do %r in Symbolic Python is made up for Python 2's backticks, which are an alias for the repr function.
Explanation:
_=" "; # Assign the string to the _ variable
__(_) # Eval the string
_= # Assign to the _ variable
'_=' # The initial _=
+`_` # The Python representation of the string
+';__(_)' # And the final evaling part
# Implicitly output the contents of _
An alternative that doesn't use the rather long eval function comes to 31 bytes, but I actually like it more.
_=';_="_="+`_`+_';_="_="+`_`+_
Perl 6, 31 27 bytes
<"<$_>~~.EVAL".say>~~.EVAL
No messing about with alternative q quotes or .perl, just <> and a good ol' EVAL quine.
Explanation:
< > # Create a list of
"<$_>~~.EVAL".say # The string '"<$_>~~.EVAL".say'
~~ # Smartmatch the list by setting $_ to it
.EVAL # Evaluate the string as code
"<$_>~~.EVAL" # Interpolate the $_ list into the string
.say # And print it with a newline
Whitespace, 406 bytes
DISCLAIMER: This quine was not created by me, it is created by Smithers. Because this challenge was missing a Whitespace answer I decided to post his/her. If Smithers reads this and wants to post it himself/herself I will of course delete my answer.
Sources: Smithers' website and his/her Whitespace quine source code (note: it's missing a trailing new-line).
[S S S T S S T S T T T T T S T T T S S T T S S S T S T T S T T T T T T T S T S S S T S S T S S T S T T T T T S T S T S S S T T T S S T S T T S S S S T T T T T T S S T T T S T S T S S S T T T S S S S S S S T T T T T T T S T S S T S S S T S T T T T S S S S S T S T S S S T S T T S T S S S T S S T S S T T T S S S S S S S T T S T S S T T T T T S S S T T T T S S T T S T T S S T S T T T T S S S S T T S S T T T T S T S S T T S S T S S T T S S S S T T S S T T S S T S S T T S T S T S T T S S S T T S T S N
_Push_67079405567184005086107571748115383207539763039497665210559156555730234138][S N
S _Duplicate][N
S T S N
_Call_Label_PRINT_SPACE][N
S T S N
_Call_Label_PRINT_SPACE][S S S T S N
_Push_2][S N
T _Swap][N
S T N
_Call_Label_RECURSIVE_PRINTER][S S S T S T S N
_Push_10][T N
S S _Print_as_char][S N
N
_Drop][S S S T T N
_Push_3][S N
T _Swap][N
S T N
_Call_Label_RECURSIVE_PRINTER][N
N
N
_Exit][N
S S N
_Create_Label_RECURSIVE_PRINTER][S N
S _Duplicate][N
T S T N
_If_0_Jump_to_Label_DISCARD_TOP(_AND_PRINT_SPACE)][S T S S T N
_Copy_1][S T S S T N
_Copy_1][S T S S T N
_Copy_1][T S T S _integer_divide][N
S T N
_Call_Label_RECURSIVE_PRINTER][T S T T _Modulo][S N
S _Duplicate][N
T S T N
_If_0_Jump_to_Label_DISCARD_TOP(_AND_PRINT_SPACE)][S S S T S S S N
_Push_8][T S S S _Add][T N
S S _Print_as_character][N
T N
_Return][N
S S T N
_Create_Label_DISCARD_TOP(_AND_PRINT_SPACE)][S N
N
_Discard][N
S S S N
_Create_Label_PRINT_SPACE][S S S T S S S S S N
_Push_32][T N
S S _Print_as_character][N
T N
_Return]
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Whitespace is a stack-based language only using three characters: spaces, tabs and new-lines. In Whitespace the stack can only contain integers, and there are two options to print something to STDOUT: "Print as number" and "Print as character". In the case of "Print as character" it will print the character based on the unicode value at the top of the stack. Because whitespace uses spaces, tabs and new-lines, it means it'll have to print numbers 32, 9, and 10 respectively as characters to STDOUT for this quine.
Smithers uses a pretty ingenieus piece of code with the magic number (s)he found.
Pseudo-code:
Push 67079405567184005086107571748115383207539763039497665210559156555730234138
Duplicate top
Call function_PRINT_SPACE
Call function_PRINT_SPACE
Push 2
Swap top two
Call function_RECURSIVE_PRINTER
Push 10
Pop and print top as character
Discard top
Push 3
Swap top two
Call function_RECURSIVE_PRINTER
Exit program
function_RECURSIVE_PRINTER:
Duplicate top
If 0: Call function_DISCARD_TOP(_AND_PRINT_SPACE)
Make a copy of the 2nd top item of the stack
Make a copy of the 2nd top item of the stack
Make a copy of the 2nd top item of the stack
Integer-divide top two
Call function_RECURSIVE_PRINTER
Modulo top two
Duplicate top
If 0: Call function_DISCARD_TOP(_AND_PRINT_SPACE)
Push 8
Add top two
Pop and print top as character
Return
function_DISCARD_TOP(_AND_PRINT_SPACE):
Discard top
function_PRINT_SPACE:
Push 32
Pop and print top as character
Return
It first uses a recursive-loop which keeps integer-dividing the initial integer by 2 until it's 0. Once it's 0, it goes back over these values and does modulo-2, printing either a space (if the modulo-2 resulted in 0) or a tab (by adding 8 to the modulo-2 result of 1). This first part is used to print the magic number itself, which only consists of spaces and tabs, because pushing a number in Whitespace is done as follows (and thus doesn't contain any new-lines except for the single trailing one):
S: Enable Stack ManipulationS: Push a numberS/T: Positive/Negative respectively- Some
S/T, followed by a trailingN: The number as binary, whereS=0andT=1
After it has printed the spaces and tabs required for pushing the magic number itself, it pushes a 3 and will use the same recursive function with the magic number, integer-dividing and using modulo 3 instead of 2. Which will print the spaces (if the modulo-3 resulted in 0), or tabs/new-lines (by adding 8 to the modulo-3 result).
MathGolf, 9 bytes
ÿ_'ÿ¬_'ÿ¬
Explanation:
ÿ_'ÿ¬_'ÿ¬
ÿ Start string of length 4
_'ÿ¬ Push "_'ÿ¬"
_ Duplicate it
'ÿ Push the character "ÿ"
¬ Rotate stack so the "ÿ" is at the bottom
Implicitly output "ÿ", "_'ÿ¬", "_'ÿ¬" join together
Runic Enchantments, 7 bytes
"'<~S@|
Explanation
< Entry
"' Push the " character (loop around)
| Mirror (loop around)
" Begin string mode
'<~S@| Push the string '<~S@|
" End string mode
'<~ Push and pop a < character
S Swap stack the following also work, r: reverse, q: concatenate, +: add
@ Print and terminate
Pascal (FPC), 103 bytes
const s=#39'const s=#39;begin write(s[2..12],s,s[10..50])end.'#39;begin write(s[2..12],s,s[10..50])end.
s is the string that the output is generated from. In Pascal, subtrings can be easily extracted with [from..to] syntax. #39 is replacement for ' using its ASCII codepoint. As seen in this program, sequences of character codepoints can be glued together with the rest of the string delimited with 's at any time. s consists of characters before and after 's concatenated together. #39 occurs immediately before first ' and after second ' so it can be put in s only once and used in both substrings in the output.
The version that may be more suitable in modified, quine-like programs is at 106 bytes:
const s='const s=;begin write(s[1..8],#39,s,#39,s[9..52])end.';begin write(s[1..8],#39,s,#39,s[9..52])end.
Runic Enchantments, 7 6 bytes
"'<~@>
Huh, a multiple pointer quine actually works pretty well.
Explanation:
"'<~@>
< > Start pointers going left and right
"'< Left pointer pushes " to their stack
@ And terminate the IP, printing the stack (")
> Right pointer wraps around
" Start string literal
'<~@> Push as string
" End string literal
'<~ Push the < character, but pop it
@ Terminate the IP, printing the stack ('<~@>)
End the program as there are no IPs left
Edit: I realised you can replicate this with only one pointer
'<~@|"
Elixir, 44 bytes
q=:'q=:~p;:io.format q,[q]';:io.format q,[q]
This is basically an existing quine taken from here, but I managed to save another 2 bytes by declaring q as an atom instead of a binary.
Backhand, 21 bytes
"#v{<@^:[ba+0v|{$:o[}
This is my new 1D language Backhand. It's a little bit more complicated than the typical wrapping string literal quine.
Explanation:
The program initially starts with a step count of 3.
" Start string literal, stepping 3 places at a time
This pushes the source code, but all jumbled up :(
See my Hello, World! answer to see what you have to do to push a string normally.
" End the garbage string literal
v{ Step left and decrease the step count to 2
< Change direction to left
v Decrease the step count to 1
# No-op
" Start string literal
Now the step count is 1, so it actually pushes the source code
#v{<@^:[ba+0v|{$:o[} Push to stack going right and bounce off the end
#v{<@^:[ba+0v|{$:o[ Push to stack going left
" End string literal
v Decrease the step count to 0
v Decrease the step count to -1
Now the pointer is technically going right, but with a step count of -1
" Push the source code again...
v Decrease the step count to -2
< Change direction to left (step count is still negative, so it goes right)
^ Increase step count to -1
:[ Dupe the top of stack (# 35) and decrement to 34 (")
ba+ Add 10 and 11 to push 21 as the counter
0 Push 0
v Decrease step count to -2
{ Step left
| Pop 0 and continue moving left
$ o Swap the top two items and print the character
[} Step right (against the wall so it bounces) and decrement the counter
|{ : Duplicate the counter and reflect if it is non-zero
Repeat this 21 times to print the source code
[ a 0 Garbage
^ Increase the step counter to -1
@ Terminate program
Flobnar, 94 bytes
9 f; /*+{ ;{?06 0/9^[]={o) *4_;= 9);];36
:
g<
0+,|!<|@17
10:_\^>|p*
+5`<>
:*< ^ <47!!!
There's some debate over whether the get instruction counts as reading the source code, but in this case, I'm not using it to read the executed code, but a data array on the first line (except for specifically reusing just the 9 character).
This reads and prints the data section, then reads and prints each character incremented by one to represent the code section.
Explanation:
.
..
.....<|@.. Start at the @ going left
.......... We use the | to evaluate the code beyond it and come back here
.....
.............
:
g<
0+,|!<.... Print the character on the first line at position n plus 0
.0........ Then go down from the |
.....
.............
.9
.
..
...|!.....
..:_...... If n > 5*9 then go left at the _ and return !n
.5`<.
.*<..........
.
..
...|!<.... Else go right and increment n
1.._\^.... And loop again
+...>
:............
.
.. Once we've ended the loop we come back to the original | going down
.....<|.17 And we put a 1 at the (1,4) position and repeat the main code again
.1....>|p* This time adding 1 to each character
.....
.....^ <47...
J (REPL) - 20 (16?) char
Seems we're missing a J entry. Trivially, any sentence that doesn't evaluate gets itself printed in the REPL, so 1 or + or +/ % # are all quines in that sense. A non-trivial quine would be one that produces specifically a string containing the source code.
',~@,~u:39',~@,~u:39
u:39 is the ASCII character 39, i.e. the single quote, and ',~@,~u:39' is a string. , is the append verb. The main verb ,~@,~ evaluates as follows:
x ,~@,~ y
y ,~@, x NB. x f~ y => y f x "Passive"
,~ (y , x) NB. x f@g y => f (x g y) "At"
(y,x) , (y,x) NB. f~ y => y f y "Reflex"
So the result is 'string'string when x is string and y is the single quote, and thus this is a quine when x is ,~@,~u:39.
If we're allowed the J standard library as well, then we can write the 16 character
(,quote)'(,quote)'
which appends the quote of the string (,quote) to itself.
J, 27 bytes
echo(,quote)'echo(,quote)'
It's surprising that there's no proper J quine submission yet.
How it works
echo(,quote)'echo(,quote)'
'echo(,quote)' The string `s`
quote Wrap `s` with single quotes
, Concat s to the above; `(f g)x` is equal to `x f g x`
echo Explicitly print the result
echo is needed because the result of a non-REPL line is not printed.
Cardinal, 10 bytes
",-#) %8-$
This should be a quine, except for a small bug in the interpreter which causes the Bug is fixed, yay!( command to throw an error. For completeness' sake, here's a version where a # is placed in the position the ( is accidentally calling. Note that the space is actually a NUL character.
"% (#-,0-$ also works with just one pointer.
How It Works:
The % creates two pointers, going left and right (the ones going vertical don't matter). The right pointer is delayed by the 8 for three steps, which lets the left pointer execute ,-#) which changes the active value to #, decrements it and prints the ". Then the right pointer starts again, decrementing the active value to -1. $ sets the pointer location to 0,-1, which then runs " over the rest of the code, printing it.
Excel, 17 Bytes
In cell A1...
=FunctionText(A1)
I discovered this yesterday by accident. Feels a bit cheaty somehow though. I appreciate this answer much more, but this does seem to be a quine :D
Z80Golf, 120 bytes
00000000: 21f5 76e5 2180 10e5 21cd 00e5 2180 7ce5 !.v.!...!...!.|.
00000010: 21cd 00e5 21e1 7de5 2106 14e5 2110 e8e5 !...!.}.!...!...
00000020: 2100 80e5 21e5 cde5 211b 3ee5 2100 80e5 !...!...!.>.!...
00000030: 211a cde5 2180 13e5 21cd 00e5 211b 1ae5 !...!...!...!...
00000040: 2180 1be5 21cd 00e5 213e 21e5 2106 14e5 !...!...!>!.!...
00000050: 0614 3e21 cd00 801b 1b1a cd00 8013 1acd ..>!............
00000060: 0080 1b3e e5cd 0080 10e8 0614 e17d cd00 ...>.........}..
00000070: 807c cd00 8010 f576 .|.....v
Verification:
$ ./z80golf a.bin | xxd
00000000: 21f5 76e5 2180 10e5 21cd 00e5 2180 7ce5 !.v.!...!...!.|.
00000010: 21cd 00e5 21e1 7de5 2106 14e5 2110 e8e5 !...!.}.!...!...
00000020: 2100 80e5 21e5 cde5 211b 3ee5 2100 80e5 !...!...!.>.!...
00000030: 211a cde5 2180 13e5 21cd 00e5 211b 1ae5 !...!...!...!...
00000040: 2180 1be5 21cd 00e5 213e 21e5 2106 14e5 !...!...!>!.!...
00000050: 0614 3e21 cd00 801b 1b1a cd00 8013 1acd ..>!............
00000060: 0080 1b3e e5cd 0080 10e8 0614 e17d cd00 ...>.........}..
00000070: 807c cd00 8010 f576 .|.....v
$ ./z80golf a.bin | diff -s a.bin -
Files a.bin and - are identical
Looks like no one tried to make a proper quine in machine code yet, so here is one.
Although the machine code is loaded to memory, it does NOT read any address occupied by the code. Instead, it uses the stack space to setup required data.
Disassembly
start:
ld hl, $76f5
push hl
ld hl, $1080
push hl
ld hl, $00cd
push hl
ld hl, $7c80
push hl
ld hl, $00cd
push hl
ld hl, $7de1
push hl
ld hl, $1406
push hl
ld hl, $e810
push hl
ld hl, $8000
push hl
ld hl, $cde5
push hl
ld hl, $3e1b
push hl
ld hl, $8000
push hl
ld hl, $cd1a
push hl
ld hl, $1380
push hl
ld hl, $00cd
push hl
ld hl, $1a1b
push hl
ld hl, $1b80
push hl
ld hl, $00cd
push hl
ld hl, $213e
push hl
ld hl, $1406
push hl
ld b, 20
loop1:
ld a, $21
call $8000
dec de
dec de
ld a, (de)
call $8000
inc de
ld a, (de)
call $8000
dec de
ld a, $e5
call $8000
djnz loop1
ld b, 20
loop2:
pop hl
ld a, l
call $8000
ld a, h
call $8000
djnz loop2
halt
At start, the stack pointer sp is zero, just like other registers. Pushing some values causes sp to decrease, so the values are stacked in the memory region $ffxx.
The combination ld hl, $xxxx and push hl seems like the best option to dump predefined values into some memory space. It takes 4 bytes to store 2 bytes; any other option I could think of uses 3 or more bytes to store only one byte.
The first loop prints the ld hl, $xxxx (21 xx xx) and push hl (e5) instructions for the data, from the bottom of the stack (the address, represented by de, is decreased starting from $0000).
ld b, $xx and djnz label combined forms a fixed-times looping construct. It is only 4 bytes, which is optimal in Z80 (unless the loop count is already saved in another register).
But there is an endianness problem here, so simply sweeping the memory addresses in decreasing order does not work. So I had to add a pair of dec de and inc de at the cost of 2 bytes (plus 4 bytes to push the 2 bytes into the stack).
The second loop prints the main code by popping data from the stack.
Possible improvement ideas
Since the code is longer than $38 or 56 bytes, we can't use rst $38 in place of call $8000. Having call $8000 6 times in total, it's a great opportunity for golf. I considered placing call $8000; ret at address $38, but then I have to reduce the main code into 26 bytes or lower.
I also thought of moving the code to the front by adding some jr, so that I can embed the call $8000; ret in the code part. But then I can't use the efficient "pop and print" loop. It prints the data in reverse order of pushing, so it can't be used to print the push part; the "print" overwrites the stack with the return address, so it can't be used to print the first part either.
Finally, there is room for alternative encoding since some bytes frequently appear in the code. But Z80 itself is severely limited in arithmetic...
Noether, 30 bytes
"~a34BPaP34BPaP"~a34BPaP34BPaP
Basically, this works by pushing the string and storing it in the variable a, printing quotation marks (34B where B pushes the character with ASCII code 34) then printing a twice.
2DFuck, 1352 1289 bytes
!xv>>>>x>x>>>>>>x>x>x>x>>x>x>x>>x>x>>x>x>x>x>x>>x>x>>x>x>>x>x>x>x>x>>x>x>x>x>x>>x>x>x>x>>x>x>>x>x>x>>x>x>>x>>>x>>>>>>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>x>x>>>>>x>>>x>>>x>x>>x>x>x>x>x>>x>x>x>x>>>x>x>x>x>>x>x>x>x>x>x>>x>x>>>>>>>>>>x>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>x>x>>>>>x>>>x>>>x>x>x>>x>x>>x>x>>x>x>x>x>>x>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>x>x>x>>x>x>>x>x>x>x>x>>x>x>>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>x>>x>x>>x>x>>x>>>x>x>>>>x>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>>x>x>>x>x>x>>x>>>x>x>>>>>x>>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>x>x>>x>x>x>>x>x>>x>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>x>>x>x>x>x>x>x>>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>x>>x>x>x>x>x>>x>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>x>x>>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>x>x>x>>x>x>x>x>>>x>x>>>>x>>x>>>x>>>x>x>>x>x>x>x>>x>x>>x>x>x>>x>x>>>x>x>>>x>x>>>x>x>>>x>x>>>x>x>>>>>x>>>>x>x>>>>>>>>x>x>>>x>x>>>>>>>>>>x>x>>>>>x>>x>>>x>x>^x!..!.!....!.!.!....!....!...!.!..!.![<r!]![vr[!.!....!...]..!.....!.>^r!]![<r!]![vr[!..!.!.!...!.]r![>r[!..!.!....!.!]r![>r[>r[!.!.!.!...!.!.!]r![!.!.!.!..!.!..!]<]r![>r[!.!...!..!.!.]r![>r![!..!.....!.]r[>r![!..!....!..]r[>r![!.!.!.!....!.]r[>r[!.!....!...]r![!.!...!.!..!.]]]]]<]>]]>^r!]
Shaved off 63 bytes with Huffman coding! New explanation in progress.
Yabasic, 103 bytes
An anonymous Yabasic quine
c$=Chr$(34):q$="c$=Chr$(34):q$=:?Left$(q$,15)+c$+q$+c$+Mid$(q$,16)":?Left$(q$,15)+c$+q$+c$+Mid$(q$,16)
Includes a trailing newline
VBA, 77 bytes
An anonymous VBE immediate window quine.
c=Chr(34):q="c=Chr(34):q=:?Replace(q,Chr(7),c+q+c)":?Replace(q,Chr(7),c+q+c)
Foo, 136 111 96 bytes
I'm surprised to see that there's no Foo quine here yet!
>&41>&60>&99>&36>&40>&60>&41>&62>&105>&36>&34>&38>&62>&34>&40>&62>&41>&60>&40(<)>(">&"$i>)<($c<)
Explanation
This is pretty simple as far as quines go. There are two sections: the data and the decoder. The data is encoded on the array, and is decoded as such:
(<)>(">&"$i>)<($c<)
Which basically iterates once over the tape, outputting >& and the integer value of the cell, then iterating once again over the tape, outputting each character. The tape, then, is just the character codes of this decoder.
Javascript REPL, 21 bytes
(_=$=>`(_=${_})()`)()
MATL, 12 bytes
'&DtU'
&DtU
(the code has a trailing newline).
Explanation
'&DtU' % Push this string
&D % String representation (adds quote marks)
t % Duplicate
U % Evaluate (removes quote marks)
% Implicitly display each string followed by a newline
Shakespeare Programming Language, 327718 292629 bytes
That's about 286 KiB, not 3 MiB.
Because the source code itself is too big, run this Bash program to generate the quine in quine.spl file. Expect .input.tio file to be the input in the TIO link.
cat << 'eof' > convert.ijs
9!:37 (0 _ _ _)
f =: (('the sum ofa cat ' #~ 2&|) , 'twice ' , [: f <.@%&2) ` ('zero'"_) @. (=&0)
g =: ([: toupper 'remember ' , f , '!'"_)"0
inp =: stdin''
inp =: toupper inp rplc LF;' ';'!';'.'
out =: 'LET USSCENE D.' ,~ ; <@g 0, |. -&31 a. i. inp
NB. echo # out
echo out
exit ''
eof
cp .input.tio quine.spl
/opt/j/bin/jconsole convert.ijs < .input.tio | tr -d '\n' >> quine.spl
wc -c quine.spl
/opt/spl/spl2c < quine.spl > quine.spl.c 2> /dev/null
gcc -c -I /opt/spl -o quine.spl.o quine.spl.c
gcc -lm -o quine quine.spl.o /opt/spl/libspl.a
./quine < /dev/null > quine.spl.out
wc -c quine.spl.out
diff quine.spl quine.spl.out
The content of the .input.tio file should be:
T.AJAX,.PAGE,.ACT I:.SCENE I:.[ENTER AJAX AND PAGE]AJAX:LET USSCENE II.SCENE D:.PAGE:REMEMBER A PIG.SCENE C:.AJAX:RECALL.PAGE:REMEMBER I.AJAX:BE YOU NICER ZERO?IF NOTLET USSCENE M.YOU BE THE SUM OFA PIG THE SUM OF A BIG BIG BIG BIG BIG CAT YOU.SPEAK THY.LET USSCENE C.SCENE M:.PAGE:RECALL.BE YOU WORSE ZERO?IF SOLET USSCENE IX.AJAX:YOU BE THE SUM OFTHE SQUARE OFTHE SUM OFA BIG BIG BIG CAT A CAT A CAT.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA BIG BIG CAT A CAT THE CUBE OFA BIG BIG CAT.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG CAT YOU.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG PIG YOU.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG CAT YOU.SPEAK THY.YOU BE THE SUM OFTHE CUBE OFA BIG BIG CAT A BIG CAT.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA CAT YOU A BIG CAT.SPEAK THY.YOU BE THE SUM OFTHE SQUARE ROOT OFTWICE YOU THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE A BIG BIG BIG BIG BIG CAT.SPEAK THY.SCENE V:.PAGE:BE YOU NICER ZERO?IF NOTLET USSCENE X.AJAX:YOU BE THE QUOTIENT BETWEENI A BIG CAT.REMEMBER YOU.BE I NICER TWICE YOU?IF NOTLET USSCENE L.YOU BIG BIG BIG BIG BIG CAT.PAGE:YOU BE TWICE THE SUM OFTWICE THE SQUARE ROOT OFI I.SPEAK THY.YOU BE TWICE THE SUM OFA BIG BIG CAT I.SPEAK THY.YOU BE THE SUM OFTHE SQUARE ROOT OFI TWICE I.SPEAK THY.AJAX:SPEAK THY.PAGE:YOU BE THE SQUARE ROOT OFTHE PRODUCT OFTHE SUM OFYOU I YOU.SPEAK THY.YOU BE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG PIG YOU.SPEAK THY.AJAX:SPEAK THY.PAGE:YOU BE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE TWICE THE SUM OFTHE SUM OFA CAT I A BIG CAT.SPEAK THY.YOU BE THE SUM OFTWICE I A CAT.SPEAK THY.AJAX:SPEAK THY.PAGE:YOU BE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE THE SUM OFTWICE I A CAT.SPEAK THY.YOU BE TWICE THE SUM OFTWICE THE SQUARE ROOT OFI I.SPEAK THY.AJAX:SPEAK THY.SCENE L:.PAGE:YOU BIG BIG BIG CAT.AJAX:YOU BE TWICE THE SUM OFTWICE THE SUM OFTWICE I A CAT I.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA CAT YOU A BIG CAT.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA CAT I THE SQUARE OFI.SPEAK THY.YOU BE THE SUM OFTWICE THE SUM OFA BIG PIG A PIG YOU.SPEAK THY.YOU BE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE TWICE TWICE I.SPEAK THY.RECALL.PAGE:YOU BE I.LET USSCENE V.SCENE X:.PAGE:YOU BIG BIG BIG BIG CAT.AJAX:YOU BE THE SQUARE ROOT OFTWICE THE CUBE OFI.SPEAK THY.YOU BE THE SUM OFTWICE TWICE THE SUM OFA CAT I A CAT.SPEAK THY.YOU BE THE SUM OFTWICE THE SUM OFTWICE I A CAT I.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA PIG YOU A BIG PIG.SPEAK THY.YOU BE THE SUM OFTWICE I A CAT.SPEAK THY.LET USSCENE M.SCENE IX:.PAGE:YOU BE TWICE TWICE THE SUM OFTWICE THE SUM OFA BIG BIG BIG CAT A CAT A CAT.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA CAT YOU A BIG BIG BIG PIG.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG BIG CAT THE SUM OFA PIG YOU.SPEAK THY.YOU BE A BIG BIG BIG BIG BIG CAT.SPEAK THY.YOU BE THE SUM OFTWICE THE SUM OFTWICE THE SQUARE ROOT OFYOU YOU A CAT.SPEAK THY.YOU BE THE SUM OFA BIG PIG YOU.SPEAK THY.YOU BE YOU.SPEAK THY.YOU BE THE SUM OFA BIG BIG BIG BIG PIG YOU.SPEAK THY.YOU BE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA CAT YOU A BIG BIG BIG CAT.SPEAK THY.YOU BE THE SUM OFTHE SUM OFA PIG YOU A BIG BIG BIG PIG.SPEAK THY.YOU BE A BIG BIG BIG BIG BIG CAT.SPEAK THY.YOU BE TWICE THE SUM OFA BIG CAT YOU.SPEAK THY.YOU BE TWICE THE SQUARE ROOT OFTWICE TWICE TWICE YOU.SPEAK THY.RECALL.SCENE II:.AJAX:
which is also the first part of the quine program. The second part is the first part converted through the convert.ijs J script written above.
The constant generation part needs a lot more work.
Each byte in the source code is encoded by:
REMEMBER <repr(value - 31)>.
where:
repr(0) = 'ZERO'
repr(2 * x + 1) = 'THE SUM OFA CAT ' + repr(2 * x)
repr(2 * x) = 'TWICE ' + repr(x)
with integral x.
Gol><>, 6 5 bytes
sP#H"
Credit to Jo King.
How it works
sP#H"
s +16
P +1
# Reverse direction
P +1
s +16
" Start string literal
sP#H" Push H, #, P, s and end string literal
H Print everything on the stack from the top, and halt
The printed chars are s, P, #, H, 34 (")
Previous solution, 6 bytes
"r2ssH
How it works
"r2ssH Push the string "r2ssH" to stack, "r" being at the bottom
" Close the literal
r Reverse the stack
2ss Push 34 (")
H Print all content of the stack from top to bottom as chars, and halt
There were a couple of alternatives to consider:
S"prints the string right away (instead of pushing to stack), but then it gets harder to handle".`"is an alternative way to push 34 to the stack, but the string literal also treats`"as escaped"which is not desirable.
Nim, 95 bytes
import strutils;let s="import strutils;let s=$#;echo s%s.repr[^49..^1]";echo s%s.repr[^49..^1]
After scrolling through the leaderboard snippet, I was surprised to see that Nim hasn't been represented here yet. So, let's fix it!
This follows the standard pattern of constructing and printing a string with a quoted representation of itself inserted in the middle. Unfortunately, Nim has a few features that make this golf-unfriendly:
- String interpolation with
%is not available unless youimport strutils. reprnot only quotes strings, but also prepends them with a hex number (seemingly, memory address), like this:0x40a6d0"my string". Therefore, we have to extract the right part.
Still, not so bad overall, as it is significantly shorter than the version currently posted at Rosetta Code, which actually doesn't even work without tweaks in recent versions of the language.
Befunge-93, 25 22 bytes
-2*6<>:#,_@#:-5: _-p<"
Thanks to jimmy23013's answer for inspiring the idea to create the " before the wrapping string literal.
Previous answers have usually relied on non-standard interpreter behaviour in order to wrap a string literal around the code and avoid the extra spaces. My quine however, is compliant with Befunge-93 specs.
Befunge-93 has a bounding box of 80x25 cells, which are initially filled with spaces. This means the wrapping string literal, a staple of 2D quines, usually fills the stack with a lot of excess spaces.
How It Works:
-2*6< Create the " character
" Start the wrapping string literal
_-p< Pop all the spaces until there are none left
Note that p is the put command, which basically pops 3 items from the stack
:-5: Dupe the 2 and subtract 5 to replace the - that was destroyed
Dupe that again to compensate for the _
>:#,_@# Print until stack is empty and terminate
Alternatively:
++9*5<>:#,_@#::_$#-< "
also works for 22 bytes.
Reflections, 4222 bytes
Since wastl out-golfed me by about... 1.810371 bytes through a vastly superior encoding system, I've decided to have another look at the problem. Since my program is still quite long, here's the main section (with SOHs replaced with spaces):
\0=0#_(4:(2(4(40\
/# 0v\/(1v/
\+#@~ > ~<
/#@#_#_#_1^1/
+
\#1)(2:2)4=/
Try It Online! (but have patience) (ASCII-only points out that unchecking the time between steps will make it go faster, but beware of the javascript freezing up your browser)
This uses the same encoding as wastl's answer, where each character with byte value n is represented by n newlines followed by
+
#
and the first character of the code is \ to change the pointer's direction down. Additionally, it also encodes the \ as well as the #,+ and newline in this process to save on doing them later
The main code is a more streamlined version of wastl's, where quite a few shortcuts have been made. I've also replaced all the spaces with SOHs (byte value 1) to save on bytes.
Detailed explanation
\0=0 Create a copy of the data in stack 0
#_ Print the `\`
(4:(2(4(4 Push the +, \n, # to stack 4, and a copy of the newline to stack 2
0\ Switch back to the intact copy of the data
/(1v/ Reverse the data
> ~<
^1/
v\
~ While the stack exists
^
v\
1 Move data to stack 1
4=/ Copy #, \n, +
(2:2) Copy newline
\#1) Get top of data
+
\# Redefine origin and move up
/
+ Push -2
/#@ Print the newline the value of the top of data times
#_#_#_ Print the +, \n, #
1^ Switch back to the data and loop again
/# 0v When the data stack is empty
\+#@~
/#@#_#_#_1^
0 Switch to the other copy of the data
/# Redefine the origin to push 1
\+
#@ Print the whole stack
~ > And end
Reflections, 9228 bytes
As the program has 8620 lines, I won't put it here completely.
First line:
\
Then, for each character in the last part (below), there are n newlines for ASCII character n, followed by:
+
#
After it, the last part is (the # is actually already covered by the previous section):
# / \ /+\ /#_=0v\
>~ < /(1:1)#@/ ~
\(0/ 2) \3)(2:2)(3^ 0#+#@
\:(24):(4#_#_#_ /
+ \* (4\
\*(1(2 +/
Working on explanation.
I had to fix a bug in the interpreter for this one. Does that count as adding a feature just for a challenge?
PHP, 147 bytes
<?php $c= <<<'s'
$n='<?php $c= <<<\'s\''."\n";global $c;echo($n.$c."\ns;\n".'$e=create_function("",$c);$e();');
s;
$e=create_function("",$c);$e();
Fueue, 423 bytes
Fueue is a queue-based esolang in which the running program is the queue.
)$$4255%%1(~):[)$$24%%0:<[~:)~)]~[$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]](H-):~:[)[):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):]~:](106328966328112328136317639696111819119696281563139628116326221310190661962811611211962861109696289611619628116111612896281115421063633063961111116163963011632811111819159628151213262722151522061361613096119619190661966311961128966130281807072220060611612811961019070723232022060611
How it works
This explanation may or may not have got way out of hand. On the other hand I don't know how to explain it much shorter in a way I hope people can follow.
Fueue cheat sheet
See esolang wiki article for details, including the few features not used in this program.
The initial program is the initial state of the queue, which can contain the following elements:
- Integer literals (only non-negative in the source, but negative ones can be calculated), executing them prints a character.
- Square-bracket delimited nested blocks, inert (preserved intact unless some function acts upon them).
- Functions, their arguments are the elements following them immediately in the queue:
+*/-%: integer arithmetic (-is unary,%logical negation). Inert if not given number arguments.()<: put element in brackets, remove brackets from block, add final element to block. The latter two are inert unless followed by a block.~:: swap, duplicate.$: copy (takes number + element). Inert before non-number.H: halt program.
Note that while
[]nest,()don't - the latter are simply separate functions.
Execution trace syntax
Whitespace is optional in Fueue, except between numerals. In the following execution traces it will be used to suggest program structure, in particular:
- When a function executes, it and its arguments will be set off from the surrounding elements with spaces. If some of the arguments are complicated, there may be a space between them as well.
- Many execution traces are divided into a "delay blob" on the left, separated from a part to the right that does the substantial data manipulation. See next section.
Curly brackets {} (not used in Fueue) are used in the traces to represent the integer result of mathematical expressions. This includes negative numbers, as Fueue has only non-negative literals – - is the negation function.
Various metavariable names and ... are used to denote values and abbreviations.
Delaying tactics
Intuitively, execution cycles around the queue, partially modifying what it passes through. The results of a function cannot be acted on again until the next cycle. Different parts of the program effectively evolve in parallel as long as they don't interact.
As a result, a lot of the code is devoted to synchronization, in particular to delaying execution of parts of the program until the right time. There are a lot of options for golfing this, which tends to turn those parts into unreadable blobs that can only be understood by tracing their execution cycle by cycle.
These tactics won't always be individually mentioned in the below:
)[A]delaysAfor a cycle. (Probably the easiest and most readable method.)~efswaps the elementseandfwhich also delays their execution. (Probably the least readable, but often shortest for minor delays.)$1edelays a single elemente.-and%are useful for delaying numbers (the latter for0and1.)- When delaying several equal elements in a row,
:or$can be used to create them from a single one. (nwrapsnin brackets, which may later be removed at convenience. This is particularly vital for numeric calculations, since numbers are too unstable to even be copied without first putting them in a block.
Overall structure
The rest of the explanation is divided into seven parts, each for a section of the running program. The larger cycles after which most of them repeat themselves will be called "iterations" to distinguish them from the "cycles" of single passes through the entire queue.
Here is how the initial program is divided between them:
A: )$$4255%%1(~
B: ):[)$$24%%0:<[~:)~)]~[$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]]
C:
D: (H-
E:
F:
G: ):~:[)[):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):]~:](106328966328112328136317639696111819119696281563139628116326221310190661962811611211962861109696289611619628116111612896281115421063633063961111116163963011632811111819159628151213262722151522061361613096119619190661966311961128966130281807072220060611612811961019070723232022060611
The big numeral at the end of the program encodes the rest in reverse, two digits per character, with 30 subtracted from each ASCII value (so e.g. 10 encodes a (.)
On a higher level you can think of the data in this program (starting with the bignum) as flowing from right to left, but control flowing from left to right. However, at a lower level Fueue muddles the distinction between code and data all the time.
- Section G decodes the bignum into ASCII digits (e.g. digit
0as the integer48), splitting off the least significant digits first. It produces one digit every 15 cycles. - Section F contains the produced digit ASCII values (each inside a block) until section E can consume them.
- Section E handles the produced digits two at a time, pairing them up into blocks of the form
[x[y]], also printing the encoded character of each pair. - Section D consists of a deeply nested block gradually constructed from the
[x[y]]blocks in such a way that once it contains all digits, it can be run to print all of them, then halt the entire program. - Section C handles the construction of section D, and also recreates section E.
- Section B recreates section C as well as itself every 30 cycles.
- Section A counts down cycles until the last iteration of the other sections. Then it aborts section B and runs section D.
Section A
Section A handles scheduling the end of the program.
It takes 4258 cycles to reduce to a single swap function ~, which then makes an adjustment to section B that stops its main loop and starts running section D instead.
)$ $4255% %1 (~
)$%%%...%% %0 [~]
)$%%%...% %1 [~]
⋮
)$ %0 [~]
) $1[~]
)[~]
~
- A
$function creates 4255 copies of the following%while the(wraps the~in brackets. - Each cycle the last
%is used up to toggle the following number between0and1. - When all
%s are used up, the$1creates 1 copy of the[~](effectively a NOP), and on the next cycle the)removes the brackets.
Section B
Section B handles regenerating itself as well as a new iteration of section C every 30 cycles.
) : [)$$24%%0:<[~:)~)]~[$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]]
) [)$$24%%0:<[~:)~)]~[$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]] [BkB]
)$ $24% %0 :< [~:)~)] ~ [$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<] [BkB]
)$ %...%%% %1 < < [~:)~)] [BkB] [$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]
)$ %...%% %0 < [~:)~)[BkB]] [$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]
)$ %...% %1 [~:)~)[BkB][$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]]
⋮
) $1 [~:)~)[BkB][$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]]
) [~:)~)[BkB][$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]] (1)
~:) ~)[BkB] [$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]
) : [BkB] ) [$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<] (2)
) [BkB] [BkB] $11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<
- A
:duplicates the big block following (one copy abbreviated as[BkB]), then)removes the brackets from the first copy. $$24%%0sets up a countdown similar to the one in section A.- While this counts down,
:<turns into<<, and a~swaps two of the blocks, placing the code for a new section C last. - The two
<functions pack the two final blocks into the first one - this is redundant in normal iterations, but will allow the~from section A to do its job at the end. - (1) When the countdown is finished, the
)removes the outer brackets. Next~:)turns into):and~)swaps a)to the beginning of the section C code. - (2) Section B is now back at its initial cycle, while a
)is just about to remove the brackets to start running a new iteration of section C.
In the final iteration, the ~ from section A appears at point (1) above:
~ ) [~:)~)[BkB][$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]] (1)
[~:)~)[BkB][$11~)~<[[+$4--498+*-:~-10)):])<~][)))~]<]] )
The ~ swaps the ) across the block and into section C, preventing section B from being run again.
Section C
Section C handles merging new digit character pairs into section D's block, and also creating new iterations of section E.
The below shows a typical iteration with x and y representing the digits' ASCII codes. In the very first iteration, the incoming "D" and "E" elements are the initial [H] and - instead, as no previous section E has run to produce any digit character pairs.
C D E
$11~ ) ~<[[+$4--498+*-:~-10)):])<~] [)))~] < [)))~[...]] [x[y]]
~~~ ~~~ ~~~ ~~) [[+$4--498+*-:~-10)):])<~] < [)))~] [)))~[...][x[y]]]
~~~ ~~~ ) ~ [[+$4--498+*-:~-10)):])<~] [)))~[)))~[...][x[y]]]]
~~~ ~ ) [)))~[....]] [[+$4--498+*-:~-10)):])<~]
~~[)))~[....]] )[[+$4--498+*-:~-10)):])<~]
[)))~[....]] ~[+$4--498+*-:~-10)):])<~
- This uses a different method of synchronization which I discovered for this answer. When you have several swap functions
~in a row, the row will shrink to approximately 2/3 each cycle (because one~swaps two following), but occasionally with a remainder of~s thatwreaks havoc oncarefully manipulates what follows. $11~produces such a row. The next~swaps a<across the following block. Another<at the end appends a new digit pair block (digits x and y as ASCII codes) into the section D block.- Next cycle, the
~row has a~~remainder, which swaps a~over the following). The other<appends section D to a[)))~]block. - Next the swapped
~itself swaps the following block with new section E code across the section D block. Then a new leftover~swaps a)across, and finally the last~~in the~row swap one of them across to section E just as the)has removed its brackets.
In the final iteration, section A's ~ has swapped a ) across section B and into section C. However, section C is so short-lived that it already has disappeared, and the ) ends up at the beginning of section D.
Section D
Section D handles printing the final big numeral and halting the program. During most of the program run, it is an inert block that sections B–G cooperate on building.
(H -
[H]-
⋮
[)))~[H-]] After one iteration of section C
⋮
[)))~[)))~[H-][49[49]]]] Second iteration, after E has also run
⋮
) [)))~[...]] [49[48]] Final printing starts as ) is swapped in
))) ~[...][49[48]]
)) )[49[48]] [...]
)) 49 [48][...] Print first 1
) )[48] [...]
) 48 [...] Print 0
)[...] Recurse to inner block
...
⋮
)[H-] Innermost block reached
H - Program halts
- In the first cycle of the program, a
(wraps the halting functionHin brackets. A-follows, it will be used as a dummy element for the first iteration instead of a digit pair. - The first real digit pair incorporated is
[49[49]], corresponding to the final11in the numeral. - The very last digit pair
[49[48]](corresponding to the10at the beginning of the numeral) is not actually incorporated into the block, but this makes no difference as)[A[B]]and)[A][B]are equivalent, both turning intoA[B].
After the final iteration, the ) swapped rightwards from section B arrives and the section D block is deblocked. The )))~ at the beginning of each sub-block makes sure that all parts are executed in the right order. Finally the innermost block contains an H halting the program.
Section E
Section E handles combining pairs of ASCII digits produced by section G, and both prints the corresponding encoded character and sends a block with the combined pair leftwards to sections C and D.
Again the below shows a typical iteration with x and y representing the digits' ASCII codes.
E F
~ [+$4--498+*-:~-10)):] ) < ~ [y] [x]
) [+$4--498+*-:~-10)):] < [x] [y]
+ $4- - 498 +*- :~ -10 ) ) : [x[y]]
+--- -{-498} +*- ~~{-10} ) ) [x[y]] [x[y]]
+-- - 498 +* -{-10} ~ ) x [y] [x[y]]
+- -{-498} + * 10 x )[y] [x[y]]
+ - 498 + {10*x} y [x[y]]
+ {-498} {10*x+y} [x[y]]
{10*x+y-498} [x[y]]
[x[y]]
- The incoming digit blocks are swapped, then the y block is appended to the x block, and the whole pair block is copied. One copy will be left until the end for sections C and D.
- The other copy is deblocked again, then a sequence of arithmetic functions are applied to calculate
10*x+y-498, the ASCII value of the encoded character.498 = 10*48+48-30, the48s undo the ASCII encoding ofxandywhile the30shifts the encoding from00–99to30–129, which includes all printable ASCII. - The resulting number is then left to execute, which prints its character.
Section F
Section F consists of inert blocks containing ASCII codes of digits. For most of the program run there will be at most two here, since section E consumes them at the same speed that G produces them with. However, in the final printing phase some redundant 0 digits will collect here.
[y] [x] ...
Section G
Section G handles splitting up the big number at the end of the program, least significant digits first, and sending blocks with their ASCII codes leftward to the other sections.
As it has no halting check, it will actually continue producing 0 digits when the number has whittled down to 0, until section D halts the entire program with the H function.
[BkG] abbreviates a copy of the big starting code block, which is used for self-replication to start new iterations.
Initialization in the first cycles:
) :~ : [)[):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):]~:] ( 106328966328112328136317639696111819119696281563139628116326221310190661962811611211962861109696289611619628116111612896281115421063633063961111116163963011632811111819159628151213262722151522061361613096119619190661966311961128966130281807072220060611612811961019070723232022060611
) ~ ~ [)[):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):]~:] [BkG] [10...11]
) [)[):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):]~:] ~ [BkG] [10...11]
) [):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):] ~ : [10...11] [BkG]
Typical iteration, N denotes the number to split:
) [):~[)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+:5):] ~ : [N] [BkG]
) :~ [)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/]+ :5 ) : [N] : [BkG]
) ~ ~ [)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/] +5 5 ) [N] [N] [BkG] [BkG]
) [)~:~~([:~)*[):~[$1(+48]):~+]-:~~)10)~~]/] ~ 10 N [N] [BkG] [BkG]
) ~:~ ~ ( [:~)*[):~[$1(+48]):~+]-:~~)10)~~] / N 10 [N] [BkG] [BkG]
) ~ : [:~)*[):~[$1(+48]):~+]-:~~)10)~~] ( {N/10} [N] [BkG] [BkG]
) [:~)*[):~[$1(+48]):~+]-:~~)10)~~] : [{N/10}] [N] [BkG] [BkG]
:~ )*[):~[$1(+48]):~+]- :~ ~)10 ) ~ ~ [{N/10}] [{N/10}] [N] [BkG] [BkG]
~~) *[):~[$1(+48]):~+]- ~~10 ) ) [{N/10}] ~ [{N/10}] [N] [BkG] [BkG]
) ~ * [):~[$1(+48]):~+] -10 ~ ) {N/10} [N] [{N/10}] [BkG] [BkG]
) [):~[$1(+48]):~+] * {-10} {N/10} ) [N] [{N/10}] [BkG] [BkG]
) :~ [$1(+48]) :~ + {-10*(N/10)} N [{N/10}] [BkG] [BkG]
) ~ ~ [$1(+48] ) ~ ~ {N%10} [{N/10}] [BkG] [BkG]
) [$1(+48] ~ ) {N%10} ~ [{N/10}] [BkG] [BkG]
$1( + 48 {N%10} ) [BkG] [{N/10}] [BkG]
( {48+N%10} BkG [{N/10}] [BkG] New iteration starts
[{48+N%10}] ....
- The delay blob here is particularly hairy. However, the only new delaying trick is to use
+:5instead of--10to delay a10two cycles. Alas only one of the10s in the program was helped by this. - The
[N]and[BkG]blocks are duplicated, then one copy ofNis divided by10. [{N/10}]is duplicated, then more arithmetic functions are used to calculate the ASCII code of the last digit ofNas48+((-10)*(N/10)+N). The block with this ASCII code is left for section F.- The other copy of
[{N/10}]gets swapped between the[BkG]blocks to set up the start of a new iteration.
Bonus quine (540 bytes)
)$$3371%%1[~!~~!)!]):[)$$20%%0[):]~)~~[)$$12%%0[<$$7%~~0):~[+----48+*-~~10))]<]<~!:~)~~[40~[:~))~:~[)~(~~/[+--48):]~10]+30])):]]][)[H]](11(06(06(21(21(25(19(07(07(19(61(96(03(96(96(03(11(03(63(11(28(61(11(06(06(20(18(07(07(18(61(11(28(63(96(11(96(96(61(11(06(06(19(20(07(07(18(61(30(06(06(25(07(96(96(18(11(28(96(61(13(15(15(15(15(22(26(13(12(15(96(96(19(18(11(11(63(30(63(30(96(03(28(96(11(96(96(61(22(18(96(61(28(96(11(11(96(28(96(61(11(96(10(96(96(17(61(13(15(15(22(26(11(28(63(96(19(18(63(13(21(18(63(11(11(28(63(63(63(61(11(61(42(63(63
Since I wasn't sure which method would be shortest, I first tried encoding characters as two-digit numbers separated by (s. The core code is a bit shorter, but the 50% larger data representation makes up for it. Not as golfed as the other one, as I stopped when I realized it wouldn't beat it. It has one advantage: It doesn't require an implementation with bignum support.
Its overall structure is somewhat similar to the main one. Section G is missing since the data representation fills in section F directly. However, section E must do a similar divmod calculation to reconstruct the digits of the two-digit numbers.
Pain-Flak, 2009 bytes
><))(())(())()(())(())()(())(())(())(())()()(())()(())(())()()()(())(())()(())(())()()(())(())(())()(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()(())(())(())()()(())()()(())(())(())()()(())(())(())()()()(())(())(())()()()(())(())()()(())()(())()()(())(())()()()(())(())(())(())(())(())()(())()()()(())()(())()()(())(())()()()(())(())(())()()()(())(())()()(())()(())(())()()(())()()(())(())(())()()(())(())(())(())(())(())()()()(())(())(())()()(())(())(())(())()()(())()()(())()()()(())(())()()(())()(())(())()()(())(())(())(())(())(())()()(())()()()(())(())()(())(())()()(())()(())()()(())()()()(())(())()()(())(())(())(())(())(())()()(())()()()(())()(())(())()(())()()(())(())()(())()()()()(())()(())(())(())(())(())(())(())(())()(())(())(())()()(())()(())(())(())(())(())()()()(())()(())(())()()(())(())(())()()(())()(())(())(())()()(())()(())()(())(())(())(())()()(())()(())()()()()(())()(())()(())()()()(())(())(())()(())(())()()(())(())(())()()(())()(())(())(())()()(())()(())()(())(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()()()(())(())()(())(())()()(())()(())()(())()()()(())()(())(())(())()(())()()()()(())()()(())(())()(())()(())(())(())(())()()(())(())(())()()()(())(())(())()()()(())(())()()(())()(())()()(())(())()()()(())(())(())()()()(())(())(())(())()(())(())(())(())()(())()()()()(())(())()()(())()(())()(())()(())(())()()()(())(())(())()(())(())()()(())()(())()()(())()()()(())(())()(())(())(())(())()()(())()()()()(())()(())()(())(())()()()(())(())(())()(())(())(())()()(())(())(())()()(())(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()(())()(())(())()()()(())()()((}><))))))()()()()((}{(}{(}{()((><))]}{[()(>})}{)((><)))}{])([()(((><{><})}{><(><{}{<())(}])([)>))}{)(>))))()()()()((}{())}{()}{(}{)((>))])}{([))}{()}{(}{)><((()}{()((<(<(()])(})()>}{<({[}{>})}{)(>}{<({<}{)}{>}}{{<}{(><(<({}{(}}{)}{><(><})>)(<({{><})}{><(><{}{{}}{{)))))()()()((}{)((}{)(><)}{(()()((
(Trailing newline because the interpreter outputs a newline.)
-176 bytes by improving the Brain-Flak quine
Basically a straight port of my Brain-Flak quine. The only major difference is the >< at the beginning, which is required in order to keep the data section out of the output.
>< switch to right stack; effectively does nothing since both stacks are empty
))((...))()()(( data, same format as the Brain-Flak quine
}main loop{ same as the Brain-Flak quine, but with different constants
}}{{ clear current stack; this does nothing
)))))()()()((}{)((}{)(><)}{(()()(( push opening >< at beginning of code
Since this is Pain-Flak, the code also goes backward after it is finished going forward. As such, I had to ensure that this does not mess up the output.
))()())}{(><)(}{))(}{))()()()((((( push 70, 68, 5, 4 on right stack
}}{{ clear right stack
}pool niam{ do nothing because top of stack is zero
))()()((...))(( push constants on right stack in reverse order
>< switch to left stack and implicitly output
Brain-Flak, 1805 bytes
(())(()()()())(())(())(()()())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(())(())(())(())(())(()())(()()()())(()())(()()())(())(()()()())(())(())(()()()())(())(()()())(()())(())(()()())(()()())(())(())(()()())(())(())(())(())(())(()()()())(())(())(()()())(())(())(())(()()())(()()())(()()()())(())(()()())(()())(())(()()())(())(())(())(())(())(()()())(()()()())(())(()())(())(()()())(()())(()()())(()()()())(())(()()())(())(())(())(())(()()())(()()()())(()())(())(()())(()()())(())(()())(()())(())(())(())(())(())(())(())(()())(())(()()())(())(())(()())(())(())(())(())(()()()())(()())(())(()()())(())(())(()()())(()())(())(()()())(()())(())(())(())(()())(())(())(()()())(()())(()())(()()()()())(()())(()())(()())(()()()())(())(())(()()())(())(())(()()())(()())(())(())(()()())(()())(()())(())(())(()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()()()())(())(()())(())(()()())(()())(()())(()()()())(()())(())(())(()())(()()()()())(()()())(())(()())(()())(())(())(())(()()())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(())(())(()()()())(())(())(())(())(()())(()()()()())(())(())(()())(())(()()())(()())(()())(()())(())(()()()())(())(())(()())(())(()()())(()())(()()())(()()()())(())(()())(())(())(())(()()())(()()()()())(()())(()())(())(()()()())(())(())(())(()())(()()()()())(())(())(()())(())(()()())(())(())(()()())(())(())(()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(())(()()()())(()()()){<>(((((()()()()()){}){}){}())[()])<>(([{}])()<{({}())<>((({}())[()]))<>}<>{({}<>)<>}{}>)((){[()](<(({}()<(((()()()()()){})(({})({}){})<((([(({})())]({}({}){}(<>)))()){}())>)>))((){()(<{}>)}{}<{({}()<{}>)}>{}({}<{{}}>{})<>)>)}{}){{}({}<>)<>{(<()>)}}<>{({}<>)<>}{}}<>
-188 bytes by avoiding code duplication
Like Wheat Wizard's answer, I encode every closing bracket as 1. The assignment of numbers to the four opening brackets is chosen to minimize the total length of the quine:
2: ( - 63 instances
3: { - 41 instances
4: < - 24 instances
5: [ - 5 instances
The other major improvement over the old version is a shorter way to create the code points for the various bracket types.
The decoder builds the entire quine on the second stack, from the middle outward. Closing brackets that have yet to be used are stored below a 0 on the second stack. Here is a full explanation of an earlier version of the decoder:
# For each number n from the encoder:
{
# Push () on second stack (with the opening bracket on top)
<>(((((()()()()()){}){}){}())[()])<>
# Store -n for later
(([{}])
# n times
{<({}())
# Replace ( with (()
<>((({}())[()]))<>
>}{}
# Add 1 to -n
())
# If n was not 1:
((){[()]<
# Add 1 to 1-n
(({}())<
# Using existing 40, push 0, 91, 60, 123, and 40 in that order on first stack
<>(({})<(([(({})())]((()()()()()){})({}{}({})(<>)))({})()()())>)
# Push 2-n again
>)
# Pop n-2 entries from stack
{({}()<{}>)}{}
# Get opening bracket and clear remaining generated brackets
(({}<{{}}>{})
(<
# Add 1 if n was 2; add 2 otherwise
# This gives us the closing bracket
({}(){()(<{}>)}
# Move second stack (down to the 0) to first stack temporarily and remove the zero
<<>{({}<>)<>}{}>
# Push closing bracket
)
# Push 0
>)
# Push opening bracket
)
# Move values back to second stack
<>{({}<>)<>}
# Else (i.e., if n = 1):
>}{})
{
# Create temporary zero on first stack
(<{}>)
# Move second stack over
<>{({}<>)<>}
# Move 0 down one spot
# If this would put 0 at the very bottom, just remove it
{}({}{(<()>)})
# Move second stack values back
<>{({}<>)<>}}{}
}
# Move to second stack for output
<>
Lost, 120 116 98 96 76 70 66 bytes
Edit: yay, under 100
Edit: Saved a bunch o' bytes by switching to all /s on the bottom line
:2+52*95*2+>::1?:[:[[[[@^%?>([ "
////////////////////////////////
Try it online! + verification it's deterministic for all possible states
Lost is a 2D language in which the starting position and direction are completely random. This means there has to be a lot of error-checking at every stage to make sure you've got the correct instruction pointer, and it isn't one that has just wandered in randomly.
Explanation:
All the /s on the bottom line are there to make sure that all the pointers that spawn in a vertical direction or on the bottom line get funneled in the right direction. From there, they end up at several different places, but all of them end up going right into the
^%?>
////
Which clears out all the non-zero numbers in the stack. The ([ after that clears out any extra 0s as well.
In the middle of the clear, it hits the %, which turns the 'safety' off, which allows the program to end when it hits the @ (without this, the program could end immediately if a pointer started at the @).
From there it does a pretty simple 2D language quine, by wrapping a string literal (") around the first line, pushing a " character by duping a space (:2+) and then a newline (52*). For the second line, it creates a / character (95*2+) and duplicates it a bunch (>::1?:[:[[[[), before finally ending at the @ and printing the stack implicitly. The ?1 is to stop the process from creating too many 0s if the pointer enters early, saving on having to clear them later.
I saved 20 bytes here by making the last line all the same character, meaning I could go straight from the duping process into the ending @.
Explanation about the duping process:
[ is a character known as a 'Door'. If the pointer hits the flat side of a [ or a ] , it reflects, else it passes through it. Each time the pointer interacts with a Door, it switches to the opposite type. Using this knowledge we can construct a simple formula for how many times an instruction will execute in a >:[ block.
Add the initial amount of instructions. For each [, add 2 times the amount of instructions to the left of it. For the example >::::[:[[[, we start with 5 as the initial amount. The first Door has 4 dupe instructions, so we add 4*2=8 to 5 to get 13. The other three Doors have 5 dupes to their left, so we add 3*(5*2)=30 to 13 to get 43 dupe instructions executed, and have 44 >s on the stack. The same process can be applied to other instructions, such as ( to push a large amount of items from the stack to the scope, or as used here, to clear items from the stack.
A trick I've used here to avoid duping too many 0s is the 1?. If the character is 0, the ? doesn't skip the 1, which means it duplicates 1 for the remainder of the dupe. This makes it much easier to clear the stack later on.
Stax, 10 4 bytes
..SS
I have long believed that the 10-byte quine cannot be any shorter until I happen to come across this one while doing another challenge. This one is not extensible while the 10-byte one is.
Explanation
..SS
..S The string ".S"
S Powerset, in dictionary order if the original string is ordered
In this case, generates [".",".S","S"]
Implicit flatten and output
Old version, 10 bytes
"34bL"34bL
Added for completeness. I thought this is the shortest proper quine in Stax, but the idea is not that exciting and has been extensively used. I tried to come up with a more interesting (but longer) solution but so far to no avail Now there is one, it's even shorter than this.
I would also be happy to offer a bounty to a proper quine in Stax in the packed form.
Explanation
"34bL" Push that string
34 Push the quotation mark
b Duplicate both elements on stack
L Pack all elements to an array
Implicit output
Finally, an improper quine:
|? Source of the program
or just
0 Implicitly prints the 0 on the top of stack
Haskell, 44 41 bytes
EDIT:
- -3 bytes due to H.PWiz
GHC 8.4.1 is out, which implements the second phase of the Semigroup Monoid Proposal.
As a result, the <> operator is now available without an import, which allows a 9 bytes shorter quine than the previous record, the nearly six year old answer by AardvarkSoup.
main=putStr<>print$"main=putStr<>print$"
Try it online! (This cheats and has an import in the header because TIO hasn't upgraded to GHC 8.4 yet.)
How it works
<>isSemigroupmultiplication, defined differently for each type it supports.- For functions, it returns a new function that takes an argument, passes it to the two multiplied functions, and then applies
<>for the result type to the results. - For
IOactions, it returns a newIOaction that runs the two multiplied actions, and then applies<>to their result values to get the result value of the combination.
- For functions, it returns a new function that takes an argument, passes it to the two multiplied functions, and then applies
- Thus
putStr<>print$q = do x <- putStr q; y <- print q; pure (x<>y), which first outputs the stringq, then outputs its string literal version with a newline appended. (The result values are both(), so the final one is also(), although this doesn't affect output.)
SmileBASIC, 66 54 bytes
?MID$(("+CHR$(34))*3,19,54)?MID$(("+CHR$(34))*3,19,54)
This will work in most BASIC dialects.
Brain-Flak, 9.8e580 1.3e562 9.3e516 12818 11024 4452 4332 4240 4200 4180 3852 3656 3616 3540 2485 + 3 = 2488 bytes
Now fits in the observable universe!
(())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(())(())(()())(())(())(())(()())(()()()())(())(()()()()())(()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(())(())(()())(())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(())(())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(()()())(())(()()())(())(())(())(()())(()()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(())(())(())(()()())(())(())(())(()())(())(()())(()()()())(())(())(()()()()())(()())(()())(())(()()())(())(())(())(())(()()())(()())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(()()()()())(())(()()())(())(())(()())(())(()()()()())(())(()()()()())(())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(())(()()()()())(())(())(())(()())(())(()()()()())(())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()()()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(())(()())(()()()())(())(())(()())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(()()())(())(())(()())(())(())(()()()()())(()()()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(()()()())(()()()())(()())([[]]){({}()<(([{}]())<{({}())<>(((((()()()()()){}){}){}())[()])<>{({}())<>{}({}(((()()()){}())){}{})<>{({}())<>({}(((()()()()()){})){}{}())<>{{}<>({}(((()()()()){}){}){})(<>)}}<>(({})[()()])<>}}{}<>({}(<()>)<><{({}<>)<>}<>>){({}<>)<>}{}(<>)<>{({}<>)<>}{}(((((((()()()()()){}){}){}))()))>){({}()<((({}[()])()))>)}{}<>{({}<>)<>}{}>)}{}<>{({}<>)<>}<>
Explanation
This Quine works like most Quines in esoteric languages; it has two parts an encoder and a decoder. The encoder is all of the parentheses at the beginning and the decoder is the more complex part at the very end.
A naive way of encoding the program would be to put the ASCII value of every character in the decoder to the stack. This is not a very good idea because Brain-Flak only uses 8 characters (()<>[]{}) so you end up paying quite a few bytes to encode very little information. A smarter idea, and the one used up until now is to assign each of the 8 braces to an much smaller number (1-8) and convert these to the ASCII values with our decoder. This is nice because it costs no more than 18 bytes to encode a character as opposed to the prior 252.
However this program does neither. It relies on the fact that Brain-Flak programs are all balanced to encode the 8 braces with the numbers up to 5. It encodes them as follows.
( -> 2
< -> 3
[ -> 4
{ -> 5
),>,],} -> 1
All the close braces are assigned 1 because we can use context to determine which of them we need to use in a particular scenario. This may sound like a daunting task for a Brain-Flak program, but it really is not. Take for example the following encodings with the open braces decoded and the close braces replaced with a .:
(.
((..
<([.{...
Hopefully you can see that the algorithm is pretty simple, we read left to right, each time we encounter a open brace we push its close brace to an imaginary stack and when we encounter a . we pop the top value and put it in place of the .. This new encoding saves us an enormous number of bytes in the encoder while only losing us a handful of bytes on the decoder.
Low level explanation
Work in progress
Reflections, 1.81x10375 bytes
Or to be more accurate, 1807915590203341844429305353197790696509566500122529684898152779329215808774024592945687846574319976372141486620602238832625691964826524660034959965005782214063519831844201877682465421716887160572269094496883424760144353885803319534697097696032244637060648462957246689017512125938853808231760363803562240582599050626092031434403199296384297989898483105306069435021718135129945 bytes.
The relevant section of code is:
+#::(1 \/ \ /: 5;;\
>v\>:\/:4#+ +\
/+# / 2 /4):_ ~/
\ _ 2:#_/ \ _(5#\ v#_\
*(2 \;1^ ;;4) :54/
\/ \ 1^X \_/
Where each line is preceeded by 451978897550835461107326338299447674127391625030632421224538194832303952193506148236421961643579994093035371655150559708156422991206631165008739991251445553515879957961050469420616355429221790143067273624220856190036088471450829883674274424008061159265162115739311672254378031484713452057940090950890560145649762656523007858600799824096074497474620776326517358755429533782443 spaces. The amount of spaces is a base 128 encoded version of the second part, with 0 printing all the spaces again.
Edit: H.PWiz points out that the interpreter probably doesn't support this large an integer, so this is all theoretical
How It Works:
+#::(1 Pushes the addition of the x,y coordinates (this is the extremely large number)
Dupe the number a couple of times and push one of the copies to stack 1
\
>
Pushes a space to stack 2
*(2
\/
/ \
>v >:\
/+# / 2 Print space number times
\ _ 2:#_/
# Pop the extra 0
\;1^ Switch to stack 1 and start the loop
/:4#+ +\
/4):_ ~/ Divide the current number by 128
\ _(5#\ v Mod a copy by 128
^ 4) :
\_/
v#_\ If the number is not 0:
^ ;;4) :54/ Print the number and re-enter the loop
/: 5;;\
v\ 4 If the number is 0:
4 Pop the excess 0
: \ And terminate if the divided number is 0
Otherwise return to the space printing loop
\ 1^X
Conclusion: Can be golfed pretty easily, but maybe looking for a better encoding algorithm would be best. Unfortunately, there's basically no way to push an arbitrarily large number without going to that coordinate.
Befunge-93, 15 14 13 bytes
+9*5x:#,_:@#"
Works in this interpreter. x is an unrecognized command which reflects the instruction pointer.
Thanks to Jo King for saving 1 byte.
This 14 byte version works in FBBI:
+9*5<>:#,_:@#"
Cubically, 191143 136577 91163 79824 32301 23782 bytes
bzip2 base64:
QlpoOTFBWSZTWSMgFToABO/+gH+v8Axh+v8AxgYAoIAKQAJdwKuVzgxQ1MUB6hoA0GmgGgJT1FTQ
no0T1BgEBkwhgmqSlP0SaekAAANDNNR6giUSNI9IwgYmRiYGk0bAN0SBGEAgAwipuIKA7IAr0BT8
fTJaxJTd/OTv5dAU375w7dKpPdcgU38W3ZxzMysszgCmq8dVJjeCn61Wa1tmVmZ1gplc94KanXgK
cOAKeeFeHf2XHWrLMyzN2ta1qzWZbvDa2srdncCnMFMvDqBTOflgU0CmgU6gU1rcqk8cmYtCraEq
FKwAEaKqDciINVVTgCm214pJTKFMjGGprIlgQhSh8AAjdcACPWrfws5fs4KwtZFUULGPlBwWUWQo
qGxI64evL2PCZJmSklppgmpiUlBJkhQFgWAlKaYCS+ygDZJECsG+CYIJIAVi+p1vkyE47sxkphLQ
aCIqikSFBkERl6ftt99xKSQE0Q4IhIkVmlYztSX3HWMA+VMsrqrboe70pOhdF17QtcGYNScpPTPc
lIkkgGc4wjB9xJJp/Xd/blx283P0/I2BTsBTmqkxVJ0BTf3YCnTr7QU/4u5IpwoSBGQCp0A=
At least it is obviously possible. Didn't try v1.3 yet.
The official interpreter seemed to be lying about that it supports SBCS. But I managed to get it working in Unicode mode.
Generator in CJam
{
e#"«»"[129 130]er
"«»"'Â1$f+ers
}:U;
{
N-U:i_0=\2ewWf%::-+
{
_g:M;
[z
[[36 5]
[29 4]
[25 2]
[23 1]
[21 3]]
{~@@md\@s*\}/
_11>{3 21@-])\s_M" +-"=\+e&\0s*_M" -+"=\+e&+}{0s*]s_M" +-"=\+e&}?
'@
}%s
}:F;
[
""
"M2E
(
!0{LDL'"
"}))"F
"&}
M-"
""
"*1(6/1+"
""
"*1
!0{?6{*11LDL'"
"
?0{/4+11@_}
!0{(6*11+33@/11-4)}
}-1
!6{+":QN-F
"LD'L'/11}}
!6{+"
]_sN-
U,24md23\-'+*@0@t4 2$)"3"*t6@)"3"*t
sN-
_U{i32-"4"*QN-}/"}))"
Pseudocode
Loop i in {1,2,3}
If i = 3, output "}))" and exit
n = -1 - length before the first +1+1+1+1+...
Loop while n != 0:
n += 1 + length before the first +1+1+1+1+...
If i = 2, output the code corresponding to the following pseudocode:
"
If i = 1, output n as a character
If i = 2, output "+1" n times
n--
If n = 0:
n =
"
If n = 0:
n = +1+1+1+1+... (the first character)
If i = 1, output n as a character
If i = 2, output "+1" n times
n--
If n = 0:
n = +1+1+1+1+... (the second character)
If i = 1, output n as a character
If i = 2, output "+1" n times
n--
...
n is stored in the register called "notepad". i is stored as cube positions.
The first version has used a 1 in one face to print numbers. The latest version simply add whatever number in one face and divides by it.
There are two ways of printing a string preserving the register. One way is to multiply by 16 or 32 two times, the other is to shift left by a small number. The cube position had to be chosen carefully to get a small enough number in the first version to prevent overflow. But after it is golfed it almost always works.
HTML + CSS 118 78 77 75 53 51 50 characters
<style>*{display:flex}html:before{content:'<style>
This language isn't good for quining, but it works. Invalid HTML and CSS, but it doesn't really matter.
ColdFusion, 276 bytes
<cfset u=Chr(34)><cfset q="<cfset u=Chr(34)><cfset q=%s%s%s><cfoutput>%screateObject(%sjava%s,%sjava.lang.String%s).format(q,[u,q,u,Chr(35),u,u,u,u,Chr(35)])%s</cfoutput>"><cfoutput>#createObject("java","java.lang.String").format(q,[u,q,u,Chr(35),u,u,u,u,Chr(35)])#</cfoutput>
I've never used ColdFusion, but after seeing @Danninta's post on Self-growing code codee codeee codeeee I thought I'd play around. This could almost certainly be golfed down by someone that actually knows the language, so feel free to add a new answer.
Tested locally on lucee-express-5.2.6.60
Dodos, 1743 1722 1380 1360 1340 1155 1120 1105 1095 1075 985 bytes
o d
o e d
o
a 3 p
o > >
p
u =
u =
=
= >
u
e
* * - =
e >
a
dot
>
dab
b
b dip
=
a b m
m
a >
a
i
a + =
>
*
= b
+
dip = b
-
i i +
.
i -
2
i i i i .
3
i 2
5
i 3
d
* * 3 - * * 2 - * + * * 3 - * * 2 . * * 2 - * + 3 - * + * * 2 * * * - 3 * * 3 . * + * * 3 - * * . 3 * * . 3 * + 3 . * + * * 3 3 * * . 2 * + * * 3 3 * * . 2 * + * * . 2 * + * * . 2 * * . 3 * + 3 3 * + * * * + * * * + * * * + * * * + * * * + 2 . * + * * - * * * - * * * - - * * . 2 * + * * 2 . * * . 3 * + 2 * * + * * 2 - 3 - 3 2 * + . 3 * + * * 2 - 2 * 2 + * + 2 + * + * * 2 + * * 2 - 2 2 3 . * + . 2 * + * * 2 * * * 2 + * * 3 + * + 3 + * + * * 2 * * * . 3 * + * * 2 * * + 2 2 * + * * 2 * * * - + * * . 2 * + * * . 3 * + - * * + * * . 2 * * 2 + * + * * * + - + * + * * 2 - 2 2 3 . * * . 2 * * 2 + * + * * * + - - * + * * 2 2 * * 2 2 * * - + * + - . * + * * 2 2 * * - - * + - 2 * + * * 2 2 * * 2 2 * * 2 2 * * 2 2 * * - . * + - 3 * + * * 2 2 * * - 2 * + . * * + * * 2 2 * * - 3 * + 2 - * +
Japt, 9 bytes
I've fantasized about a 9-byte Japt quine for years, and now it's finally snapped into place :-D
9îQi"9îQi
Explanation
"9îQi Start with this string. 9îQi
Qi Insert it before a quotation mark. 9îQi"
9î Repeat until it reaches length 9. 9îQi"9îQi
Rust, 108 characters
macro_rules!f(()=>("macro_rules!f(()=>({:?}));fn main(){{print!(f!(),f!())}}"));fn main(){print!(f!(),f!())}
This is a suboptimal solution, but it's so close to the current shortest solution that I wanted to post it anyway as it uses a completely different strategy. I think it can be optimized by using macro keyword instead of verbose macro_rules! when it becomes stable (which would reduce this to 96 characters).
Hexagony, side length 15 14 13 12, 616 533 456 383 bytes
After several days of careful golfing, rearranging loops and starting over, I've finally managed to get it down to a side 12 hexagon.
1845711724004994017660745324800783542810548755533855003470320302321248615173041097895645488030498537186418612923408209003405383437728326777573965676397524751468186829816614632962096935858"">./<$;-<.....>,.........==.........<"......."">'....>+'\.>.........==........<"......"">:>)<$=<..>..............$..<"...."">\'Q4;="/@>...............<"....."">P='%<.>.............<"..!'<.\=6,'/>
Unfolded:
1 8 4 5 7 1 1 7 2 4 0 0
4 9 9 4 0 1 7 6 6 0 7 4 5
3 2 4 8 0 0 7 8 3 5 4 2 8 1
0 5 4 8 7 5 5 5 3 3 8 5 5 0 0
3 4 7 0 3 2 0 3 0 2 3 2 1 2 4 8
6 1 5 1 7 3 0 4 1 0 9 7 8 9 5 6 4
5 4 8 8 0 3 0 4 9 8 5 3 7 1 8 6 4 1
8 6 1 2 9 2 3 4 0 8 2 0 9 0 0 3 4 0 5
3 8 3 4 3 7 7 2 8 3 2 6 7 7 7 5 7 3 9 6
5 6 7 6 3 9 7 5 2 4 7 5 1 4 6 8 1 8 6 8 2
9 8 1 6 6 1 4 6 3 2 9 6 2 0 9 6 9 3 5 8 5 8
" " > . / < $ ; - < . . . . . > , . . . . . .
. . . = = . . . . . . . . . < " . . . . . .
. " " > ' . . . . > + ' \ . > . . . . . .
. . . = = . . . . . . . . < " . . . . .
. " " > : > ) < $ = < . . > . . . . .
. . . . . . . . . $ . . < " . . . .
" " > \ ' Q 4 ; = " / @ > . . . .
. . . . . . . . . . . < " . . .
. . " " > P = ' % < . > . . .
. . . . . . . . . . < " . .
! ' < . \ = 6 , ' / > . .
. . . . . . . . . . . .
While it doesn't look like the most golfed of Hexagony code, the type of encoding I used is optimised for longer runs of no-ops, which is something you would otherwise avoid.
Explanation
This beats the previous Hexagony answer by encoding the no-ops (.) in a different way. While that answer saves space by making every other character a ., mine encodes the number of no-ops. It also means the source doesn't have to be so restricted.
Here I use a base 80 encoding, where numbers below 16 indicate runs of no-ops, and numbers between 16 and 79 represent the range 32 (!) to 95 (_) (I'm just now realising I golfed all the _s out of my code lol). Some Pythonic pseudocode:
i = absurdly long number
print(i)
base = 80
n = i%base
while n:
if n < 16:
print("."*(16-n))
else:
print(ASCII(n+16))
i = i//base
n = i%base
The number is encoded in the first half of the hexagon, with all the
" " >
" " >
... etc
on the left side and the
> ,
< "
>
< "
... etc
on the right side redirecting the pointer to encode the number into one cell. This is taken from Martin Ender's answer (thanks), because I couldn't figure out a more efficient way.
It then enters the bottom section through the ->:
" " > \ ' Q 4 ; = " / @ > . . . .
. . . . . . . . . . . < " . . .
. . " " > P = ' % < . > . . .
. . . . . . . . . . < " . .
-> ! ' < . \ = 6 , ' / > . .
! prints the number and ' navigates to the right memory cell before starting the loop. P='% mods the current number by 80. If the result is 0, go up to the terminating @, else go down and create a cell next to the mod result with the value -16.
. " " > ' . . . . > + ' \ . > . . . . . .
. . . = = . . . . . . . . < " . . . . .
. " " > : > ) < $ = < . . > . . . . .
. . . . . . . . . $ . . < " . . . .
" " > \ ' Q 4 ; = " / @ > . . . .
/
/
Set the cell to (mod value + -16). If that value is negative, go up at the branching >+'\, otherwise go down.
If the value is positive:
" " > . / < $ ; - < . . . . . > , . . . . . .
. . . = = . . . . . . . . . < " . . . . . .
. " " > ' . . . . > + ' \ . > . . . . . .
The pointer ends up at the ;-< which sets the cell to (mod value - -16) and print it.
The the value is negative:
. " " > ' . . . . > + ' \ . > . . . . . .
. . . = = . . . . . . . . < " . . . . .
. " " > : > ) < $ = < . . > . . . . .
Go down to the > ) < section which starts the loop. Here it is isolated:
. . > ) < $ = < . .
. . . . . . . . .
\ ' Q 4 ; = " /
Which executes the code 'Q4;="= which prints a . (thanks again to Martin Ender, who wrote a program to find the letter-number combinations for characters) and moves back to the starting cell. It then increments ()) the mod value cell and loops again, until the mod value is positive.
When that is done, it moves up and joins with the other section at:
" " > . / < $ ; - < . . .
\
\
The pointer then travels back to the start of the larger loop again
" " > . / <--
. . . = =
. " " > '
. . . = =
. " " > :
. . . . .
" " > \ ' . .
. . . . . . .
. . " " > P = ' % < . > . . .
This executes ='=:' which divides the current number by 80 and navigates to the correct cell.
Old version (Side length 13)
343492224739614249922260393321622160373961419962223434213460086222642247615159528192623434203460066247203920342162343419346017616112622045226041621962343418346002622192616220391962343417346001406218603959366061583947623434"">/':=<$;'<.....>(......................<"......"">....'...>=\..>.....................<"....."">....>)<.-...>...........==......<"...."">.."...'.../>.................<"..."">\Q4;3=/.@.>...............<".."".>c)='%<..>..!'<.\1*='/.\""
I can most definitely golf another side length off this, but I'll have to leave it til' tomorrow because it's getting late. Turns out I'm impatient and can't wait until tomorrow. Maybe another side can be golfed? :( ahhhhhhhhh i did it!
I even golfed off a couple of extra digits with a base 77 encoding, but it doesn't really matter, since it has the same bytecount.
Java, 528 bytes:
A Java solution with an original approach:
import java.math.*;class a{public static void main(String[]a){BigInteger b=new BigInteger("90ygts9hiey66o0uh2kqadro71r14x0ucr5v33k1pe27jqk7mywnd5m54uypfrnt6r8aks1g5e080mua80mgw3bybkp904cxfcf4whcz9ckkecz8kr3huuui5gbr27vpsw9vc0m36tadcg7uxsl8p9hfnphqgksttq1wlolm2c3he9fdd25v0gsqfcx9vl4002dil6a00bh7kqn0301cvq3ghdu7fhwf231r43aes2a6018svioyy0lz1gpm3ma5yrspbh2j85dhwdn5sem4d9nyswvx4wmx25ulwnd3drwatvbn6a4jb000gbh8e2lshp",36);int i=0;for(byte c:b.toByteArray()){if(++i==92)System.out.print(b.toString(36));System.out.print((char)c);}}}
in readable form:
import java.math.*;
class a
{
public static void main (String [] a)
{
BigInteger b=new BigInteger ("90ygts9hiey66o0uh2kqadro71r14x0ucr5v33k1pe27jqk7mywnd5m54uypfrnt6r8aks1g5e080mua80mgw3bybkp904cxfcf4whcz9ckkecz8kr3huuui5gbr27vpsw9vc0m36tadcg7uxsl8p9hfnphqgksttq1wlolm2c3he9fdd25v0gsqfcx9vl4002dil6a00bh7kqn0301cvq3ghdu7fhwf231r43aes2a6018svioyy0lz1gpm3ma5yrspbh2j85dhwdn5sem4d9nyswvx4wmx25ulwnd3drwatvbn6a4jb000gbh8e2lshp", 36);
int i=0;
for (byte c:b.toByteArray ())
{
if (++i==92)
System.out.print (b.toString (36));
System.out.print ((char) c);
}
}
}
Swift 4, 120 bytes
import Foundation;let q="import Foundation;let q=%c%@%c;print(String(format:q,34,q,34))";print(String(format:q,34,q,34))
Since this code imports Foundation, and the Swift corelibs can be a little quirky in non-macOS environments, you might not be able to run it (it doesn't work in TIO, or IBM's Swift Sandbox). If, however, you have a macOS environment, then you should be just fine.
Bash + coreutils, 18 bytes
sed p<<a
sed p<<a
It requires a trailing newline and generates a warning.
Posted the Zsh version in a separate answer to fix the leaderboard.
Wumpus, 9 bytes
"#34#9&o@
Explanation
This is a fairly standard Fungeoid quine. However, as opposed to most other Fungeoids, Wumpus's grid doesn't wrap around, so the IP actually bounces back and forth through the code:
"#34#9&o@o&9#32#"
This pushes the individual code points of this string to the stack.
#34 Push 34.
#9 Push 9.
&o Print 9 characters from the top of the stack.
@ Terminate the program.
There are several other ways to do this in 9 bytes, e.g. this one which generates the " from the # instead:
"#9[(~&o@
I haven't yet found a way to get it down to 8 bytes though (it might be possible: if there's a way to generate the 34 in three bytes that doesn't end in a digit, we could get rid of the # in front of the 9).
Locksmith, 201 bytes
070405000400080701090704000102010702070000080006030109000107020001020106070707040507040001020107020700000800060301090001070200010201067450408719740121727008063190172012167774574012172700806319017201216
Formatted:
0704050004000807010907040001020107020700000800060301090001070200010
2010607070704050704000102010702070000080006030109000107020001020106
7450408719740121727008063190172012167774574012172700806319017201216
This consists of two parts: the data section and the decoder. The data section is simply each byte of the encoder prefixed with a 0 (which is the command to push that number). The decoder is:
74 // push stack length
5 // that many times:
0408719 // output a 0
74012172 // bring bottom of stack to the top
700806319 // output this without popping
0172 // swap top two (brings length to top)
0121 // decrement
6 // close loop
7774 // pop counter, push length again
5
74012172 // bring bottom to top
700806319 // output
0172 // bring length to top
0121 // decrement
6 // close loop
Lost, 293 262 249 bytes
>:2+52*:6*:(84*+75*):>:::::[[[[[[[:[(52*)>::::[[[[[[:[84*+@>%?!<((((((((((([[[[[[[[[[[[[[ "
\#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\
Explanation
This entire project has been an up and down. I kept thinking it was impossible and then coming up with a crazy idea that just might work.
Why is a Lost Quine so hard?
As you may know Lost is a 2D programming language where the start location and direction are entirely random. This makes writing any lost program about as difficult as writing radiation hardened code. You have to consider every possible location and direction.
That being said there are some standard ways to do things. For example here is the standard way of printing a string.
>%?"Stringv"(@
^<<<<<<<<<<<<<
This has a collection stream at the bottom that grabs the most of the ips and pulls them to the start location. Once they reach are start location (upper left) we sanitize them with a loop getting rid of all the values on the stack then turn the safety of push the string and exit. (safety is a concept unique to Lost every program must hit a % before exiting, this prevents the possibility of the program terminating upon start). Now my idea would be to extend this form into a full fledged quine.
The first thing that had to be done was to rework the loop a bit, the existing loop was specific to the String format.
>%?!<"Stringv"(@
^<<<<<<<<<<<<<<<
^<<<<<<<<<<<<<<<
We need to add a second stream to avoid the possibility of the ! jumping over the stream and creating a loop.
Now we want to mix this with the standard Quine format. Since Lost is based very much on Klein I've basically stolen borrowed the Klien Quine for Martin Ender.
:2+@>%?!< "
<<<<^<<<<<<
<<<<^<<<<<<
This quite conveniently prints the first line of the quine. Now all we need to do is hard-code the streams. Well this is easier said than done. I tried approximately four different methods of doing this. I'll just describe the one that worked.
The idea here is to use doors to get the desired number of arrows. A Door is a special type of mirror that changes every time it is hit. [ reflects ips coming from the left and ] from the right. When they are hit by an ip from either of these sides the switch orientation. We can make a line of these doors and a static reflector to repeatedly perform an operation.
>:[[[
Will perform : three times. This way if we push a < to the stack before hand we can make a lot of them with less bytes. We make 2 of these, one for each line, and in between them we lay down a newline, however the second one needs only go until it covers the ! we added it for, anything else can be left empty saving us a few bytes. Ok now we need to add the vertical arrows to our streams. This is where the key optimization comes in. Instead of redirecting all the ips to the "start" of the program directly we will instead redirect them to the far left, because we already know that the ips starting in far left must work (or at least will work in the final version) we can also just redirect the other ips. This not only makes it cheaper in bytes, I think this optimization is what makes the quine possible.
However there are still some problems, the most important one being ips starting after the > has been pushed but before we start making copies of it. Such ips will enter the copier and make a bunch of copies of 0. This is bad because our stack clearing mechanism uses zeros to determine the bottom of the stack, leaving a whole bunch of zeros at the bottom. We need to add a stronger stack sanitation method. Since there is no real way of telling if the stack is empty, we will simply have to attempt to destroy as many items on the stack as possible. Here we will once again use the door method described earlier. We will add ((((((((((([[[[[[[[[[[[[[ to the end of the first line right after the sanitizor to get rid of the zeros.
Now there is one more problem, since we redirected our streams to the upper left ips starting at the % and moving down will already have turned the safety off and will exit prematurely. So we need to turn the safety off. We do this by adding a # to the stream, that way ips flowing through the stream will be turned off but ips that have already been sanitized will not. The # must also be hard coded into the first line as well.
That's it, hopefully you understand how this works now.
Operation Flashpoint scripting language, 22 15 bytes
q={"q={"+q+"}"}
Call with:
hint call q
Output:
Old version (22 bytes):
q={format["q={%1}",q]}
><>, 8 bytes
#o<}-1:"
Copied the trick of copying and decrementing the # to get " from the other ><> answer, but uses both sides of the # to avoid needing to reverse the stack.
Edit: A much cleaner solution of the same length:
'rd3*>o<
Everyone forgets that a ' acts exactly the same as a ", but has usable divisors. Another 8 byte solution, but considered cheaty by some, 'r00g>o<
Implicit, 20 bytes
«@171%@187»@171%@187
This didn't work in older versions of Implicit.
How it works
«@171%@187» Push the string '@171%@187' on the stack. Let's call it s.
@171 Print '«' (char code 171), without pushing it on the stack.
% Print s without popping it from the stack.
@187 Print '»' (char code 171), without pushing it on the stack.
(implicit) Print the top of the stack: s.
Implicit, 26 bytes
«:171,::187,"»:171,::187,"
How it works
«:171,::187,"» Push the string ':171,::187,"' on the stack.
Let's call it s.
:171 Push 171 (code point of «).
, Swap s and 171.
: Push a copy of s.
:187 Push 187 (code point of »).
, Swap the copy of s and ».
" Combine the entire stack into a string.
Retina, 20 14 9 7 bytes
Before we get started, I'd like to mention the trivial solution of a file which contains a single 0. In that case Retina will try to count the 0s in the empty input, the result of which is also 0. I wouldn't consider that a proper quine though.
So here is a proper one:
>\`
>\`
Alternatively, we could use ; instead of >.
Explanation
The program consists of a single replacement which we print twice.
In the first line, the ` separates the configuration from the regex, so the regex is empty. Therefore the empty string (i.e. the non-existent input) is replaced with the second line, verbatim.
To print the result twice, we wrap it in two output stages. The inner one, \ prints the result with a trailing linefeed, and the outer one, >, prints it without one.
If you're a bit familiar with Retina, you might be wondering what happened to Retina's implicit output. Retina's implicit output works by wrapping the final stage of a program in an output stage. However, Retina doesn't do this, if the final stage is already an output stage. The reason for that is that in a normal program it's more useful to be able to replace the implicit output stage with special one like \ or ; for a single byte (instead of having to get rid of the implicit one with the . flag as well). Unfortunately, this behaviour ends up costing us two bytes for the quine.
Awk, 64 bytes
BEGIN{c="BEGIN{c=%c%s%c;printf c,34,c,34}";printf c,34,c,34}
Java 8 - 392 bytes
interface Q{static void main(String[]a){p("interface Q{static void main(String[]a){p(");q(");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}
The main trick with this was using 34 cast to a character for the quotes that bound the string literals in order to not run into issues.
Aubergine, 21 bytes
-a1+a1=oA=Bi-BA:bB=ia
This program ends with a trailing tab character.
Funky, 21 bytes
f=@write`f=[f]f()`f()
or, if Functions are allowed...
Funky, 9 bytes
f=@'f='+f
The second of these defines a function f which returns the string f=@'f='+f, the first however is a full program.
tinylisp, 88 bytes
The byte count includes a trailing newline.
((q (g (c (c (q q) g) (c (c (q q) g) ())))) (q (g (c (c (q q) g) (c (c (q q) g) ())))))
There are no strings in tinylisp, but a nontrivial quine is still possible because code is lists and lists are code. The above code is a list which, when evaluated, returns (and therefore prints) itself.
The idea is to pass the list (g (c (c (q q) g) (c (c (q q) g) ()))) to a function which will wrap it in a list, tack a q on the front, and then wrap two copies of that in a list. Which is exactly what the function (q (g (c (c (q q) g) (c (c (q q) g) ())))) does. In-depth explanation available on request, but I wanted to post this before turning in for the night.
OML, 20 bytes
"lK(34Tos)"lK(34Tos)
This was an interesting process. I initially started off with the classic data-decoder method of quining. That is, one devotes one section of the program to encoding the decoder, and another section to generate the data representation and decode the data. This came out to look like this (51 bytes):
'\'l'K'l'2'/'['('''''o'o')']'('o')\lKl2/[(''oo)](o)
Where the data section looks like:
'\'l'K'l'2'/'['('''''o'o')']'('o')
which pushes each character after a '. The decoder looks like this:
\lKl2/[(''oo)](o)
\ reverse stack
lK duplicate stack
l2/[ copy the duplication into a new stack
( ) while there are characters on this stack:
''o output a single quote
o and the character
] return to the original stack
(o) output all characters on this stack
This can be improved slightly by replacing (o) with ls (48 bytes):
'\'l'K'l'2'/'['('''''o'o')']'l's\lKl2/[(''oo)]ls
However, OML also has a length-encoded string construct. Let's say the string is "xyz". This is effectively 'x'y'z3, since there are three characters in the string. We can use s to print this string, but we still need to generate the quote characters. With all this in mind, I was able to devise the following approach (26 bytes):
"lK34Tos34Tos"lK34Tos34Tos
Simply put, this puts the "string" "lK34Tos34Tos" to the stack, then performs the following actions:
lK34Tos34Tos
lk duplicate the stack (in this case, the string)
34To output a quotation mark "
s output the string
34To output another quotation mark "
s output the string again
We obtain our final version by noting that the structure 34Tos is repeated twice. We can use a while loop to produce the current answer.
JavaScript (ES6 REPL), 22 bytes
f=_=>"f="+f+";f()";f()
Idea stolen from Kendall Frey but in less bytes.
Since I cannot comment on his answer because I don't have rep I decided to make a new answer.
JavaScript (ES6), 28 26 bytes
Run this code in Firefox 34+ (currently in Aurora)'s Web console
(f=x=>alert`(f=${f})()`)()
Bob, 1221 bytes
c=","; n="\n"; q="\""; s="\\";
v=\[
"c=\",\"; n=\"\\n\"; q=\"\\\"\"; s=\"\\\\\";",
"v=\\[",
"define prtQuote(str) {",
" local j,t,v;",
" stdout.Display(q);",
" for (j=0; j<str.size; j++) {",
" t = str.Substring(j,1);",
" if (t==q) { stdout.Display(s); }",
" if (t==s) { stdout.Display(s); }",
" stdout.Display(t);",
" }",
" stdout.Display(q);",
"}",
"for(i=0; i<2; i++){ stdout.Display(v[i]); stdout.Display(n); }",
"for(i=0; i<v.size-1; i++){ prtQuote(v[i]); stdout.Display(c); stdout.Display(n); }",
"prtQuote(v[v.size-1]); stdout.Display(n);",
"stdout.Display(v[v.size-1]); stdout.Display(n);",
"for(i=2; i<v.size-1; i++){ stdout.Display(v[i]); stdout.Display(n); }",
"];"
];
define prtQuote(str) {
local j,t,v;
stdout.Display(q);
for (j=0; j<str.size; j++) {
t = str.Substring(j,1);
if (t==q) { stdout.Display(s); }
if (t==s) { stdout.Display(s); }
stdout.Display(t);
}
stdout.Display(q);
}
for(i=0; i<2; i++){ stdout.Display(v[i]); stdout.Display(n); }
for(i=0; i<v.size-1; i++){ prtQuote(v[i]); stdout.Display(c); stdout.Display(n); }
prtQuote(v[v.size-1]); stdout.Display(n);
stdout.Display(v[v.size-1]); stdout.Display(n);
for(i=2; i<v.size-1; i++){ stdout.Display(v[i]); stdout.Display(n); }
ABAP, 515 bytes
REPORT R NO STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:
`REPORT.FORM F TABLES T.NEW-PAGE LINE-SIZE 78.WRITE:'REPORT R NO',` TO A,
`'STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:'.LOOP` TO A,
`AT T.REPLACE ALL OCCURENCES OF'``' IN T WITH'````'.WRITE:/'``'` TO A,
`NO-GAP,T NO-GAP,'`` TO A,'.ENDLOOP.WRITE:AT 78'.','GENERATE',` TO A,
`'SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.'.ENDFORM.` TO A.
GENERATE SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.
Should work on on any SAP system with SY-SAPRL >= '700'.
MaybeLater, 74 bytes
x="write(('x='+chr(34))+x+(chr(34))+x)"write(('x='+chr(34))+x+(chr(34))+x)
Taxi, 1144 1034 970 bytes
"is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l."is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l.
Please ignore the output to stderr. Who needs a job if you can quine anyway?
How does this work?
Short answer
This quine starts with a string. If you replace the content of that string by <string>, the code looks like "<string>"<string>, which is "<string> twice. Because the string doesn't contain the double quote, we first get the double quote via its character code, concatenate it with the string, then copy the string and concatenate it with itself. Finally, we print the string.
Long answer
under construction
C (tcc), 64 bytes
main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}
could be one problem if compiler not use the stack based way of push arguments.
result of the print (tcc, gcc all in TIO today at last ok (not ok in clang)):
main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}
Octave, 28 bytes
Note: This doesn't work on TIO. I guess it's because TIO doesn't store the command history. It works on the desktop version. I tried it in Octave 4.2.1.
printf('%s',[history(1){:}])
So, what's going on here?
history is a function that can be used to read and manipulate the command history.
history(n) shows the n most recent commands you have typed, numbered:
>> x = 1 + 2;
>> y = x * 3;
>> history(3)
7 x = 1 + 2;
8 y = x * 3;
9 history(3)
As you can see, x = 1 + 2 was the seventh command that was typed after the history was cleared the last time. The command history(3) is included in this list.
Now, history(1) is not a quine, since it gives:
>> history(1)
10 history(1)
However, if you assign the output from history(1) to an output, you'll get:
>> x = history(1)
x =
{
[1,1] = x = history(1)
}
It's still not a quine, but it's something we can work with.
Unwrapping this, and we're a bit closer:
>> [history(1){:}]
ans = [history(1){:}]
Notice that the entire command, including brackets are outputted.
Finally, if we print this as a string, using printf, we get:
>> printf('%s',[history(1){:}])
printf('%s',[history(1){:}])
Note: disp([history(1){:}]) almost works, but it appends a trailing newline.
Proton, 32 30 bytes
-2 bytes thanks to ppperry.
s='s=%rprint(s%%s)'print(s%s)
I swear, if I get a bounty for this...
JavaScript (Firefox), 44 40 bytes
eval(e="alert('eval(e='+uneval(e)+')')")
Not sure how I haven't thought of this before; it's basically exactly the same as the standard function quine (f=_=>alert('f='+f+';f()'))(), but with a string. Funnily enough, I only thought of this while attempting to demonstrate how similar string-based quines are to function-based quines...
A cross-browser version (avoiding uneval) is 72 bytes:
Q='"';q="'";eval(e="alert('Q='+q+Q+q+';q='+Q+q+Q+';eval(e='+Q+e+Q+')')")
Or ES6, 50 bytes:
Q='"';eval(e="alert(`Q='${Q}';eval(e=${Q+e+Q})`)")
Previous answer, 74 bytes
".replace(/.+/,x=>alert(uneval(x)+x))".replace(/.+/,x=>alert(uneval(x)+x))
Simply takes the whole string and prepends its unevaluated form. Note: uneval may not work in all browsers. Here's a cross-browser version at 113 bytes:
".replace(/.+/,x=>alert(q+x+q+x.replace(/\\d/g,q)),q='1')".replace(/.+/,x=>alert(q+x+q+x.replace(/\d/g,q)),q='"')
Original answer, 118 bytes
Now, this certainly isn't a winner, but AFAIK, this is the first ever non-source-reading quine in JS! :D
alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))
How does it work, you ask? Well, if you look closely, you will see that it's really the same thing repeated twice:
alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))
The logic here is to A) place a copy of the real code in a string, and B) orient this string so the program can be split into two identical halves. But how could we get those quotes in there? Well, we could either navigate an insanely difficult path of inserting backslashes before a quote, or use the (painfully long) workaround String.fromCharCode(34) to retrieve one. The latter method is what I chose.
So, this code puts three copies of the string
,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=
in an array, then joins them with quotes (using the mentioned workaround):
,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=
and finally, slices off the unnecessary characters from the beginning and end:
,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=
alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))
This leaves us with the text of the original program, which is alerted to the user.
If the alert is unnecessary, here's a 104-byte alternative:
[A=",A,A].join(String.fromCharCode(34)).slice(48,-3)[A=",A,A].join(String.fromCharCode(34)).slice(48,-3)
PHP, 50 chars
<?printf($s='<?printf($s=%c%s%1$c,39,$s);',39,$s);
I realized I could save four chars by enabling short tags (<?=sprintf becomes <?printf)
I saved four more bytes by reusing one of the values in my printf.
Gaia, 10 bytes
“:ṙpp”:ṙpp
Explanation
“:ṙpp” Push this string.
: Copy it.
ṙ Get the string representation of it.
p Print the string representation.
p Print the string.
C (gcc), 78 70 66 62 bytes
Minus 4 bytes thanks to MD XF (reusing first argument of printf)!
There are a few unprintables in this answer, replaced with ?.
main(){printf("main(){printf(%c%s%1$c,34,'@??');}",34,'@??');}
Here's an xxd:
00000000: 6d61 696e 2829 7b70 7269 6e74 6628 226d main(){printf("m
00000010: 6169 6e28 297b 7072 696e 7466 2825 6325 ain(){printf(%c%
00000020: 7325 3124 632c 3334 2c27 4005 9027 293b s%1$c,34,'@..');
00000030: 7d22 2c33 342c 2740 0590 2729 3b7d }",34,'@..');}
Here's a bash script to generate and execute the program.
62 bytes, part 2
Here's a version that I have tested on my windows machine on gcc (ANSI encoded):
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
Here's the output:
C:\Users\Conor O'Brien\Documents
λ xxd test.c
00000000: 6d61 696e 2829 7b70 7269 6e74 6628 226d main(){printf("m
00000010: 6169 6e28 297b 7072 696e 7466 2825 6325 ain(){printf(%c%
00000020: 7325 3124 632c 3334 2c27 4040 3027 293b s%1$c,34,'@@0');
00000030: 7d22 2c33 342c 2740 4030 2729 3b7d }",34,'@@0');}
C:\Users\Conor O'Brien\Documents
λ cat test.c
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
C:\Users\Conor O'Brien\Documents
λ wc test.c -c
62 test.c
C:\Users\Conor O'Brien\Documents
λ gcc test.c -o test
test.c:1:1: warning: return type defaults to 'int' [-Wimplicit-int]
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
^
test.c: In function 'main':
test.c:1:8: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
^
test.c:1:8: warning: incompatible implicit declaration of built-in function 'printf'
test.c:1:8: note: include '<stdio.h>' or provide a declaration of 'printf'
test.c:1:55: warning: multi-character character constant [-Wmultichar]
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
^
C:\Users\Conor O'Brien\Documents
λ test
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}$c,34,'@@0');}
C:\Users\Conor O'Brien\Documents
λ
66 bytes
main(){printf("main(){printf(%c%s%1$c,34,4195728);}",34,4195728);}
I have no idea why this works, 100% honest here. But dang, is it short. Only 6 bytes longer than the current best.
70 bytes
main(){printf("main(){printf(%c%s%c,34,4195728,34);}",34,4195728,34);}
78 bytes
main(){printf("main(){printf(%c%s%c,34,%c%c+8,34,34,34);}",34,""+8,34,34,34);}
Foam, 15 bytes
[. <' |: ~|]: ~
This prints itself with a trailing newline. Without a trailing newline:
[. .' |: ~|]: ~
Zsh, 17 bytes
sed p<<a
sed p<<a
JScript, 175 bytes
WScript.Echo((k="WScript.Echo((k=\"%Z\").replace(/%[Z]/,k.replace(/[\"\\\\]/g,function(e){return\"\\\\\"+e})))").replace(/%[Z]/,k.replace(/["\\]/g,function(e){return"\\"+e})))
JScript is Microsoft's implementation of the JavaScript language. On a microsoft console, you can invoke the program as <name>.js, and this will output to a popup. To output to the console, one must use:
cscript //E:JScript //nologo <name>.js
and add a trailing CRLF to the source code.
Husk, 8 bytes
S+s"S+s"
Husk is a new golfing functional language created by me and Zgarb. It is based on Haskell, but has an intelligent inferencer that can "guess" the intended meaning of functions used in a program based on their possible types.
Explanation
This is a quite simple program, composed by just three functions:
S is the S combinator from SKI (typed) combinator calculus: it takes two functions and a third value as arguments and applies the first function to the value and to the second function applied to that value (in code: S f g x = f x (g x)).
This gives us +"S+s"(s"S+s"). s stands for show, the Haskell function to convert something to a string: if show is applied to a string, special characters in the string are escaped and the whole string is wrapped in quotes.
We get then +"S+s""\"S+s\"". Here, + is string concatenation; it could also be numeric addition, but types wouldn't match so the other meaning is chosen by the inferencer.
Our result is then "S+s\"S+s\"", which is a string that gets printed simply as S+s"S+s".
Alice, 45 bytes
Credit to Martin Ender for the use of %, r, and y to obtain the characters "/\ without escaping.
/?.!eO%?.*y1?@~mtz!!4\
\"Y!Z1hrZRoY@*m*h%1Y{/
This program runs entirely in ordinal mode. Because of how ordinal mode programs need to be formatted, this is significantly longer than Martin Ender's cardinal mode quine.
In ordinal mode, the instruction pointer moves diagonally, and commands work on strings instead of integers. The diagonal movement is what makes this tricky: there is even a challenge specifically about formatting a program for ordinal mode. While it's possible to sidestep the entire issue by putting the same string on both lines, this approach ends up slightly longer at 52 bytes.
\".!e1%r.Ryh?*.Ooo1m@z1!{
\".!e1%r.Ryh?*.Ooo1m@z1!{/
Explanation
This is a standard template for ordinal mode, with an additional mirror to allow the program to loop back to the beginning. Linearized, the code is as follows:
".!e1%r.RyY?*~*t%!Y4?Y!ZOh?Z*o1@@mmhz1!{
As with many Fungeoid quines, the " wraps around to itself and puts this entire program in a string literal. Since string mode treats mirrors as mirrors (instead of literals), the string that gets pushed is exactly the linearized code, excluding the ".
.! Duplicate the string, and move the copy to tape
e1% Split on "1", placing "@@mmhz" and "!{" on top of the stack.
The other two parts are irrelevant.
r Expand !{ into the entire range from code point 33 to 123.
.R Duplicate and reverse this range
y Modify the string @@mmhz by changing every character in the range 33-123
with the corresponding character in the reversed range.
The result of this transformation is \\//4" .
This allows us to get these characters without escaping them.
Y?*~* Split this string in half by unzipping, and put the halves on either
side of the original string. The new string is \/"sourcecode\/4 .
t% Extract the newly added 4 at the end, and use it to split on the single 4 in the code.
At this point, we have two strings corresponding to approximately half of the code. The top of the stack has the second half of the program and the right side mirrors, and corresponds to these output bytes:
? ! O ? * 1 @ m z ! \
Y Z h Z o @ m h 1 {/
The string below that has the first half of the program, along with the left side mirrors and quote:
/ . e % . y ? ~ t !
\" ! 1 r R Y * * % Y
Neither string currently contains the 4 that was used to split the string.
! Move second half string to the tape.
Y Unzip first half: the top of the stack now contains the characters
from the first half that will end up in the first row of the output.
4 Append the digit 4 to this string.
?Y Copy second half back from tape and unzip: the top of the stack contains
characters from the second half that will end up in the second row
! Move this onto the tape.
Z Zip the two halves of the first row together.
O Output this with a linefeed.
h Temporarily remove the initial \ so the next zip will work right.
?Z Copy the string back from the tape, and zip the second row together.
This Z isn't the exact inverse of Y since the second half is longer.
The resulting behavior is exactly what we want.
*o Join with the previously removed \ and output.
1 Append 1 to the irrelevant string on the top of the stack.
@ Terminate.
The 52-byte quine works on exactly the same principle, except that it doesn't need the ordinal formatting section of the 45-byte quine.
Mathcad, 94 characters
f:(c{"f:(c{"")]concat(substr(c,0,6),c,substr(c,6,41))")]concat(substr(c,0,6),c,substr(c,6,41))
Watch out for quotation marks autocompletion in the editor!
This should create a parameterless function f which returns its own code.
This quine makes use of (another) weird feature of Mathcad: you can put as much quotation marks inside a string as you like. No idea how they handle it...
Triangular, 18337
...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<>HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp...HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH``
Since this contains un-printables here's a pastebin. Try it online!
Explanation
Here is the relevant portion of the code with a line breaks where they would be inserted:
,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<
>HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp...HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH`
`
The Hs are there because they are easier to print than ., but they have the same function, so I'll replace them and all the other noops with .:
,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<
>................................................33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp.................................................`
`
Like most quines this comes in two parts, an encoder and a decoder. The encoder is the line full of numbers and the decoder is the line full of symbols. Each pair of numbers in the encoder represents a single character in the decoder. Once we have encoded we get pushed down to the decoder.
The first thing in the encoder (besides 33pp which is just there for spacing) is ). This tells triangular to jump back to the start of the most recent loop. However since we have not opened a loop there is nothing to go back to so it does nothing. This will be used later to yoyo the ip when we don't want it to run the decoder.
We then store - to the register with 95*P, this will be used to create both , and .. We then push 189 which is the number of blank lines before the code starts. We use this and a loop to generate all the empty lines before the code starts.
(:(dUi@p]pd]
Once our loop is done we add the , with pUd@p. Now we are ready to decode the encoder, this is done with the simple loop:
(%p%p]
Each %p prints one of the numbers off the top of the stack. We have two of them because some of the numbers have zero as their second digit, meaning in order to get the loop to go through all the encoder we need to print them two at a time.
Once the encoder has been printed we print <> which makes up the two redirects that are needed.
562**@2+@p
Now we need to fetch another copy of the encoder. To start we open a loop with ( this will be closed by the ) we encountered earlier allowing us to spring back to where we were first.
But first we have to run through the decoding section once. The decoding section combines the two numbers as a double digit number in base 10 and adds 18 to the result, since our stack is currently empty this will decode to 18 directly. Thats what accounts for the unprintable in the quine. Once we have "decoded" a character we run through the bit of the program that creates the padding, we make half the padding and leave the other half to be made later. Next up we is the code that makes the backticks. Since we absolutely cannot have any of these just lying around we subtract the register from the result to makes some significantly less harmful 3s. Lastly we use the check the contents of the register, exiting on zero. Since we don't have anything we continue on for later. In order to make sure the next run does terminate we put a 0 in the register.
The ip runs through the encoder again and gets yoyo'd back to our decoder again.
Now we are ready to decode everything. The first loop
(9i*+92*+@p]p
Converts to base 10 adds 18 and outputs, it does this until we have emptied the stack.
Next up we create the padding. We already created half the padding the first run through so we only have half left.
86*dd(d89*@p]p
Once again we pad with H because its cheaper to make than . in this situation.
Now we make the backticks. We make them using 843** and subtract the contents of the register using U-, since we previously set the register to zero we output backtick this time.
Now we exit by checking the contents of the register:
U0P!&
(there are also 3 ps at the end of the code, I don't know why they need to be there but they do, a bunch of weird characters end up in the output otherwise)
Micro, 5 bytes
{_BS}
Explination:
{_BS}
{ start a code block (this block will be run due to implicit evaluation)
_ push the item most recently popped. this pushes the code block which was popped due to implicit evaluation
BS} convert the code block to a string, and end the block. Micro's implicit evaluation is weird, because the evaluated variable may generate new items on the stack, in which case the program's execution will continue as if it hadn't ended. this second implicit evaluation displays the string which is left on the stack: "{_BS}", and ends execution.
QBIC, 8 bytes
?A+@?A+@
I was trying to do this, but I accidentally golfed an actual quine. Whadda you know?
Explanation
? Print
A A$
+ concatenated with
@ a string literal containing
?A+@ "?A+@"
When A$ is used the first time, it might not seem to have a value yet, but it already contains the string literal ?A+@ because the QBIC interpreter first scans the code, sees the @, looks up what the first available string variable is (it's A$, because it hasn't been used by other QBIC language features yet), and it then extracts the definition A$ = "?A+@" to the top of the file, and inserts A$ at the place where it found the literal.
Python 3, 54
I have never seen this one before, so here's my fair creation. It is longer than the classical one but it is a single expression.
print(str.format(*['print(str.format(*[{!r}]*2))']*2))
Kotlin, 121 bytes
Nobody cared enough about Kotlin to post it so...
fun main(a:Array<String>){val s="fun main(a:Array<String>){val s=%c%s%1$1c;print(s.format(34,s))}";print(s.format(34,s))}
Go, 112 bytes
As far as I can tell, there's no Go answer here. Here's mine and I think this is the shortest possible.
package main;import.`fmt`;func main(){s:="package main;import.`fmt`;func main(){s:=%q;Printf(s,s)}";Printf(s,s)}
Bash, 54 52 bytes
-2 thanks to Ørjan Johansen
a=\' b='a=\\$a b=$a$b$a\;eval echo \$b';eval echo $b
Excel, 131 bytes
=SUBSTITUTE("=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))",CHAR(64),CHAR(34)&"=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))"&CHAR(34))
Adapted from a program by Dave Burt.
Vim, 27 bytes
ii^V^V^V^[BDuplxbbpp^[BDuplxbbpp
^V being CTRL+V and ^[ being ESC.
The other one is beating mine, but it took a while and I didn't think it was possible.
COBOL, 18808 bytes
This was posted to the mvsHelp forum in 2004. Spaces necessary.
IDENTIFICATION DIVISION.
PROGRAM-ID. GRICE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
SYMBOLIC CHARACTERS FULL-STOP IS 76.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OUTPUT-FILE ASSIGN TO OUTPUT1.
DATA DIVISION.
FILE SECTION.
FD OUTPUT-FILE
RECORDING MODE F
LABEL RECORDS OMITTED.
01 OUTPUT-RECORD PIC X(80).
WORKING-STORAGE SECTION.
01 SUB-X PIC S9(4) COMP.
01 SOURCE-FACSIMILE-AREA.
02 SOURCE-FACSIMILE-DATA.
03 FILLER PIC X(40) VALUE
" IDENTIFICATION DIVISION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" PROGRAM-ID. GRICE. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ENVIRONMENT DIVISION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" CONFIGURATION SECTION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" SPECIAL-NAMES. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" SYMBOLIC CHARACTERS FULL-STOP".
03 FILLER PIC X(40) VALUE
" IS 76. ".
03 FILLER PIC X(40) VALUE
" INPUT-OUTPUT SECTION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" FILE-CONTROL. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" SELECT OUTPUT-FILE ASSIGN TO ".
03 FILLER PIC X(40) VALUE
"OUTPUT1. ".
03 FILLER PIC X(40) VALUE
" DATA DIVISION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" FILE SECTION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" FD OUTPUT-FILE ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" RECORDING MODE F ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" LABEL RECORDS OMITTED. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" 01 OUTPUT-RECORD ".
03 FILLER PIC X(40) VALUE
" PIC X(80). ".
03 FILLER PIC X(40) VALUE
" WORKING-STORAGE SECTION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" 01 SUB-X ".
03 FILLER PIC X(40) VALUE
" PIC S9(4) COMP. ".
03 FILLER PIC X(40) VALUE
" 01 SOURCE-FACSIMILE-AREA. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" 02 SOURCE-FACSIMILE-DATA. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" 03 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X(40) VALUE ".
03 FILLER PIC X(40) VALUE
" 02 SOURCE-FACSIMILE-TABLE RE".
03 FILLER PIC X(40) VALUE
"DEFINES ".
03 FILLER PIC X(40) VALUE
" SOURCE-FACSIMILE-DATA".
03 FILLER PIC X(40) VALUE
". ".
03 FILLER PIC X(40) VALUE
" 03 SOURCE-FACSIMILE OCCU".
03 FILLER PIC X(40) VALUE
"RS 68. ".
03 FILLER PIC X(40) VALUE
" 04 SOURCE-FACSIMILE-".
03 FILLER PIC X(40) VALUE
"ONE PIC X(40). ".
03 FILLER PIC X(40) VALUE
" 04 SOURCE-FACSIMILE-".
03 FILLER PIC X(40) VALUE
"TWO PIC X(40). ".
03 FILLER PIC X(40) VALUE
" 01 FILLER-IMAGE. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" 02 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X(15) VALUE SPACES. ".
03 FILLER PIC X(40) VALUE
" 02 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X VALUE QUOTE. ".
03 FILLER PIC X(40) VALUE
" 02 FILLER-DATA ".
03 FILLER PIC X(40) VALUE
" PIC X(40). ".
03 FILLER PIC X(40) VALUE
" 02 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X VALUE QUOTE. ".
03 FILLER PIC X(40) VALUE
" 02 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X VALUE FULL-STOP. ".
03 FILLER PIC X(40) VALUE
" 02 FILLER ".
03 FILLER PIC X(40) VALUE
" PIC X(22) VALUE SPACES. ".
03 FILLER PIC X(40) VALUE
" PROCEDURE DIVISION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MAIN-LINE SECTION. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ML-1. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" OPEN OUTPUT OUTPUT-FILE. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE 1 TO SUB-X. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ML-2. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE (SUB-X)".
03 FILLER PIC X(40) VALUE
" TO OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" IF SUB-X < 19 ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ADD 1 TO SUB-X ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" GO TO ML-2. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE 1 TO SUB-X. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ML-3. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE (20) TO".
03 FILLER PIC X(40) VALUE
" OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE-ONE (SU".
03 FILLER PIC X(40) VALUE
"B-X) TO FILLER-DATA. ".
03 FILLER PIC X(40) VALUE
" MOVE FILLER-IMAGE TO OUTPUT-R".
03 FILLER PIC X(40) VALUE
"ECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE (20) TO".
03 FILLER PIC X(40) VALUE
" OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE-TWO (SU".
03 FILLER PIC X(40) VALUE
"B-X) TO FILLER-DATA. ".
03 FILLER PIC X(40) VALUE
" MOVE FILLER-IMAGE TO OUTPUT-R".
03 FILLER PIC X(40) VALUE
"ECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" IF SUB-X < 68 ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ADD 1 TO SUB-X ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" GO TO ML-3. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE 21 TO SUB-X. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ML-4. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" MOVE SOURCE-FACSIMILE (SUB-X)".
03 FILLER PIC X(40) VALUE
" TO OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" WRITE OUTPUT-RECORD. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" IF SUB-X < 68 ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ADD 1 TO SUB-X ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" GO TO ML-4. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" ML-99. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" CLOSE OUTPUT-FILE. ".
03 FILLER PIC X(40) VALUE
" ".
03 FILLER PIC X(40) VALUE
" STOP RUN. ".
03 FILLER PIC X(40) VALUE
" ".
02 SOURCE-FACSIMILE-TABLE REDEFINES
SOURCE-FACSIMILE-DATA.
03 SOURCE-FACSIMILE OCCURS 68.
04 SOURCE-FACSIMILE-ONE PIC X(40).
04 SOURCE-FACSIMILE-TWO PIC X(40).
01 FILLER-IMAGE.
02 FILLER PIC X(15) VALUE SPACES.
02 FILLER PIC X VALUE QUOTE.
02 FILLER-DATA PIC X(40).
02 FILLER PIC X VALUE QUOTE.
02 FILLER PIC X VALUE FULL-STOP.
02 FILLER PIC X(22) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-LINE SECTION.
ML-1.
OPEN OUTPUT OUTPUT-FILE.
MOVE 1 TO SUB-X.
ML-2.
MOVE SOURCE-FACSIMILE (SUB-X) TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
IF SUB-X < 19
ADD 1 TO SUB-X
GO TO ML-2.
MOVE 1 TO SUB-X.
ML-3.
MOVE SOURCE-FACSIMILE (20) TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
MOVE SOURCE-FACSIMILE-ONE (SUB-X) TO FILLER-DATA.
MOVE FILLER-IMAGE TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
MOVE SOURCE-FACSIMILE (20) TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
MOVE SOURCE-FACSIMILE-TWO (SUB-X) TO FILLER-DATA.
MOVE FILLER-IMAGE TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
IF SUB-X < 68
ADD 1 TO SUB-X
GO TO ML-3.
MOVE 21 TO SUB-X.
ML-4.
MOVE SOURCE-FACSIMILE (SUB-X) TO OUTPUT-RECORD.
WRITE OUTPUT-RECORD.
IF SUB-X < 68
ADD 1 TO SUB-X
GO TO ML-4.
ML-99.
CLOSE OUTPUT-FILE.
STOP RUN.
///, 204 bytes
/<\>/<\\\\>\\\\\\//P1/<>/<<>\><>/<<>\<>\<>\<>\><>\<>\<>\<>\<>\<>\<>/<>/P<>1<>/P<>2<>/<>/P<<>\<>\><>\<>\<>2<>/P<>1<>/<>/<<>\><>/<<<>\<>\>><>\<>\<>/<>/<<>\<>\><>/<>/P<>1//P<\\>\\2/P1//<\>/<<\\>>\\//<\\>//P1
With some helpful whitespace inserted:
/<\>/<\\\\>\\\\\\/
/P1/
<>/<<>\><>/<<>\<>\<>\<>\><>\<>\<>\<>\<>\<>\<>/<>/P<>1<>/P<>2<>/<>/P<<>\<>\><>\<>\<>2<>/P<>1<>/<>/<<>\><>/<<<>\<>\>><>\<>\<>/<>/<<>\<>\><>/<>/P<>1
/
/P<\\>\\2/P1/
/<\>/<<\\>>\\/
/<\\>//
P1
How it works
- The long third line is the quining data. It is made from the entire rest of the program, with a
P2in the spot where the data itself would fit, and then with the string<>inserted before each character from the set\/12.- It would be harmless to put
<>before all characters in the data, but only these are necessary -\/because they need escaping to be copied, and12because it's vital to have a break insideP1andP2to prevent infinite loops when substituting them.
- It would be harmless to put
- The first substitution changes all the
<>prefixes into<\\>\\\. The\in the source<\>is there to prevent its final printable form from being garbled by the other substitutions. - The second substitution includes the quining data, copying them to the other
P1s in the program. The<\\>\\\prefixes now become<\>\in both copies. - The third substitution copies one of the quining data copies (in the substitution itself) into the middle of the other (at the end of the program), marked by the string
P<\>\2. In the inner copy, the<\>\prefix now becomes<>again. - The fourth substitution changes the inner copy's
<>prefixes into<<\>>\. The change is needed to introduce the final backspace, protecting any following\s and/s that are to be printed. The inner<\>is necessary to prevent this substitution from infinitely looping – just a backslash here wouldn't do, as it would be garbled by the fifth substitution. - The fifth substitution removes all instances of the string
<\>, both those remaining in the outer copy of the quining data, and those produced by the fourth substitution. - Finally, we reach the constructed copy of the program, with suitable backslashes prepended to some characters, ready for printing.
Ceylon, 173 154 bytes
Saved those bytes thanks to Challenger5
shared void run(){print(let(x="""shared void run(){print(let(x=$)x.replaceFirst("$","\"\"\""+x+"\"\"\""));}""")x.replaceFirst("$","\"\"\""+x+"\"\"\""));}
ACL2, 41 bytes
(let((q"(let((q~x0))(cw q q))"))(cw q q))
Babel, 161 bytes
{ "{ '{ ' << dup [val 0x22 0xffffff00 ] dup <- << << -> << ' ' << << ' }' << } !" { '{ ' << dup [val 0x22 0xffffff00 ] dup <- << << -> << ' ' << << '}' << } ! }%
80x86 TASM, 561 bytes
MODEL TINY
.CODE
.STARTUP
DB 177
DB 076
DB 186
DB 044
DB 001
DB 172
DB 180
DB 036
DB 179
DB 004
DB 191
DB 080
DB 001
DB 079
DB 136
DB 037
DB 212
DB 010
DB 004
DB 048
DB 134
DB 196
DB 075
DB 117
DB 244
DB 180
DB 009
DB 205
DB 033
DB 178
DB 071
DB 226
DB 228
DB 178
DB 038
DB 205
DB 033
DB 195
DB 013
DB 010
DB 069
DB 078
DB 068
DB 036
DB 077
DB 079
DB 068
DB 069
DB 076
DB 032
DB 084
DB 073
DB 078
DB 089
DB 013
DB 010
DB 046
DB 067
DB 079
DB 068
DB 069
DB 013
DB 010
DB 046
DB 083
DB 084
DB 065
DB 082
DB 084
DB 085
DB 080
DB 013
DB 010
DB 068
DB 066
DB 032
END
x86/DOS assembly, 4619 bytes
bits 16
org 256
mov ah,64
mov bx,1
mov cx,720
mov dx,b+16
int 33
mov cx,90
mov si,b+16
c:push cx
mov ah,64
mov bx,1
mov cx,6
mov dx,b
int 33
mov cx,7
a:push cx
mov al,[si]
shr al,4
add al,48
cmp al,58
jb g
add al,39
g:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb e
add al,39
e:mov [b+9],al
mov ah,64
mov bx,1
mov cx,5
mov dx,b+6
int 33
pop cx
loop a
mov al,[si]
shr al,4
add al,48
cmp al,58
jb h
add al,39
h:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb n
add al,39
n:mov [b+9],al
mov ah,64
mov bx,1
mov cx,4
mov dx,b+6
int 33
pop cx
loop c
mov ah,64
mov bx,1
mov cx,5
mov dx,b+11
int 33
mov ah,76
int 33
b db 13,10,' db 0x ,',13,10,'end'
db 0x62,0x69,0x74,0x73,0x20,0x31,0x36,0x0d
db 0x0a,0x6f,0x72,0x67,0x20,0x32,0x35,0x36
db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x37,0x32
db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64
db 0x78,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
db 0x69,0x6e,0x74,0x20,0x33,0x33,0x0d,0x0a
db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x39
db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x73
db 0x69,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
db 0x63,0x3a,0x70,0x75,0x73,0x68,0x20,0x63
db 0x78,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
db 0x68,0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f
db 0x76,0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a
db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x36
db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78
db 0x2c,0x62,0x0d,0x0a,0x69,0x6e,0x74,0x20
db 0x33,0x33,0x0d,0x0a,0x6d,0x6f,0x76,0x20
db 0x63,0x78,0x2c,0x37,0x0d,0x0a,0x61,0x3a
db 0x70,0x75,0x73,0x68,0x20,0x63,0x78,0x0d
db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x6c,0x2c
db 0x5b,0x73,0x69,0x5d,0x0d,0x0a,0x73,0x68
db 0x72,0x20,0x61,0x6c,0x2c,0x34,0x0d,0x0a
db 0x61,0x64,0x64,0x20,0x61,0x6c,0x2c,0x34
db 0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20,0x61
db 0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a,0x62
db 0x20,0x67,0x0d,0x0a,0x61,0x64,0x64,0x20
db 0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a,0x67
db 0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62,0x2b
db 0x38,0x5d,0x2c,0x61,0x6c,0x0d,0x0a,0x6c
db 0x6f,0x64,0x73,0x62,0x0d,0x0a,0x61,0x6e
db 0x64,0x20,0x61,0x6c,0x2c,0x31,0x35,0x0d
db 0x0a,0x61,0x64,0x64,0x20,0x61,0x6c,0x2c
db 0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20
db 0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a
db 0x62,0x20,0x65,0x0d,0x0a,0x61,0x64,0x64
db 0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a
db 0x65,0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62
db 0x2b,0x39,0x5d,0x2c,0x61,0x6c,0x0d,0x0a
db 0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c,0x36
db 0x34,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x62
db 0x78,0x2c,0x31,0x0d,0x0a,0x6d,0x6f,0x76
db 0x20,0x63,0x78,0x2c,0x35,0x0d,0x0a,0x6d
db 0x6f,0x76,0x20,0x64,0x78,0x2c,0x62,0x2b
db 0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20,0x33
db 0x33,0x0d,0x0a,0x70,0x6f,0x70,0x20,0x63
db 0x78,0x0d,0x0a,0x6c,0x6f,0x6f,0x70,0x20
db 0x61,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
db 0x6c,0x2c,0x5b,0x73,0x69,0x5d,0x0d,0x0a
db 0x73,0x68,0x72,0x20,0x61,0x6c,0x2c,0x34
db 0x0d,0x0a,0x61,0x64,0x64,0x20,0x61,0x6c
db 0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70
db 0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a
db 0x6a,0x62,0x20,0x68,0x0d,0x0a,0x61,0x64
db 0x64,0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d
db 0x0a,0x68,0x3a,0x6d,0x6f,0x76,0x20,0x5b
db 0x62,0x2b,0x38,0x5d,0x2c,0x61,0x6c,0x0d
db 0x0a,0x6c,0x6f,0x64,0x73,0x62,0x0d,0x0a
db 0x61,0x6e,0x64,0x20,0x61,0x6c,0x2c,0x31
db 0x35,0x0d,0x0a,0x61,0x64,0x64,0x20,0x61
db 0x6c,0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d
db 0x70,0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d
db 0x0a,0x6a,0x62,0x20,0x6e,0x0d,0x0a,0x61
db 0x64,0x64,0x20,0x61,0x6c,0x2c,0x33,0x39
db 0x0d,0x0a,0x6e,0x3a,0x6d,0x6f,0x76,0x20
db 0x5b,0x62,0x2b,0x39,0x5d,0x2c,0x61,0x6c
db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x34,0x0d
db 0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78,0x2c
db 0x62,0x2b,0x36,0x0d,0x0a,0x69,0x6e,0x74
db 0x20,0x33,0x33,0x0d,0x0a,0x70,0x6f,0x70
db 0x20,0x63,0x78,0x0d,0x0a,0x6c,0x6f,0x6f
db 0x70,0x20,0x63,0x0d,0x0a,0x6d,0x6f,0x76
db 0x20,0x61,0x68,0x2c,0x36,0x34,0x0d,0x0a
db 0x6d,0x6f,0x76,0x20,0x62,0x78,0x2c,0x31
db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x63,0x78
db 0x2c,0x35,0x0d,0x0a,0x6d,0x6f,0x76,0x20
db 0x64,0x78,0x2c,0x62,0x2b,0x31,0x31,0x0d
db 0x0a,0x69,0x6e,0x74,0x20,0x33,0x33,0x0d
db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c
db 0x37,0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20
db 0x33,0x33,0x0d,0x0a,0x62,0x20,0x20,0x20
db 0x64,0x62,0x20,0x31,0x33,0x2c,0x31,0x30
db 0x2c,0x27,0x20,0x64,0x62,0x20,0x30,0x78
db 0x20,0x20,0x2c,0x27,0x2c,0x31,0x33,0x2c
db 0x31,0x30,0x2c,0x27,0x65,0x6e,0x64,0x27
end
Turtlèd, 68 63 53 54 bytes (newlines)
rewrote
@##'@r,r,r-{ +.r_}r{ +.r_}'#'@r,r,r-{ +.r_}r{ +.r_}'f
Try it online!
Explanation
@# Set character variable to #. Useful because this cannot occur in string var
# # Set the string var to...
'@r,r,r-{ +.r_}r{ +.r_}' This string (quotes included. coincidental)
'@r,r,r Write out first three chars of program: @##
-{ +.r_}r Write out the string var, then #, move right
{ +.r_} Write out the string var again, write #
'f overwrite last # with f
Charcoal, 64 31 32 (because of newlines)
My first answer in charcoal ever!
Similar to /// and other languages, just straight up ascii would print itself. however that is not payload and also boring, so here is an actual quine.
taking a golfing tip from Ascii-only, and my realisation that the second looping is pointless, I have reduced by >50%
A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια
Explanation
(thanks to ascii-only for making most of this.)
A α Assign to a
´α´´´A´F´α´⁺´´´´´ι´α "α´AFα⁺´´ια", but with ´ escape character with each
character
these are the variable being assigned to, and the
rest of the program that is not the string.
´A Print A to the grid. current grid: "A"
Fα⁺´´ι For each character in a, print ´ + character
this results in the escaped version of the string
which is the literal string that is assigned at the
start. current grid state: "A´α´´´A´F´α´⁺´´´´´ι´α"
α Print a ("α´AFα⁺´´ια"), which is the commands after
the string assignment. final grid state vvv:
"A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια"
[implicitly print the grid: "A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια", the source, with a trailing newline]
><>, 9 bytes
":1-or>o#
Try it online! Exits with an error. Since the top answer reads from its source code, I present this program.
":1-or>o#
"........ capture these characters
: duplicate last character (`#`)
1- decrement it (`"`)
o output it
r reverse the stack
> # loop inner
o output
The # is a very repulsive mirror--anything that touches it will go the other way. In this case, it is functionally the same as <.
Klein, 11 + 6 = 17 bytes
3 additional bytes for the topology argument 001 and another 3 for ASCII output -A.
:?/:2+@> "
Let's start with the topology. The 1 at the end indicates that the north and south edges of the code are mapped to each other in reverse. So if the IP leaves the code through the south edge in the leftmost column, it will re-enter through the north edge in the rightmost column. We use this to skip to the end of the program.
: Duplicate the top of the stack (implicitly zero).
? Skip the next command if that value is non-zero (which it isn't).
/ Reflect the IP north.
The IP leaves through the north edge in the third column from
the left, so it will re-enter from the south edge in the third
column from the right.
> Move east.
":?/:2+@> " Push the code points of the program, except for the quote itself
to the stack.
: Duplicate the top of the stack, now a 32 (the space).
? Skip the next command (the /).
: Duplicate the top of the stack again.
2+ Add 2, to turn the space into a quote.
@ Terminate the program.
Ohm, 22 20 bytes
-2 bytes thanks to Business Cat
"D34'DLaJL"D34'DLaJL
"D34'DLaJL" # Push this string (everything after this)
D # Duplicate
34' # Push the character "
D # Duplicate
L # Print "
a # Swap the top 2 elements
JL # Print the string, ", then the string again.
GNU Make, 52 51 11 bytes
$(value $0)
When called as a function, returns its source code.
And here's a complete makefile that doesn't return its code, but rather prints it:
Q=$(info Q=$(value Q))$(info $$(call Q))
$(call Q)
Explanation
The second line just instantiates the variable, the first one defines it:
$(info Q=$(value Q))$(info $$(call Q))
$(value Q) # Get unexpanded value
$$ # "$" escaped
$(info Q= )$(info (call Q)) # Print the remaining parts
dc, 16 bytes
[91Pn6120568P]dx
Nothing fancy, posting for completeness.
Explanation
[91Pn6120568P]dx
91P # Print "["
n # Print the macro
6120568P # Print "]dx" encoded as a number
[ ]dx # Run macro on its own code
Standard ML (MLton), 60 bytes
";str(chr 34)^it;print(it^it);";str(chr 34)^it;print(it^it);
I previously thought this kind of quine would only work when interpreted, e.g. by the Moscow ML interpreter. However, MLton happily compiles it to a standalone executable, so I guess it's fine.
How it works
Usually one writes val x = <some expression> ; in a SML interpreter to bind the identifier x to result of the evaluation of <some expression>. If the val x = part is omitted, the result is bound to the implicit result identifier it instead.
The quine consists of three declarations:
";str(chr 34)^it;print(it^it);";
A single string, so it = ";str(chr 34)^it;print(it^it);".
str(chr 34)^it;
chr 34 yields the 34th ASCII-character, which is ". str converts the character into a string and the ^-operator performs string concatenation, thus it = "\";str(chr 34)^it;print(it^it);".
print(it^it);
it^it now yields an escaped string version of the source code which is printed to STDOUT with print.
Forth, 105 bytes
S" 2dup 34 83 emit emit space type 34 emit space type" 2dup 34 83 emit emit space type 34 emit space type
Explanation:
S" 2dup 34 83 emit emit space type 34 emit space type" \ push a string
2dup \ duplicate string
34 83 emit emit space \ print 'S" '
type \ print string
34 emit space \ print '" '
type \ print string duplicate
Brainfuck, 404 bytes
->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>>>+++>>>+++>+>>>>>>>++>+++>+++>+>>+++>+++>+>+++>+>+++>+>++>+++>>>+>+>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>+++>+>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>+++>+>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>+[[>>+[>]+>+[<]<-]>>[>]<+<+++[<]<<+]>>>[>]+++>+[+[<++++++++++++++++>-]<++++++++++.<]
I found this quine here; I didn't write it myself. I'm currently trying to understand how it works exactly to add an explanation.
Hack 60 bytes
<?hh printf($p='<?hh printf($p=%c%s%c,39,$p,39);',39,$p,39);
Only language I could think to do it in that I didn't see on the list.
Brachylog (2), 26 bytes, language postdates challenge
"ạ~bAh34∧A~ạj"ạ~bAh34∧A~ạj
A function that returns its own source code. (This can be made into a 28-byte full program by adding w after each occurrence of j.)
Explanation
"ạ~bAh34∧A~ạj"ạ~bAh34∧A~ạj
"ạ~bAh34∧A~ạj" String literal
ạ Convert to list of character codes
~b Prepend an element
h34 so that the first element is 34
A ∧A but work with the entire list
~ạ Convert to string
j Concatenate the string to itself
Cubix, 20 bytes
3434Qu$v@!<"OOw\o;/"
Almost got the \o/...
Net:
3 4
3 4
Q u $ v @ ! < "
O O w \ o ; / "
. .
. .
Try it online
Try it here!
Additional notes
Background story
After being impressed by reading this great answer by @ais523, I started thinking about further golfing the quine. After all, there were quite a few no-ops in there, and that didn't feel very compressed. However, as the technique his answer (and mine as well) uses, requires the code to span full lines, a saving of at least 12 bytes was needed. There was one remark in his explanation that really got me thinking:
On the subject of golfing down this quine further, [...] it'd need [...] some other way to represent the top face of the cube [...]
Then, suddenly, as I stood up and walked away to get something to drink, it struck me: What if the program didn't use character codes, but rather numbers to represent the top face? This is especially short if the number we're printing has 2 digits. Cubix has 3 one-byte instructions for pushing double-digit numbers: N, S and Q, which push 10, 32 and 34 respectively, so this should be pretty golfy, I thought.
The first complication with this idea is that the top face is now filled with useless numbers, so we can't use that anymore. The second complication is that the top face has a size which is the cube size squared, and it needed to have an even size, otherwise one number would also end up on the starting position of the instruction pointer, leading to a polluted stack. Because of these complications, my code needed to fit on a cube of size 2 (which can contain 'only' 24 bytes, so I had to golf off at least 21 bytes). Also, because the top and bottom faces are unusable, I only had 16 effective bytes.
So I started by choosing the number that would become half of the top face. I started out with N (10), but that didn't quite work out because of the approach I was taking to print everything. Either way, I started anew and used S (32) for some reason. That did result in a proper quine, or so I thought. It all worked very well, but the quotes were missing. Then, it occured to me that the Q (34) would be really useful. After all, 34 is the character code of the double quote, which enables us to keep it on the stack, saving (2, in the layout I used then) precious bytes. After I changed the IP route a bit, all that was left was an excercise to fill in the blanks.
How it works
The code can be split up into 5 parts. I'll go over them one by one. Note that we are encoding the middle faces in reverse order because the stack model is first-in-last-out.
Step 1: Printing the top face
The irrelevant instructions have been replaced by no-ops (.). The IP starts the the third line, on the very left, pointing east. The stack is (obviously) empty.
. .
. .
Q u . . . . . .
O O . . . . . .
. .
. .
The IP ends at the leftmost position on the fourth line, pointing west, about to wrap around to the rightmost position on that same line. The instructions executed are (without the control flow character):
QOO
Q # Push 34 (double quotes) to the stack
OO # Output twice as number (the top face)
The stack contains just 34, representlng the last character of the source.
Step 2: Encode the fourth line
This bit pretty much does what you expect it to do: encode the fourth line. The IP starts on the double quote at the end of that line, and goes west while pushing the character codes of every character it lands on until it finds a matching double quote. This matching double quote is also the last character on the fourth line, because the IP wraps again when it reaches the left edge.
Effectively, the IP has moved one position to the left, and the stack now contains the representation of the fourth line in character codes and reverse order.
Step 3: Push another quote
We need to push another quote, and what better way than to recycle the Q at the start of the program by approaching it from the right? This has the added bonus that the IP directly runs into the quote that encodes the third line.
Here's the net version for this step. Irrelevant intructions have been replaced by no-ops again, the no-ops that are executed have been replaced by hashtags (#) for illustration purposes and the IP starts at the last character on the fourth line.
. .
. .
Q u $ . . . . .
. . w \ . . / .
. #
. #
The IP ends on the third line at the first instruction, about to wrap to the end of that line because it's pointing west. The following instructions (excluding control flow) are excecuted:
$uQ
$u # Don't do anthing
Q # Push the double quote
This double quote represents the one at the end of the third line.
Step 4: Encoding the third line
This works exactly the same as step 2, so please look there for an explanation.
Step 5: Print the stack
The stack now contains the fourth and third lines, in reverse order, so all we need to do now, it print it. The IP starts at the penultimate instruction on the third line, moving west. Here's the relevant part of the cube (again, irrelevant parts have been replaced by no-ops).
. .
. .
. . . v @ ! < .
. . . \ o ; / .
. .
. .
This is a loop, as you might have seen/expected. The main body is:
o;
o # Print top of stack as character
; # Delete top of stack
The loop ends if the top item is 0, which only happens when the stack is empty. If the loop ends, the @ is executed, ending the program.
PowerShell, 24 bytes, 21 characters
.($s={".(`$s={$s})"})
I'm going to attempt to explain this, but be forewarned that I'm terrible at explaining myself.
This code sets $s to the following:
".(`$s={$s})"
This recursively sets the variable $s (the first $s is a plain string, but the second $s is the variable $s) in itself and then the block inside parentheses echoes $s, which at time of execution will be the following:
.($s={".(`$s={$s})"})`
Befunge-98 (cfunge), 8 characters
'k<@,k␇
␇ represents a literal BEL character (ASCII 7, or Ctrl-G). (Note also that the program starts with a leading space.)
Note that the k command, which is heavily used here, is somewhat imprecisely defined, and this code is outright exploiting several edge cases at once, making this an example of corner-case code. As such, this is somewhat interpreter-dependent; it doesn't work on TIO, for example. cfunge is the Befunge-98 interpreter I normally use locally (and has been tested to be highly conformant with the specification), and it handles this code correctly. (Update: I've been talking to some Befunge experts about this quine, and the consensus is that it's exploiting a bug in cfunge, not behaviour that's defensible by the specification. Still a valid answer, though, because languages are defined by their implementation and this is the sort of corner case that has no right answers, only wrong answers.)
This program would also work in Unefunge-98 and Trefunge-98, but I'm not sure if any of the pre-existing interpreters for those handle k in the way we need, so it may be noncompeting in those languages.
Verification
$ xxd /tmp/quine.b98
00000000: 2027 6b3c 402c 6b07 'k<@,k.
$ ./cfunge /tmp/quine.b98 | xxd
00000000: 2027 6b3c 402c 6b07 'k<@,k.
Explanation
General principles
We know that in fungeoids, it's normally easiest to wrap a string around the code, so that the code is inside and outside the string literal at the same time. However, another trick for shortening quines is to use a string representation which doesn't need escaping, so that we don't need to spend bytes to represent the string delimiter itself. So I decided to see if these techniques could be combined.
Befunge-98 normally uses " as a string delimiter. However, you can also capture a single character using ', and you can make any command into a sort of lightweight loop (in a confusing and buggy way) using k. As such, k' functions as a sort of makeshift length-prefixed string literal. And of course, a length-prefixed string literal has no problems in escaping its own delimiter, as it doesn't have any sort of string terminator at all, meaning that the entire range of octets (in fact, the entire range of cell values) are available to exist within the string.
We can actually do even better; we no longer have to stop the string at its opening delimiter (we can stop it anywhere), so we can wrap it multiple times around the program to grab not only the k' itself, but also the length of the string (which is in this case written as a character code, thus the literal backspace). The program will continue execution just after the end of the string, i.e. just after the last character captured, which is exactly where we want it. (Bear in mind that Befunge strings are printed in reverse order to pushing them; the most common form, NUL-terminated strings, are called "0gnirts" by the community because of this, and length-prefixed strings follow the same principle. Thus if we want the length to end up at the start of the string, we have to push it last.)
As an extra bonus, this also means that we can wrap multiple times around the program with no penalty; all that matters is that the last character we see is the string length (which is at the end of the program). By an amazing stroke of luck, k' specifies length-prefixed string (sort-of; k is weird), and 'k (the same two characters in reverse order) pushes 107, which happens to loop round the program multiple times and end up in exactly the right place (this only had a 1 in 8 chance of working out). Because we have to reverse the program direction anyway (to read the string in the reverse of the natural reading order, meaning that it gets printed in the same order it appeared in the original program), we can use the same two characters for both pushing the length, and pushing the string itself, at no cost.
Of course, this now captures a risk of counting as a literal-only program, and thus not a proper quine under PPCG rules. Luckily, wrapping round from one end of the program to the other produces a literal space character, and spaces at the ends of the line (i.e. leading and trailing whitespace) aren't captured as part of a string. Thus, if we start the program with a space, we can encode that space (which isn't part of the string literal) via the implicit space that we get from wrapping the program (i.e. the leading space is encoded by the ' next to it, rather than by itself), just sneaking within the proper quine rules. The easiest way to see this is to delete the leading space from the program; you'll get the same output as the program with the leading space (thus effectively proving that it doesn't encode itself, because even if you remove it it still gets printed).
Detailed description
'k<@,k␇
'k Push 107 to the stack
< Set execution delta to leftwards
'k Push the next 107 characters to the stack: "'␠␇k, … @<ck'␠␇"
,k Pop a length from the stack, output that many characters
, Output the top stack element
@ Exit the program
You can note that k has some odd ideas of where to start reading the string from (for the first k that runs), or where to leave the IP afterwards (for the second k that runs); this is just the way k happens to work (you think of k as taking an "argument", the command to run, but it doesn't actually move the IP to skip the "argument"; so if the command inside the loop doesn't affect the IP or the IP's movement, it'll end up being the next command that runs and the loop runs one more time). The literal BEL, ASCII 7, is interpreted by the second k as a loop counter, so the , inside the k will print the first 7 characters, then the , outside the k (which is the same character in the source) will print the 8th just before the program exits.
Alice, 9 bytes
Credits to Sp3000 for the idea of including the !.
"!<@o&9h.
Explanation
This works much like quines in other Fungeoids with an unmatched " that wraps the entire code (except itself) in a string because the instruction pointer move cyclically through the code.
"!<@o&9h." Push code points of the entire program except the " to the
stack (irrelevant).
! Store 46 (the code point of '.') on the tape (irrelevant).
< Send IP back west.
! Store 104 (the code point of 'h') on the tape (irrelevant).
".h9&o@<!" Push code points of the entire program except the " to the
stack in reverse.
. Duplicate the 33 (the code point of '!').
h Increment to 34 (the code point of '"').
Now the top nine values on the stack correspond to the entire
code in reverse order.
9& Repeat the next command 9 times.
o Print 9 characters from the top of the stack.
@ Terminate the program.
Bash, 65 bytes
set -o history
echo "set -o history"
history|tail -n 2|cut -c 8-
Bash disables the command-history function in scripts, but you can turn it on manually with 'set-o history'.
This first command is obviously not stored in the shell's history file, so the second command prints the same text to the terminal.
The third command pulls the last two out of the history file and cleans them up for displaying.
The output matches:
set -o history
echo "set -o history"
history|tail -n 2|cut -c 8-
Mathematica, 68 bytes
Print[#<>ToString[#,InputForm]]&@"Print[#<>ToString[#,InputForm]]&@"
Clojure, 91 bytes
((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))
Scala, 540 Bytes
object Q {
def main(a:Array[String]):Unit={
val d=Seq(
"object Q {",
"def main(a:Array[String]):Unit={",
"val d=Seq(",
"val c=println(_:String)",
"val b=(x:Int)=>x.toChar.toString",
"d take 3 map c",
"val a=d.zipWithIndex.map(x=>b(34)+x._1+b(34)+(if(x._2==d.size-1)b(9).drop(1)else b(44)))",
"a.map(c)",
"c(b(41))",
"d.drop(3).map(c)",
"c(b(125))",
"c(b(125))"
)
val c=println(_:String)
val b=(x:Int)=>x.toChar.toString
d take 3 map c
val a=d.zipWithIndex.map(x=>b(34)+x._1+b(34)+(if(x._2==d.size-1)b(9).drop(1)else b(44)))
a.map(c)
c(b(41))
d.drop(3).map(c)
c(b(125))
c(b(125))
}
}
Can probably be improved. I decided to call it quits for now as it is 5 in the morning. I think something that can be changed to make this smaller is to encode the d value in some other way other than a sequence of strings. I haven't thought of a cool way to do it yet, though. This would also add to the obfuscation part of the challenge.
Forte, 66 bytes
Updated for the new Interpreter
2PUT34:LET1=3
4PUT34:END
1PRINT
"2PUT34:LET1=3
4PUT34:END
1PRINT
"
Which, in order is:
1: Print the first half of the code.
2: Print a ", then set line 3 to be line 1.
3: Print the second half of the code again.
4: Print another ", then end the program.
Vim, 17, 14 keystrokes
Someone randomly upvoted this, so I remembered that it exists. When I re-read it, I thought "Hey, I can do better than that!", so I golfed two bytes off. It's still not the shortest, but at least it's an improvement.
For a long time, I've been wondering if a vim quine is possible. On one hand, it must be possible, since vim is turing complete. But after looking for a vim quine for a really long time, I was unable to find one. I did find this PPCG challenge, but it's closed and not exactly about literal quines. So I decided to make one, since I couldn't find one.
I'm really proud of this answer, because of two firsts:
This is the first quine I have ever made, and
As far as I know, this is the worlds first vim-quine to ever be published! I could be wrong about this, so if you know of one, please let me know.
So, after that long introduction, here it is:
qqX"qpAq@q<esc>q@q
Note that when you type this out, it will display the <esc> keystroke as ^[. This is still accurate, since ^[ represents 0x1B, which is escape in ASCII, and the way vim internally represents the <esc> key.
Also note, that testing this might fail if you load an existing vim session. I wrote a tips answer explaining that here, if you want more information, but basically you need to launch vim with
vim -u NONE -N -i NONE
or type qqq before running this.
Explanation:
qq " Start recording into register 'q'
X " Delete one character before the cursor (Once we play this back, it will delete the '@')
"qp " Paste register 'q'
Aq@q<esc> " Append 'q@q' to this line
q " Stop recording
@q " Playback register 'q'
On a side note, this answer is probably a world record for most 'q's in a PPCG answer, or something.
k, 48 bytes
This is, of course, ignoring the trivial quines, such as () or 1.
{}`0:(`c$34)/{(x;x;())}"{}`0:(`c$34)/{(x;x;())}"
AWK, 72 bytes
BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}
In 6 years nobody had written an AWK solution :(
This can be run from command-line as:
awk 'BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}'
or placed in a file, FILE and run as:
awk -f FILE
Note: no newline is printed so if storing in a file... the file shouldn't have an EOF in it... maybe? We can add an EOF by adding print statements but that adds 12 bytes.
This happens to be my first ever quine. :) It took me a bit to figure out how to get the quotation marks, since I first wanted to use \" but I'd have to escape the \ and then escape that one... ASCII to the rescue :)
Pip, 15 bytes
V Y"`V Y`.RPy"
The code includes a trailing newline. Try it online!
Explanation
Y"..." Yank this string into the y variable
V and evaluate it
which executes this:
`V Y` A Pattern literal (for our purposes, a string-like object without "")
. to which we concatenate
RPy repr(y), which wraps y in ""
The result is autoprinted with a trailing newline.
Bonus submission, 18 bytes
The above is the shortest Pip quine that I've found, but unfortunately it doesn't do so well when you try to modify it for other quine challenges. I have found this one to be more payload-friendly:
Y"Y yRsRPy"yRsRPy
Y"Y yRsRPy" Yank that string into y
yRsRPy Take y and replace space with repr(y)
Racket, 90 bytes
((lambda (x) (display (list (~a x) (~v x)))) '(lambda (x) (display (list (~a x) (~v x)))))
ಠ_ಠ, 6 bytes
ಠಠ
This used to work back when the interpreter was still buggy but that's fixed now. However, you can try it in the legacy version of the interpreter!
Threead, 85 bytes
>93>60>111>99>91>60>93>62>111>100>111>99>50>54>105>91>62>93>60>91[<]>[i62codo>]<[co<]
>93>60>...60>91 # Encodes the second part backwards
[<]> # Go back to the begining
[ ] # for every number
i # insert an extra cell
62co # print a '>'
d # delete the cell
o # print the original number in this cell
> # go to the next cell
<[ <] # for every cell in reverse order
co # print the character that it represents
Threead, 101 bytes
>91>60>93>62>91>105>54>50>99>111>100>111>62>93>60>91>60>93>62>91>99>111>62>93[<]>[i62codo>]<[<]>[co>]
My first thought for writing a Threead quine was to store the entire data section as one large number, in order to get a good compression ratio. This doesn't work because a) % appears to be broken, and b) Threead doesn't support bignum arithmetic.
Instead, I wrote this solution, which works along the same lines as a brainfuck quine, storing the characters of the code section of the program as individual tape elements. Then we just have to scan the list once in order to print it as data, and again to print it as code.
Although Threead allows for three threads, and requires their use when performing binary operations, this style of quine uses only unary operations and thus there was no point in using more than one thread, so I just did everything inside the first.
Explanation
>91>60>…>62>93 ASCII character codes of the rest of the program
[<]> Return the pointer to the start of the data
[ While the current data cell is nonzero:
i62 Place 62 (ASCII code of >) on a temporary tape cell
co Output it as a character (i.e. >)
d Delete the temporary tape cell
o Output the current data element as an integer
>] then continue the loop with the next data cell
<[<]> Return the pointer to the start of the data
[ While the current data cell is nonzero:
co Output it as a character
>] then continue the loop with the next data cell
Befunge-93, 17 bytes
Thanks to James Holderness for pointing out that this relies on nonstandard interpreter behavior
Slightly late to the party, but here goes!
<@,*2+98_,#! #:<"
Try it here, but you have to copy-paste the code. The program relies on nonstandard interpreter behavior, so it'll print a bunch of leading spaces on TIO. Oops. My bad.
<: sets the program direction to "left"; instruction pointer wraps around
": toggles string mode (pushes ascii value of every character until next ", which it encounters only when it wraps around)
(at this point, it pushes every character to the stack & wraps around. This is where it relies on nonstandard behavior - TIO and the reference interpreter would push a bunch of spaces to the stack)
:<: sets the instruction pointer direction to "left" and duplicates top of stack
! #: negates the value at the top (important because of the upcoming _); # skips the next character
_,#: checks the value at the top of the stack & pops it: prints the ascii value as a character of the new top and sets the direction of the instruction pointer to right if checked character was 0; else sets the direction of the instruction pointer to left
@,*2+98: prints the " at the end of the program and quits.
Threead, 24 bytes
">34co<o>o<o">34co<o>o<o
I didn't think to do it like this until I saw Riley's answer. I have no intention to self-award the bounty, so this is non-competitive for it.
Explanation
">34co<o>o<o">34co<o>o<o
">34co<o>o<o" # Encodes the right half of the program as a string, in the 1st buffer.
> # Move to the 2nd buffer.
34c # Put the string represented by ascii 34 (") in the second buffer.
o # Write it to STDOUT
<o # Move to the 1st buffer, Write the contents of the string to STDOUT.
>o # Move back to the 2nd Buffer, write it.
<o # Move back to the 1st Buffer, write it.
Originally... 129 Bytes...
My plan was to use:
"\x0E\x0E\x0E78g\x0EBv$/s@$@c8$$$$$vB\x0Ep$/c6Bb_$f$vgs@$/Bba\x0E$$$c5$$$$$1c5$$$$p"
34c
>r +o< <_4 r>
l +_2>^[ b rco< +>^]
_1 -_1 l
where \x0E is the literal SOH.
The string is simply all the commands after it, but with a byte value 4 higher. This was because I can't store a " or a \ in the string, without it getting meta. The rest of the script, acts kind of like my other solution, however manually iterates through the string, printing each character -4.
Logicode, 1368 1241 1096 1086 bytes
var a=000101011000111101001111001011000110100000111000001010001100101010100101011010111110110001111011111101110110010001000001100101010110101111101000000010100011001010111100010101111001010111110011110001010111100101011111001111100111100010101111001010111110011111001111100111100010101111001010111110011111001111100111110011110001010111100101011111001111100111110011111001111100111100010101111001010111110011111001111100111110011111001111100111100010100101010111110000010100011001010111110011111001111100111110011111001111100111110010100101011111100101000101011011111110101111010001000001110000010100001100010110001011000101100000110001011000101100000110001011000101100000110000011000001100000110001011000101100010110001011000001100000110001011000001100000110001011000001100000110000011000001100000110001011000101100000110000011000001100000110001011000001100010110001011000101100010110000011000101010010101011110000101010111110000010100011000010101001
circ p(e)->cond e->@(e<+e><+e>><+e>>><+e>>>><+e>>>>><+e>>>>>><)+p(e>>>>>>>)/e
out p(111011011000011110010010000011000010111101)+a+p(a)
Explanation
This is pretty simple as far as Quines go. The first line of the program assigns a very long list of ones and zeros to a variable called a this is the binary representation of the last two lines of the program with each character represented by 7 bits.
Then I define a function that takes in a binary string and returns it as a ASCII string.
This works pretty simply:
circ p(e)-> #Function header
cond e-> #If e is non empty
@(e<+e><+e>><+e>>><+e>>>><+e>>>>><+e>>>>>><) #return the ASCII character made by the first 7 bit
+ #plus
p(e>>>>>>>) #p of the rest of the string
/ #otherwise
e #return e (i.e. the empty string)
Then on the last line we print var a= the binary string and the ASCII representation of the binary string.
R, 47 bytes
f=function(){cat('f=');print(f);cat('f()')}
f()
Can be extended to contain any set of operations by adding those before the first cat statement.
Printing a function f returns the content of that function starting with function(){. I then added cat statements to handle the rest of the output.
D, 85 bytes
enum c=q{import std.stdio;void main(){write("enum c=q{"~c~"};mixin(c);");}};mixin(c);
Mini-Flak, 6900 bytes
Mini-flak is a Turing complete subset of Brain-Flak. It works exactly like Brain-Flak except the [], <> and <...> operations are banned from use. Programming in Min-Flak is thus much more difficult than traditional Brain-Flak.
The main difficulty with Mini-Flak is the lack of random access. While Mini-flak is Turing complete, location of access (relative to the top of the stack) must be determined at compile time rather than run time.
The following is the quine. Unfortunately this quine has an order notation of O(7**n) (where n is its own length) and thus cannot be run to completion in the lifetime of the universe. I will hopefully convince you that it does work but for now you will have to trust me a bit. If you want a version that can be run in the lifetime of the universe (or an afternoon) you can scroll down a bit to my faster version.
(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()()()()())(())(())(())(())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()()())(()()()()()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()()()()()())(()()()()())(()()()()()())(())(())(()()()()())(()()()()()())(()())(()()())(())(()()()()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(())(()()())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(())(()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()())(()())(()()()()())(()()()()())(()()()()()())(())(()()())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(())(())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(())(()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(())(()()())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(())(()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()())(()())(()()()()())(()()()()())(()()()()()())(())(()()())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(())(())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(()())(()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(({}({}))[({}[{}])]){((((((({}({}))[({}[{}])])){})){}{}{}{}({}))[({}[{}])])}{}(({})[({(({}[(((()()()){}()))]{})([((({}({}))[({}[{}])]))]{})){({}[()((({}()[({})])){{}([(({}({}[(({}[()]))]{})))]{})}{})]{})}(({}{}[({})]{}({}))[({}[{}])(({}[()(((((()()()()()){}){}){}))]{}){([(({}[()(({}()))]{}){([(({}[()((({}){}((()()())){}{}))]{}){([(({}[()(({}()()))]{}){([(({}[()(({}(((()()()()())){}{}){}))]{}){([({}({}()()))]{})}{})]{})}{})]{})}{})]{})}{})]{})}{})]{})}{})]{}){(({}[(((()()()){}()))]{})([((({}({}))[({}[{}])]))]{})){({}[()((({}()[({})])){{}([(({}({}[(({}[()]))]{})))]{})}{})]{})}(({}{}[({})]{}({}))[({}[{}])(({}[(((((()()()()()){}){}){}()))]{}){({}[()((((((()()()()()){}){}){}())[()]))]{})}{}((((()()()()()){}){}){}))]{})}{}
Explanation
Like my previous Brain-Flak quine This program has two parts. The first part pushes numbers between 1 and 6 to the stack representing the second part of the program using the following key.
1 -> (
2 -> )
3 -> [
4 -> ]
5 -> {
6 -> }
(Since there is no <> in Mini-Flak those characters are left unencoded). It does this in a deterministic fashion so that this section can be reversed by the next section.
The second section is a decoder. It takes the output from the first section and turns it into the code that generates that list and the code represented by that list (this section's source). However this is easier said than done. Because of Mini-Flak's lack of random access we are going to need to abandon Brain-Flak's traditional techniques in favor of some more bizarre methods. This program starts by compressing the entire stack into one base 7 number where each digit is one number in the list. It does that with the following code:
(({}({}))[({}[{}])]){(({}({}))[({}[{}])])((((({})){})){}{}{}{})(({}({}))[({}[{}])])}{}
This is a pretty straightforward (as far as Mini-Flak goes) program and I won't get into how it works unless any one is interested. (It is a neat little program but to save space I will leave it out).
We now have one single number representing the entire program. I will push a copy to "temporary memory" (the scope) like follows:
(({})[(...)]{})
And decompose the original copy via repeated devision. Each time I remove a digit from the number I will convert it to the code that generates it.
Once I am done with that, the program will put the copy stored in temporary memory back down and begin a second decomposition. This time it will map each digit to the ASCII value of its corresponding brace as it is decomposed from the total.
Once that is done the program has constructed it's source so it simply terminates.
Verification
You might be suspicious of my program. How can we know that it actually works if it won't terminate in the lifetime of the universe?
So I have set up a "toy version" of the original quine to demonstrate that all of the parts are working.
This version has the first part removed. You can pass the list of numbers that would be generated by the first part as command line arguments. It will construct code that pushes them and the code they represent. I provided a simple test case but I encourage you to try it out with your own! You will notice even with only six characters the run times are starting to become noticeably long. This is because the division I use is O(n). Slow division has always been a reality in Brain-Flak and it carries over into Mini-Flak.
If you have any questions or confusions comment them and I will be happy to address them.
106656 bytes
Now for my fast version.
This version takes about half an hour (175300470 Brain-Flak cycles) to run on my machine using the ruby interpreter. But for the best performance I suggest you use Crain-Flak the C interpreter which is much faster but lacks some of the polish of the ruby interpreter.
Explanation
The reason that Miniflak quines are destined to be slow is Miniflak's lack of random access. In the short but slow version (short is a bit of an exaggeration and slow an understatement) I get around this by pushing all the numbers and then packaging them up into one number and unrolling it piece by piece. However this version does it quite differently. I create a block of code that takes in a number and returns a datum. Each datum represents a single character like before and the main code simply queries this block for each one at a time. This essentially works as a block of random access memory.
To construct this block I actually reused a method from my proof that Miniflak is Turing complete. For each datum there is a block of code that looks like this:
(({}[()])[(())]()){(([({}{})]{}))}{}{(([({}{}(%s))]{}))}{}
This subtracts one from the number on top of the stack and if zero pushes %s the datum beneath it. Since each piece decrements the size by one if you start with n on the stack you will get back the nth datum.
This is nice and modular, so it can be written by a program easily.
Next we have to set up the machine that actually translates this memory into the source. This consists of 5 parts as such:
([()]())(()()()())
{({}[(
-
)]{})
1. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}{}{}
(((((((((((((((((((((((((((()()()()()){}){}){})((((()()()()){}){}())){}{})(((()()()()){}){}()){})[()()])[((((()()()()()){}){}){}()){}()])((((()()()()()){}){}){}()){}())[((((()()()()()){}){}){}()){}]))[()])())[()])())[()])())[()]))()))[()])((((()()()){}){}()){}){}())[((((()()()){}){}()){}){}])[()])((((()()()()){}){}())){}{})[((((()()()()){}){}())){}{}])
(()()()())
)]{})}{}
2. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}
(({}(({}({}))[({}[{}])][(
({}[()(
([()](((()()[(((((((()()()){})())){}{}){}){})]((((()()()()())){}{}){})([{}]([()()](({})(([{}](()()([()()](((((({}){}){}())){}){}{}))))))))))))
)]{})
{({}[()(((({})())[()]))]{})}{}
(([(((((()()()()){}){}()))){}{}([({})]((({})){}{}))]()()([()()]({}(({})([()]([({}())](({})([({}[()])]()(({})(([()](([({}()())]()({}([()](([((((((()()()())()){}){}){}()){})]({}()(([(((((({})){}){}())){}{})]({}([((((({}())){}){}){}()){}()](([()()])(()()({}(((((({}())())){}{}){}){}([((((({}))){}()){}){}]([((({}[()])){}{}){}]([()()](((((({}())){}{}){}){})(([{}](()()([()()](()()(((((()()()()()){}){}){}()){}()(([((((((()()()())){}){}())){}{})]({}([((((({})()){}){}){}()){}()](([()()])(()()({}(((((({}){}){}())){}){}{}(({})))))))))))))))))))))))))))))))))))))))))))))))
)]{})[()]))({()([({})]{})}{}()()()())
)]{})}{}
3. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}
(({}[(
({}[()(((((()()()()()){}){}){}))]{}){({}[()(({}()))]{}){({}[()(({}((((()()()){}){}){}()){}))]{}){({}[()(({}()()))]{}){({}[()(({}(((()()()()())){}{}){}))]{}){([(({}{}()))]{})}}}}}{}
(({}({}))[({}[{}])])
)]{}({})[()]))
({()([({}({}[({})]))]{})}{}()()()()[(({}({})))]{})
)]{})}{}
4. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}(([{}]))(()()()()))]{})}{}
({}[()])
}{}
The machine consists of four parts that are run in reverse starting with 4 and ending with 1. I have labeled them in the code above. Each section also uses the same lookup table format I use for the encoding. This is because the entire program is contained in a loop and we don't want to run every section every time we run through the loop so we put in the same RA structure and query the section we desire each time.
4
Section 4 is a simple set up section.
The program tells first queries section 4 and datum 0. Datum 0 does not exist so instead of returning that value it simply decrements the query once for each datum. This is useful because we can use the result to determine the number of data, which will become important in future sections. Section 4 records the number of data by negativizing the result and queries Section 3 and the last datum. The only problem is we cannot query section 3 directly. Since there is another decrement left we need to query a section 4. In fact this will be the case every time we query a section within another section. I will ignore this in my explanation however if you are looking a the code just remember 4 means go back a section and 5 means run the same section again.
3
Section 3 decodes the data into the characters that make up the code after the data block. Each time it expects the stack to appear as so:
Previous query
Result of query
Number of data
Junk we shouldn't touch...
It maps each possible result (a number from 1 to 6) to one of the six valid Miniflak characters ((){}[]) and places it below the number of data with the "Junk we shouldn't touch". This gets us a stack like:
Previous query
Number of data
Junk we shouldn't touch...
From here we need to either query the next datum or if we have queried them all move to section 2. Previous query is not actually the exact query sent out but rather the query minus the number of data in the block. This is because each datum decrements the query by one so the query comes out quite mangled. To generate the next query we add a copy of the number of data and subtract one. Now our stack looks like:
Next query
Number of data
Junk we shouldn't touch...
If our next query is zero we have read all the memory needed in section 3 so we add the number of data to the query again and slap a 4 on top of the stack to move onto section 2. If the next query is not zero we put a 5 on the stack to run section 3 again.
2
Section 2 makes the block of data by querying our RAM just as section 3 does.
For the sake of brevity I will omit most of the details of how section 2 works. It is almost identical to section 3 except instead of translating each datum into one character it translates each into a lengthy chunk of code representing its entry in the RAM. When section 2 is done it calls on section 1.
1
Section one is the most simple section.
It pushes the first bit of the quine ([()]())(()()()()){({}[( and defers to section 5.
5
There is no real section 5 instead a 5 will be decremented once by each section, entering none of them and the once more by the decrement hanging around at the end of the loop. This will result in a zero and will exit the main loop terminating the program.
I hope this was clear. Please comment if you are confused about anything.
Python 3, 38 bytes
There are already a lot of Python quines, but as far as I can see this one hasn't been posted yet. Technically it is a statement that evaluates to a string representation of itself, but other submissions do similar things.
'.__repr__()[:-1]*2'.__repr__()[:-1]*2
This works in a similar way to many quines in 2D langauges with "edge-wrap", where "string mode" is entered, the whole program is pushed to the stack, then string mode is executed and the program runs, printing the string mode character (usually ") followed by the contents of the stack (i.e. the program's source) then exiting.
A breakdown of the statement is as follows:
'.__repr__()[:-1]*2' # A string containing the body of the program.
# .__repr__()[:-1]*2
.__repr__() # The same string, but enclosed in single quote marks.
# '.__repr__()[:-1]*2'
[:-1] # A splice that crops off the last character.
# '.__repr__()[:-1]*2
*2 # Repeat the string.
# '.__repr__()[:-1]*2'.__repr__()[:-1]*2
The reason I have used .__repr__() instead of repr(string) is because the quine relies on code following and not preceding the string. This is also why this is a statement and not a program; the print() function requires code before the string, which is not possible with this quine layout.
As you may have noticed, there's a much golfier statement that evaluates to this statement:
"'.__repr__()[:-1]*2"*2
But this isn't a quine, because it doesn't evaluate to itself.
SimpleTemplate, 56 bytes
This is a template engine language I've made for fun.
It was written in PHP and run by compiling the weird syntax to PHP.
This answer is a translation of Aurel Bílý's amazing PHP answer!
{@setF"{@setF%c%s%c}{@printF,34,F,34}"}{@printF,34,F,34}
Weird, right?
This works with the commit d1d3e2c43bd98da2bd38f884ee5ac7b39cb8c579 on my Github and you can try it on http://sandbox.onlinephpfunctions.com/code/cca9ed3b9c87abad61159725f159285e5daf9bb9.
In there, you will have the existing code on that commit, plus showing the result and the generated PHP.
Java 8, 94 bytes
()->{String s="()->{String s=%c%s%1$c;System.out.printf(s,34,s);}";System.out.printf(s,34,s);}
This is a lambda expression which prints its own source code to STDOUT. It uses a similar tactic to other Java quines here, but the lambda really helps cut down bytes.
If we wanted to be really cheeky and cut down two bytes, we could declare the lambda as x->, where x is an empty string, as according to meta, "taking no input" means you can assume empty input, and in function submissions input is given as a parameter.
Pyke, 14 bytes
"34.Cp\D\Es"DE
"34.Cp\D\Es" - "34.Cp\D\Es"
DE - eval(^, stack=^)
34.C - '"'
p - print(^)
\D\Es - sum("34.Cp\D\Es", ^, "D", "E")
Forth (gforth), 21 bytes
: x
latest name-see ;
This prints the decompiled source of the latest word, thus only works if x is the latest defined word.
Test:
x
: x
latest name-see ; ok
This one works without that condition, but replaces the constant definition with it's value (since that's the only thing that actually gets saved to memory)
: x
[ latest ] literal name-see ;
Test:
x
: x
140121195205104 name-see ; ok
Actually, 4 bytes
0
0
Note the trailing linefeed. Try it online!
This exploits a potential flaw in our definition of proper quine:
It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)
Furthermore, a quine must not access its own source, directly or indirectly.
The stack of Actually is printed backwards, so the first 0 encodes the second 0, and vice versa.
This can be verified empirically; the program
1
2
prints
2
1
Haystack, 7 bytes
Yay, my first quine!
"34c,o|
Explanation
This is a standard 2D quine.
" starts to push a string
34c,o| part of the string
" it wraps around and go to the beginning of this line thus pushing the string
34 push this number
c output as character (ie outputs ")
, discard this value
o output the top of stack (ie 34c,o|)
| end program
Cheddar, 56 bytes
let q='let q=%s%s%s;print IO.sprintf(q,@"39,q,@"39)';print IO.sprintf(q,@"39,q,@"39)
See the explanation below, except mentally replace % with IO.sprintf.
Well darn. @ETHProductions came up with this solution before me..
This is the shortest I could come up with... Maybe some abuse of functional operators could help me.
let q='let q=%s;print q%@"39+q+@"39';print q%@"39+q+@"39
Try it online! You can guess what the output is.
This code can be divided into two parts: the string and the output. The string part:
let q='let q=%s;print q%@"39+q+@"39';
is simply a formatting template.
The output part:
;print q%@"39+q+@"39
formats the string. @"39 is char 39, or '.
stacked, 16 bytes
[put ':!' put]:!
[put ':!' put] is a func, which is pushed to the stack. : duplicates it, and ! executes it, which prints the function, then :!.
Zetaplex, 13 bytes
"Sr34SZOsDrFe
Zetaplex is a variant of gammaplex. In it, commands are pairs of chars and act on an infinite stack.
Cubix, 45 bytes
.....>...R$R....W..^".<R.!'.\)!'"R@>>o;?/o'u"
You can test this code here.
This program is fairly hard to follow, but to have any chance to do so, we need to start by expanding it into a cube, like the Cubix interpreter does:
. . .
. . >
. . .
R $ R . . . . W . . ^ "
. < R . ! ' . \ ) ! ' "
R @ > > o ; ? / o ' u "
. . .
. . .
. . .
This is a Befunge-style quine, which works via exploiting wrapping to make string literals "wrap around" executable code (with only one " mark, the code is both inside and outside the quote at the same time, something that becomes possible when you have programs that are nonlinear and nonplanar). Note that this fits our definition of a proper quine, because two of the double quotes don't encode themselves, but rather are calculated later via use of arithmetic.
Unlike Befunge, though, we're using four strings here, rather than one. Here's how they get pushed onto the stack;
The program starts at the top of the left edge, going rightwards; it turns right twice (
R), making it go leftwards along the third and last of the lines that wrap around the whole cube. The double quote matches itself, so we push the entire third line onto the stack backwards. Then execution continues after the double quote.The
ucommand does a U-turn to the right, so the next thing we're running is from'"onwards on the middle line. That pushes a"onto the stack. Continuing to wrap around, we hit the<near the left hand side of the cube and bounce back. When approaching from this direction, we see a plain"command, not'", so the entire second line is pushed onto the stack backwards above the third line and the double quote.We start by pushing a
!onto the stack ('!) and incrementing it ()); this produces a double quote without needing a double quote in our source code (which would terminate the string). A mirror (\) reflects the execution direction up northwards; then theWcommand sidesteps to the left. This leaves us going upwards on the seventh column, which because this is a cube, wraps to leftwards on the third row, then downwards on the third column. We hit anR, to turn right and go leftwards along the top row; then the$skips theRvia which we entered the program, so execution wraps round to the"at the end of the line, and we capture the first line in a string the same way that we did for the second and third.The
^command sends us northwards up the eleventh column, which is (allowing for cube wrapping) southwards on the fifth. The only thing we encounter there is!(skip if nonzero; the top of the stack is indeed nonzero), which skips over theocommand, effectively making the fifth column entirely empty. So we wrap back to theucommand, which once again U-turns, but this time we're left on the final column southwards, which wraps to the fourth column northwards. We hit a double quote during the U-turn, though, so we capture the entire fourth column in a string, from bottom to top. Unlike most double quotes in the program, this one doesn't close itself; rather, it's closed by the"in the top-right corner, meaning that we capture the nine-character string...>......
So the stack layout is now, from top to bottom: fourth column; top row; "; middle row; "; bottom row. Each of these are represented on the stack with the first character nearest the top of the stack (Cubix pushes strings in the reverse of this order, like Befunge does, but each time the IP was moving in the opposite direction to the natural reading direction, so it effectively got reversed twice). It can be noted that the stack contents are almost identical to the original program (because the fourth column, and the north/top face of the cube, contain the same characters in the same order; obviously, it was designed like that intentionally).
The next step is to print the contents of the stack. After all the pushes, the IP is going northwards on the fourth column, so it hits the > there and enters a tight loop >>o;? (i.e. "turn east, turn east, output as character, pop, turn right if positive"). Because the seventh line is full of NOPs, the ? is going to wrap back to the first >, so this effectively pushes the entire contents of the stack (? is a no-op on an empty stack). We almost printed the entire program! Unfortunately, it's not quite done yet; we're missing the double-quote at the end.
Once the loop ends, we reflect onto the central line, moving west, via a pair of mirrors. (We used the "other side" of the \ mirror earlier; now we're using the southwest side. The / mirror hasn't been used before.) We encounter '!, so we push an exclamation mark (i.e. 33; we're using ASCII and Cubix doesn't distinguish between integers and characters) onto the stack. (Conveniently, this is the same ! which was used to skip over the o command earlier.) We encounter a pair of R commands and use them to make a "manual" U-turn (the second R command here was used earlier in order to reach the first row, so it seemed most natural to fit another R command alongside it.) The execution continues along a series of NOPs until it reaches the W command, to sidestep to the left. The sidestep crashes right into the > command on the second line, bouncing execution back exactly where it was. So we sidestep to the left again, but this time we're going southwards, so the next command to execute is the ) (incrementing the exclamation mark into a double quote), followed by an o (to output it). Finally, execution wraps along the eighth line to the second column, where it finds a @ to exit the program.
I apologise for the stray apostrophe on the third line. It doesn't do anything in this version of the program; it was part of an earlier idea I had but which turned out not to be necessary. However, once I'd got a working quine, I just wanted to submit it rather than mess around with it further, especially as removing it wouldn't change the byte count. On the subject of golfing down this quine further, it wouldn't surprise me if this were possible at 3×3 by only using the first five lines, but I can't see an obvious way to do that, and it'd need even tighter packing of all the control flow together with some other way to represent the top face of the cube (or else modifying the algorithm so that it can continue to use the fourth column even though it'd now be ten or eleven characters long).
RProgN, 3 bytes
0
0
This exploits a potential flaw in our definition of proper quine:
It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)
Furthermore, a quine must not access its own source, directly or indirectly.
The stack of RProgN is printed backwards, so the first 0 encodes the second 0, and vice versa.
This can be verified empirically; the program
1
2
prints
2
1
BotEngine, 4x1=4 bytes
TRUE
The T instruction deletes the active bot and prints TRUE.
JavaScript, 58 54 bytes
I present to you the shortest non-source-reading quine in JavaScript:
console.log(a="console.log(a=%s,uneval(a))",uneval(a))
How have I not thought of this before? Screw that, how has nobody thought of this before? :P
Here's a version that works in all browsers at the cost of 9 bytes:
q='"';console.log(a="q='%s';console.log(a=%s,q,q+a+q)",q,q+a+q)
These are the two shortest Ruby quines from SO:
_="_=%p;puts _%%_";puts _%_
and
puts <<2*2,2
puts <<2*2,2
2
Don't ask me how the second works...









