[HN Gopher] A Ruby program that generates itself through a 128-l...
       ___________________________________________________________________
        
       A Ruby program that generates itself through a 128-language quine
       loop
        
       Author : sirnicolaz
       Score  : 325 points
       Date   : 2022-10-06 08:03 UTC (14 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | kirjavascript wrote:
       | I wrote a new page describing how to write quines recently[1],
       | but the quine-relay is really above and beyond
       | 
       | 1: https://github.com/kirjavascript/quine-howto
        
       | RektBoy wrote:
       | Of course author is from Japan, of course.
        
       | whage wrote:
       | Ken Thompson wrote in his famous paper [1] about quines:
       | 
       | > If you have never done this, I urge you to try it on your own.
       | The discovery of how to do it is a revelation that far surpasses
       | any benefit obtained by being told how to do it
       | 
       | Every once in a while I give them a try but I couldn't yet create
       | one and it frustrates me very much. Afraid of being denied that
       | "revelation" I never dared to read his paper past that point. I'm
       | afraid I might never read it because of my ego.
       | 
       | 1:
       | https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...
        
         | 3pt14159 wrote:
         | It's easier in some languages than others.
         | 
         | There is a delight in doing it, but don't overdo the
         | anticipation. I've found greater delights in programming.
        
           | behnamoh wrote:
           | > It's easier in some languages than others.
           | 
           | Yes, it seems Lisp wouldn't be appropriate for this.
        
             | moomin wrote:
             | I tried typing `1` into the REPL. Am I doing this right?
        
               | tash9 wrote:
               | Maybe. What sound did it make?
        
             | kazinator wrote:
             | I believe that solution is possible for the Lisp-modified
             | task description:
             | 
             |  _Write a cyclic quine that reproduces itself through 128
             | Lisp languages_
             | 
             | because we easily have that many, or more.
        
             | tmtvl wrote:
             | I mean, isn't generating quines and twines one of the
             | examples used to show of MiniKanren?
             | 
             | William Byrds presentations of MK are absolutely
             | delightful, by the way.
        
           | sixothree wrote:
           | Like refactoring someone else's code? So much fun.
        
         | titzer wrote:
         | I hadn't written one until ~30 mins ago [1]. I cheated and
         | looked at a Java quine (not particularly elegant, but easy to
         | see what is going on.), but I wrote one for Virgil. Just think
         | string substitution; a string with a hole in it and you
         | substitute a copy of the string, quoted into the hole. Just one
         | substitution suffices.
         | 
         | [1]
         | https://github.com/titzer/virgil/blob/master/apps/Quine/Quin...
        
           | _wldu wrote:
           | Nice, this Go version satisfies gofmt:
           | 
           | https://github.com/62726164/quine
        
           | thomasahle wrote:
           | You should put SPOILER tags on that.
        
       | jmartin2683 wrote:
       | It's amazing what people can do with stuff like this. Such a
       | beautiful language (Ruby) made so ugly yet beautiful when viewed
       | from a higher altitude.. there's a metaphor there somewhere
        
       | neilwilson wrote:
       | Disappointed there is no Eiffel
        
       | drcabana wrote:
       | Last December I had the itch to do some blogging. As it happens,
       | I wrote a four part series that explains in detail how to write
       | quines and quine relays. The initial post can be found at
       | https://drcabana.org/quine/
       | 
       | I am a longtime lurker and finally decided to join in order to
       | comment on this thread. I hope that it is not inappropriate to
       | post a link to my own take on this material. If it is, please
       | accept my apologies and feel free to downvote/flag me out of
       | existence.
        
         | feintruled wrote:
         | Great write up, thanks for posting.
        
           | drcabana wrote:
           | Thanks for the kind words. Now I know at least one person has
           | read it.
        
       | kubb wrote:
       | Many programmers complain that they can't complete a hello world
       | example in one or more of the languages featured here because
       | they're too difficult.
       | 
       | This guy demonstrated enough understanding of 128 of them to make
       | this work.
       | 
       | Is the difference in competence really so big between us?
        
         | Bloedcoin wrote:
         | Yes.
         | 
         | I see this every single day.
         | 
         | And it becomes more and more obvious the better you become.
        
         | WindyLakeReturn wrote:
         | What is meant by "can't complete"?
         | 
         | Are we saying "can't do it in an interview without access to
         | some resources", "can't do it in the amount of time I'm willing
         | to learn the language", or truly a "I could never do this even
         | if I dedicated time to it and had standard resources to work
         | with"?
         | 
         | For me, I 'can't' do the first one even in languages I commonly
         | use as I almost never write the code for the initial entry
         | point. Either I'm working on an existing project of the IDE
         | generates it and I never look closely at it so I'll likely mess
         | something up.
         | 
         | If it is the second, it is more a of an 'I won't' do it in some
         | languages. I don't doubt my ability to do it, I just don't have
         | plans on learning many of these languages. I'll read an article
         | on how BF works, but I don't plan to spend more time on it than
         | that.
         | 
         | If it is the third option, then I'm quite bothered by level of
         | defeatism in it and would be surprised by a programmer saying
         | it. It is something I hear from people who took a coding class,
         | barely passed, and decided not to touch the topic again. Even
         | then I would challenge those people as having the ability to do
         | it but having (entirely valid) reasons not to spend time on the
         | attempt. (I make such a challenge because I think it is
         | beneficial for people to not put themselves down and to draw a
         | distinction between something they can't do and something they
         | do have the power to do but don't have enough reason to do.)
        
         | lifthrasiir wrote:
         | While this is amazing, I should point out that for most
         | languages he only needs to understand enough syntax to print
         | strings and possibly unquote them. If you actually run this
         | program into the first language, Ruby, the actual code (meant
         | to be a Rust code) is as follows:                   fn
         | main(){print!("{}",("object QR extends App{print(\"(display
         | \\\"printf(\\\\\\\"1d;s/.//;s/1/ the sum of a son and0/g;s/0/
         | twice/g;s/2/You are as bad as/g;s/3/ a son!Speak your
         | mind!/g\\\\\\\\n#The Relay of Quine.\\\\\\\\n#Ajax, a
         | man.\\\\\\\\n#Ford, a man.\\\\\\\\n#Act i:
         | Quine.\\\\\\\\n#Scene i: Relay.\\\\\\\\n#[Enter Ajax and
         | Ford]\\\\\\\\n#Ajax:\\\\\\\\n#\\\\\\\");function[]=f(s);for i=1
         | :2:length(s),printf(\\\\\\\"2%s3\\\\\\\",part(dec2bin(hex2dec(p
         | art(s,i:i+1))),$:-1:2)),end;endfunction\\\\nf('[lots of
         | hexdump]')\\\\nf('[lots of hexdump]')[snip]\\\\nprintf(\\\\\\\"
         | \\\\\\\\n#[Exeunt]\\\\\\\");quit\\\")\");}"));}
         | 
         | ...where `("object ... ;}")` part is a single string literal
         | here. The actual quine stuff can be done in just one language
         | at your choice, or can be assimilated into some other language
         | where unquoting is a bit heavier. It is much easier than
         | polyglots, where a _single_ code should be interpreted in
         | multiple languages.
        
           | jstanley wrote:
           | Printing and unquoting strings is enough to write an ordinary
           | quine (although getting it exactly right is still quite
           | subtle).
           | 
           | Making a quine _relay_ is substantially more complicated,
           | because you don 't just print the quoted string, you have to
           | print the quoted version of a string in a different language,
           | but that unwraps to the same thing 128 applications later!
           | 
           | If you still think it's easy, I reckon you should write us a
           | quine relay of just 3 languages and then explain how simple
           | it is.
        
             | lifthrasiir wrote:
             | "Easier than polyglot" does not mean "easy". :-) But I took
             | a bit of time to produce a three-language quine relay
             | elsewhere in this thread [1], and it is relatively easy to
             | follow. The quine stuff (and thus every necessary quoting)
             | is done in Ruby here, Python and Java only prints an
             | appropriately quoted string.
             | 
             | Of course there should be several intermediate steps to
             | keep the number of quotes reasonable (since it will be
             | exponentially increasing in most languages), and that's
             | probably why there are hexdumps after about 20ish
             | languages.
             | 
             | [1] https://news.ycombinator.com/item?id=33109200
        
               | jstanley wrote:
               | Great job, respect!
        
             | ohwellhere wrote:
             | He didn't say it was easy at all, he simply pointed out
             | that the required knowledge of each language is a subset of
             | the total available functionality of each language.
        
           | sirnicolaz wrote:
           | In this video (where among the other things they explain
           | huroboro), they show an example of code that prints out
           | exactly the same output (itself) whether it's
           | compiled/executed in c, python or ruby
           | 
           | https://youtu.be/6avJHaC3C2U?t=1957
        
       | siraben wrote:
       | There is an ongoing issue in Nixpkgs[0] to package this quine,
       | more help would be appreciated!
       | 
       | [0] https://github.com/NixOS/nixpkgs/issues/131492
        
       | debdut wrote:
       | for anybody willing to learn the art of quine, thanks to
       | obfuscationeso, here's "The world of Bbfuscated, Esoteric,
       | Artistic Programming" book translated from Japanese
       | 
       | https://web.archive.org/web/20220309061204/https://obfuscati...
        
       | raydiatian wrote:
       | How exactly does this work? Does one language invoke another and
       | another in a chain, or ruby at the top calling A, then B, then
       | C..
       | 
       | And is that an Ouroboros snake, or something else
        
         | viraptor wrote:
         | The top of the repo explains it: https://github.com/mame/quine-
         | relay
        
       | faitswulff wrote:
       | This issue imploring Yusuke Endoh to write a paper about it is
       | amusing:
       | 
       | https://github.com/mame/quine-relay/issues/10
       | 
       | > p-e-w:
       | 
       | > This is more than a cool program - it's a computer science
       | breakthrough! Apparently, you have discovered a method for
       | constructing quines based on an arbitrary blueprint involving any
       | amount of languages. > > Please write a technical paper
       | describing your approach. I'm sure you'll have no trouble finding
       | a CS journal that will publish it.
       | 
       | > mame:
       | 
       | > Okay I'll submit to the Journal of Universal Rejection.
       | 
       | Later:
       | 
       | > mame:
       | 
       | > I'll soon publish a book, "The world of obfuscated, esoteric,
       | artistic programming". The book explains how to write a uroboros
       | quine. Hence, I proudly close this issue.
       | 
       | > It also contains my almost all (about forty) works, including
       | alphabet-only Ruby program, radiation-hardened quine, etc., and
       | explains many techniques to write such programs.
       | 
       | > You can buy my book on amazon.co.jp. Unfortunately, it is
       | written in Japanese, yet another esoteric language. I hope anyone
       | can translate to English.
        
         | obfuscationeso wrote:
         | https://web.archive.org/web/20220309061204/https://obfuscati...
        
       | belter wrote:
       | I like the Radiation-hardened Quine:
       | https://github.com/mame/radiation-hardened-quine
        
         | jvanderbot wrote:
         | I don't even understand how this is possible. My mind runs to
         | CRC or error correcting codes, but how you'd use it is beyond
         | me.
        
       | avg_dev wrote:
       | I never zoom out on GitHub, but this one time it was kind of
       | neat.
        
       | pushedx wrote:
       | One of the languages is Piet. Now that's insane.
        
       | Liquix wrote:
       | A work of art :)
       | 
       | Previous discussion: https://news.ycombinator.com/item?id=6048761
       | (177 comments) (2013)
        
       | polycaster wrote:
       | But does it run Doom?
        
       | mmohtasim wrote:
       | Is there any 2 or 3 language version of this? Like ruby to python
       | to java to ruby?
        
         | lifthrasiir wrote:
         | Here it is:                   a='print("""class q{public static
         | void main(String[]a){System.out.println("a=#;a[35.chr]=39.chr+a
         | .gsub(34.chr,92.chr*3+34.chr)+39.chr;puts a");}}""")';a[35.chr]
         | =39.chr+a.gsub(34.chr,92.chr*3+34.chr)+39.chr;puts a
         | 
         | Run with `ruby q.rb | python - > q.java && javac q.java && java
         | q`. Pretty sure that you can shorten this, I didn't take much
         | time to do that.
        
       | dwheeler wrote:
       | This article explains the basic idea:
       | 
       | David Bertoldi's "How to write your first Quine program"
       | https://towardsdatascience.com/how-to-write-your-first-quine...
       | 
       | However, that article is a basic introduction. This 128-language
       | quine loop is beyond expert, bordering on magic.
        
       | bilekas wrote:
       | This is insane.. I remember when it was only 50 and I was blown
       | away.
        
       | daptaq wrote:
       | This was written by Yusuke Endoh, who also wrote this submission
       | to the IOCCC that I remember being arguably more astonished when
       | I saw it for the first time:
       | https://www.youtube.com/watch?v=QMYfkOtYYlg (ASCII fluid
       | dynamics).
        
         | sixstringtheory wrote:
         | Wow, that was cool, never found that one when I went on a deep
         | dive after discovering their quine relay. The other amazing
         | ASCII program of theirs that I love is the Qlobe:
         | http://mamememo.blogspot.com/2010/09/qlobe.html?m=1
        
       | bheadmaster wrote:
       | I am amazed. I have no idea how the hell could the author even do
       | that.
       | 
       | Apparently, they have a book called "The world of obfuscated,
       | esoteric, artistic programming", but it seems to be written in
       | Japanese. I hope it will be translated to English someday, so I
       | may learn this dark sorcery.
        
         | obfuscationeso wrote:
         | You are in luck! I threw the book into google translate a while
         | ago cause I wanted to read it. I took it offline cause I got an
         | email from the publisher saying to take it down cause it was
         | copyrighted material, however it is still archived on the
         | wayback machine:
         | https://web.archive.org/web/20220309061204/https://obfuscati...
        
       | tromp wrote:
       | Some background: https://esoteric.codes/blog/the-128-language-
       | quine-relay
       | 
       | Note that the author made the challenge even harder by sorting
       | the languages in alphabetical order:
       | 
       | > According to Endoh, the most challenging transitions were
       | Befunge to BLC8 to brainfuck, as all three are esoteric. It runs
       | through languages strictly in alphabetical order, so there was no
       | opportunity to group easier-to-work-with languages together.
        
       | enviclash wrote:
       | Code that writes code that writes code... my limited experience
       | combining AWK and GAMS gave me impressively powerful feelings
       | about my limited code. This surely belongs to the next level,
       | I'll go for more!
        
       | ramigb wrote:
       | Now this is how you market a book. cool.
        
       ___________________________________________________________________
       (page generated 2022-10-06 23:00 UTC)