Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an elixir quine #1

Open
emson opened this issue Nov 27, 2015 · 11 comments
Open

Create an elixir quine #1

emson opened this issue Nov 27, 2015 · 11 comments

Comments

@emson
Copy link
Owner

emson commented Nov 27, 2015

Write an elixir quine. A Quine is a computer program which takes no input and produces a copy of its own source code as its only output. They are “self-replicating” or “self-reproducing” programs, and your task is to either create the shortest or the most creative elixir quine.

http://elixirgolf.com/articles/elixir-quine-self-replicating-program/

Please add your solutions as comments to this Github issue (+ your Twitter handle)... Thanks!
When the puzzle is over I'll write them up on http://elixirgolf.com and link back to your Twitter handle

@phanimahesh
Copy link

"fn x->IO.puts ~s(\#{inspect x}|>\#{x}) end.()"|>fn x->IO.puts ~s(#{inspect x}|>#{x}) end.()
or
"fn x->IO.puts~s(\#{inspect x}|>\#{x}) end.()"|>fn x->IO.puts~s(#{inspect x}|>#{x}) end.()

90 chars, by @Phani_Mahesh

@CoderDennis
Copy link
Contributor

"x"

3 chars. Meets the requirements listed. Enter that in iex and it's exactly what you'll get back. I don't think that's really what you were asking for, so I'll keep trying.

http://twitter.com/CoderDennis

@phanimahesh
Copy link

@CoderDennis Unfortunately, a value that is echoed in a REPL is not considered a quine. And if it is, for the record, I submit 0, which shaves a whooping 66% off yours. :neckbeard:

@emson
Copy link
Owner Author

emson commented Dec 1, 2015

@CoderDennis ha ha nice try... that is certainly a creative thought however a "... Quine is a computer program..." which implies an algorithm rather than returning a type such as a string or integer. Also as @phanimahesh mentions the REPL is doing the hardwork here.
However I like you creative thinking, we haven't had many solutions and in the spirit of fun... I'll give you and honourable mention!

@CoderDennis
Copy link
Contributor

@emson thanks for laughing! That was my intent. As an Elixir newbie (installed it for the first time less than a month ago) this is a hard one to figure out using the REPL. The 2 times I thought I was getting close were when the REPL was using a previously bound variable and then when I realized it was just giving me back the string as-is.

I've got lots of programming experience, but have never participated in a code golf challenge before. Since solutions are being posted publicly as comments, is it kosher to borrow from entries already given?

@emson
Copy link
Owner Author

emson commented Dec 1, 2015

@CoderDennis sure no problem at all. The Elixir community is very friendly and the whole purpose I set up elixirgolf is to help people learn elixir, and the more people become familiar with the language the better.
Also, TBH this puzzle hasn't been very popular, but any contributions are warmly welcomed! Thanks and good luck.

@CoderDennis
Copy link
Contributor

"(&(IO.puts~s(\#{inspect &1}|>\#{&1}))).()"|>(&(IO.puts~s(#{inspect &1}|>#{&1}))).()

84 chars. It requires a few extra parenthesis and some ampersands, but removes fn x-> and end chars. Again, I'm hoping it's OK to borrow from already posted solutions. I wouldn't have come up with this without seeing the solution @phanimahesh posted.

Also works without the spaces for 82:

"(&(IO.puts~s(\#{inspect&1}|>\#{&1}))).()"|>(&(IO.puts~s(#{inspect&1}|>#{&1}))).()

@CoderDennis

@emson
Copy link
Owner Author

emson commented Dec 1, 2015

Hey @CoderDennis that's great. Yes it's ok to be influenced by other people's solutions. Well done in citing @phanimahesh. Previous winners have persevered with their solutions and been influenced by others. We make sure both get a mention on the web site. Thanks again.

@rubysolo
Copy link

rubysolo commented Dec 2, 2015

q=<<"q=~p;:io.format q,[q]">>;:io.format q,[q]

@rubysolo

@phanimahesh
Copy link

@CoderDennis cool. I wonder why I haven't thought of that! If you observe, my solution was itself inspired by the ruby quine in the post.
@rubysolo You, sir, are a genius! I never even considered the beautiful :io.format. Elixir spoiled me.

@emson
Copy link
Owner Author

emson commented Dec 4, 2015

@rubysolo that is great well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants