Live data from Hacker News

A Ruby program that generates itself through a 128-language quine loop

github.com

31–40 of 63 posts

Re: A Ruby program that generates itself through a 128-language quine loop

#32

Is there any 2 or 3 language version of this? Like ruby to python to java to ruby?

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.

Re: A Ruby program that generates itself through a 128-language quine loop

#33
post #9

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?

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.)

Re: A Ruby program that generates itself through a 128-language quine loop

#35

Earlier quoted context omitted.

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…

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…

"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

Re: A Ruby program that generates itself through a 128-language quine loop

#36

Earlier quoted context omitted.

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.

> It's easier in some languages than others. Yes, it seems Lisp wouldn't be appropriate for this.

I tried typing `1` into the REPL. Am I doing this right?

Re: A Ruby program that generates itself through a 128-language quine loop

#37
post #36

Earlier quoted context omitted.

> It's easier in some languages than others. Yes, it seems Lisp wouldn't be appropriate for this.

I tried typing `1` into the REPL. Am I doing this right?

Maybe. What sound did it make?

Re: A Ruby program that generates itself through a 128-language quine loop

#38
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.

Re: A Ruby program that generates itself through a 128-language quine loop

#40
post #30
post #25

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…

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...

You should put SPOILER tags on that.
Post reply on HN