Fibonacci is so QUINE! - Code Golf Stack Exchange most recent 30 from codegolf.stackexchange.com 2019-11-12T16:39:10Z https://codegolf.stackexchange.com/feeds/question/18900 https://creativecommons.org/licenses/by-sa/4.0/rdf https://codegolf.stackexchange.com/q/18900 3 Fibonacci is so QUINE! Plarsen https://codegolf.stackexchange.com/users/2513 2014-01-19T13:25:53Z 2014-04-21T21:01:04Z <ol> <li>Your program must output atleast half of its sourcecode in reverse. Any single part of the sourcecode as long as it is one single block of neighbouring characters. </li> <li>Your program should not take any input (from user, filename, network or anything).</li> <li><p>The output has some additional constraints. The character position (first character is #1) on the output is either a fibonacci-sequence number (1, 1, 2, 3, 5, 8, 13, 21, ...) or not (4, 6, 7, 9, 10, 11, 12, ...), and this is the constraints:</p> <ul> <li>3.1 Every third fibonacci-sequence number output position must be a letter (a-z|A-Z). Starting at fibonacci-sequence number #2 (output char|byte pos: 1, 5, 21, ...).</li> <li>3.2 Every third fibonacci-sequence number output position must be a number (0-9). Starting at fibonacci-sequence number #3 (output char|byte pos: 2, 8, 34, ...).</li> <li>3.3 Every third fibonacci-sequence number output position must be a symbol !(0-9|a-z|A-Z). Starting at fibonacci-sequence number #4 (output char|byte pos: 3, 13, 55, ...).</li> </ul></li> <li><p>The output must contain exactly all of these three phrases in any place as long as the other rules is not broken (case sensitive): <code>Fibonacci is so QUINE!</code>, <code>3 is more than {4}</code>, <code>{'{"\}</code></p></li> </ol> <p>This is code-golf, shortest sourcecode in bytes wins! Good luck, have fun!</p> https://codegolf.stackexchange.com/questions/18900/-/26098#26098 8 Answer by Paul Thomann for Fibonacci is so QUINE! Paul Thomann https://codegolf.stackexchange.com/users/20572 2014-04-21T03:21:19Z 2014-04-21T21:01:04Z <h1>Befunge '98, 91 characters</h1> <p>Was formerly 104, then 101. Saved another 10 chars by moving the "Fi...E!" sentence to output position 89 using <code>'E'</code> (instead of <code>' '</code> at 55), and moving the actual code into the space this opened up, with a slightly improved print loop.</p> <pre><code>"!ENIUQ os si iccanobiF"f6*&gt;:;#-1,g0;#:_ "}\"f:4++"{'{",,0\$,,,,@"}4{ naht erom si 30" b &gt;0a </code></pre> <p>produces the following output (fibonacci positions marked):</p> <pre><code>a0&gt; b "03 is more than {4}"@,,,,\$0,,"{'{"++4:f"\}" _:#;0g,1-#;:&gt;*6f"Fibonacci is so QUINE!{'{"\} --- - - - - - - - | | | | | | | | | | </code></pre> <p>This snippet outputs all of itself, except for the first character, in reverse order. Then it appends <code>{'{"\}</code> to the output, yielding a total of 96 chars including 98.9% of the code.</p> <ul> <li>Positions 1, 5, 21 and 89 are each occupied by <code>'a'</code>, <code>'b'</code> or <code>'E'</code>.</li> <li>Positions 2, 8 and 34 each have a <code>'0'</code>.</li> <li>In positions 3, 13 and 55, we find <code>'&gt;'</code>, <code>' '</code> and <code>';'</code>, all symbols according to the definition given by Plarsen.</li> </ul> <p>There are 3 completely unused cells, and all of <code>b &gt;0a</code> is utterly useless code, only there for the aesthetics of <code>a0&gt; b 0</code>. There may (still) be room for optimization.</p> <p>Since String mode means pushing a reverse string to the stack and then pop/print-ing it forward, writing them in reverse order is totally natural in Befunge.</p> <h2>Breakdown</h2> <ol> <li><code>f6*</code> calculates 90, the index of the last character in the source. It's 15 * 6.</li> <li><code>&gt;:</code> means 'head east and duplicate the top of stack value'. Stack [ ... 90 90 ].</li> <li><code>;...;</code> skips over the code in between.</li> <li><code>#:_</code> skips the <code>:</code>, then pops TOS and heads back west if not 0. Stack [ ... 'F' 90].</li> <li>Now RTL: <code>,g0;#:</code> duplicates TOS, skips entry to the <code>;</code> portal, gets the character at (TOS, 0) and prints it.</li> <li>Still RTL: <code>:;#-1</code> decrements TOS, skips <code>;</code> and duplicates TOS. Execution continues at step 2.) Stack [ ... 89 89 ]</li> <li>Once the TOS counter is down to 0, <code>_</code> lets us through.</li> <li>We push the third required string , whereby we have to calculate the <code>'"'</code> because there is no escaping in Befunge. <code>f:4++</code> is 15 + 15 + 4. The commas write it back out from the stack. I had to insert <code>0\$</code> there (push 0 then pop/discard) to meet the requirement.</li> <li><code>@</code> terminates.</li> </ol>