9
\$\begingroup\$

Code-Golf caddy Eddie Brackets was getting tired of quine challenges, which appeared to be much too easy for the grand poobahs. He has this idea to spice up things and is sending quines to the car crusher.

Challenge: Write a quine that prints itself "squeezed" for output purposes into an n x n square followed by that same square three more times, each time rotated 90 degrees to the right, for a total of 4 squares. (By squeezed quine, Eddie means one that has all its printable characters but has all the white space (spaces, tabs, line feeds) removed. Of course, it may or may not work as a real quine after being squeezed, but it's what Eddie is talking about for his output.)

Example: If a solution quine in some language were: A%C~?5 F$G &G52[/<

its Output must be:

A%C~  
?5F$  
G7G5  
2[/<

2G?A  
[75%  
/GFC  
<5$~

</[2  
5G7G  
$F5?  
~C%A

~$5<  
CFG/  
%57[  
A?G2

Rules

  1. All whitespace in the code counts toward the final byte count, but must be removed in the output squares. There must be at least 4 printable (i.e. visible, non whitespace) characters in the quine, i.e. a minimum of 16 printable characters output.

  2. The four squares may be printed either horizontally or vertically, but must be separated by at least one space or delineating character(s) (horizontally) or at least one blank line or delineating character(s) (vertically). The first square is the "squeezed" program code (whitespace removed) printed n characters to a line. Nothing should appear between the output characters in each output square, which should each be a solid block of characters. Each square must contain all the printable characters of the quine.

  3. Orientation of all characters in the rotated output remains just as it is in the code, e.g. < remains < and never changes to > or ^.

  4. Code golf: shortest code in bytes wins.

In summary, your quine will have n^2 printable characters, and each of the four output squares will be n x n.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Welcome to Code Golf! This looks like a well-specified challenge, but for future reference, we strongly recommend using the Sandbox to get feedback on challenge ideas before posting them to the main site \$\endgroup\$
    – pxeger
    Jul 29, 2021 at 18:51
  • \$\begingroup\$ I did an got constructive feedback. Thanks \$\endgroup\$
    – DjinTonic
    Jul 29, 2021 at 18:57
  • 1
    \$\begingroup\$ @pxeger this was sandboxed here (now deleted though). That being said, we usually advise waiting for at least several days to around a week - 21 hours is usually not enough. \$\endgroup\$
    – hyper-neutrino
    Jul 29, 2021 at 18:57
  • 7
    \$\begingroup\$ Understood, however, for my last 2 challenges I got no feedback after several days. This is my 5th challenge \$\endgroup\$
    – DjinTonic
    Jul 29, 2021 at 18:58
  • 1
    \$\begingroup\$ You could try asking in chat \$\endgroup\$
    – pxeger
    Jul 29, 2021 at 19:00

4 Answers 4

3
\$\begingroup\$

J, 49 bytes

apply~'][:echo[:|:@|.^:(<4),~@7$''apply~'',quote'

Try it online!

The standard J quine (26 bytes plus newline) is required to have even length because it is a string repeated twice. The square formatting and rotating 4 times do not fit into 36 bytes and therefore must be lengthened to 64 bytes.

This quine circumvents this even-length problem by using a built-in that works just like Jelly's v built-in: eval the string as a verb and feed one argument. The basis then becomes the following at 30 bytes. (technically 29 because [: can be shortened to @, but we need to do something more on that string after all)

apply~'[:echo''apply~'',quote'

Try it online!

Now we just need to insert one copy of the string manipulation code, which barely fits in 49 bytes without whitespace.

][:echo[:|:@|.^:(<4),~@7$'apply~',quote  NB. the eval-ed string
quote      NB. uneval the string; double each quote and surround with quotes
'apply~',  NB. prepend this string
,~@7$      NB. equal to `7 7$`; format into a square (`_7]\` also works)
[:|:@|.^:(<4)    NB. generate four rotations
[:echo     NB. print the resulting 3d array of chars
           NB. each matrix is printed with an empty line between them
]          NB. a no-op padding to make 49 bytes
\$\endgroup\$
1
  • \$\begingroup\$ Very nicely done. \$\endgroup\$
    – Jonah
    Aug 31, 2021 at 2:08
3
\$\begingroup\$

Jelly, 25 bytes

“Ṿ;⁾v`s5ṚZ$3СYY¹¹¹¹¹¹”v`

Try it online!

A full program that takes no arguments and prints itself formatted as a 5x5 square with its three 90° rotations. Note the 5 ¹ are just padding - the program would work without them but would give a 5x4 rectangle.

Explanation

“Ṿ…¹”v` | Evaluate the string as Jelly code, supplying itself as an argument

Code within string

Ṿ                     | Uneval (wraps argument in “”
 ;⁾v`                 | Append "v`"
     s5               | Split into pieces of length 5
         $3С         | Do the following three times, keeing all intermediate results as well as the start:
       Ṛ              | - Reverse
        Z             | - Transpose
             Y        | Join with newlines
              Y       | Join with newlines
               ¹¹¹¹¹¹ | Identity function (repeated 6 times)

Implicit print at the end.

\$\endgroup\$
2
  • \$\begingroup\$ I'm just curious, does this make use of something similar to Basic's "Print" statement that prints its code? \$\endgroup\$
    – DjinTonic
    Jul 29, 2021 at 20:22
  • 1
    \$\begingroup\$ @DjinTonic Jelly has implicit printing, so there’s actually no print statement there. I’ll add an explanation. \$\endgroup\$ Jul 30, 2021 at 8:21
1
\$\begingroup\$

05AB1E (legacy), 36 bytes

00"D34çý6ô4FD»,¶?øí"D34çý6ô4FD»,¶?øí

Try it online.

Explanation:

00                   # Push 00
  "D34çý6ô4FD»,¶?øí" # Push this string
   D                 # Duplicate this string
    34               # Push 34
      ç              # Convert it to a character: '"'
       ý             # Join the stack with this character as delimiter:
                     #  '00"D34çý6ô4FD»,¶?øí"D34çý6ô4FD»,¶?øí'
        6ô           # Split it into parts of size 6
          4F         # Loop 4 times:
            D        #  Duplicate the current list of strings
             »       #  Join it by newlines
              ,      #  Print it with trailing newline
               ¶?    #  And also print an empty line
                     #  Then rotate it around 90 degrees clockwise, by:
             ø       #   Zipping/transposing; swapping rows/columns
              í      #   And then reverting each row
\$\endgroup\$
0
\$\begingroup\$

Python 3, 147 121 bytes

s="a='s=%r;exec(s*4)'%s;*map(print,map(''.join,[*zip(*[iter(a)]*11),''])),;a=(11*('_'+a))[-11:0:-11];aaaaaaaaa";exec(s*4)

Try it online!

prints in a 11x11 square.

How it works:

  • start from the quine s="print('s=%r;exec(s)'%s)";exec(s)
  • a='s=%r;exec(s*4)'%s store our string in a
  • zip(*[iter(a)]*11) split the string a in rows of 11 chars
  • *map(print,map(j,[* <...> ,''])), display each row plus a newline
  • a=(11*('_'+a))[-11:0:-11] rotates a and store the new value in a
  • ;aaaaaaaaa adjust the size of the square
  • exec(s*4) execute the code 4 times, the ;aaaaaaaaa transform the initialisation of a to avoid overriding a and keep it rotated

because of a is 121 char long, the result fits in a 11x11 box

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.