Fibonacci is so QUINE!

3

  1. 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.
  2. Your program should not take any input (from user, filename, network or anything).
  3. 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:

    • 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, ...).
    • 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, ...).
    • 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, ...).
  4. The output must contain exactly all of these three phrases in any place as long as the other rules is not broken (case sensitive): Fibonacci is so QUINE!, 3 is more than {4}, {'{"\}

This is code-golf, shortest sourcecode in bytes wins! Good luck, have fun!

Plarsen

Posted 2014-01-19T13:25:53.087

Reputation: 1 740

Answers

8

Befunge '98, 91 characters

Was formerly 104, then 101. Saved another 10 chars by moving the "Fi...E!" sentence to output position 89 using 'E' (instead of ' ' at 55), and moving the actual code into the space this opened up, with a slightly improved print loop.

"!ENIUQ os si iccanobiF"f6*>:;#-1,g0;#:_ "}\"f:4++"{'{",,0$,,,,@"}4{ naht erom si 30" b >0a

produces the following output (fibonacci positions marked):

a0> b "03 is more than {4}"@,,,,$0,,"{'{"++4:f"\}" _:#;0g,1-#;:>*6f"Fibonacci is so QUINE!{'{"\}
--- -  -    -       -            -                    -                                 -
|   |               |                                                                   |
 |     |                         |  
  |         |                                         |

This snippet outputs all of itself, except for the first character, in reverse order. Then it appends {'{"\} to the output, yielding a total of 96 chars including 98.9% of the code.

  • Positions 1, 5, 21 and 89 are each occupied by 'a', 'b' or 'E'.
  • Positions 2, 8 and 34 each have a '0'.
  • In positions 3, 13 and 55, we find '>', ' ' and ';', all symbols according to the definition given by Plarsen.

There are 3 completely unused cells, and all of b >0a is utterly useless code, only there for the aesthetics of a0> b 0. There may (still) be room for optimization.

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.

Breakdown

  1. f6* calculates 90, the index of the last character in the source. It's 15 * 6.
  2. >: means 'head east and duplicate the top of stack value'. Stack [ ... 90 90 ].
  3. ;...; skips over the code in between.
  4. #:_ skips the :, then pops TOS and heads back west if not 0. Stack [ ... 'F' 90].
  5. Now RTL: ,g0;#: duplicates TOS, skips entry to the ; portal, gets the character at (TOS, 0) and prints it.
  6. Still RTL: :;#-1 decrements TOS, skips ; and duplicates TOS. Execution continues at step 2.) Stack [ ... 89 89 ]
  7. Once the TOS counter is down to 0, _ lets us through.
  8. We push the third required string , whereby we have to calculate the '"' because there is no escaping in Befunge. f:4++ is 15 + 15 + 4. The commas write it back out from the stack. I had to insert 0$ there (push 0 then pop/discard) to meet the requirement.
  9. @ terminates.

Paul Thomann

Posted 2014-01-19T13:25:53.087

Reputation: 346