66
\$\begingroup\$

The title says it all. Your goal is to write a program that forms a w×h rectangle of characters that can be rotated and re-run to output the number of 90° Counter-Clockwise (CCW) rotations that have been done.

For example, if the 3×2 program

abc
def

solved the problem, it would initially output 0, and successive rotations of 90° CCW

cf    fed    da
be    cba    eb
ad           fc

would output 1, 2, and 3 respectively.

Using comments makes this a trivial task is most languages. In Ruby for example, it can be done in a 7×7 rectangle:

###p###
### ###
###1###
p 0#2 p
###3###
### ###
###p###

The challenge is to do this without any sort of comments.

Scoring

Your score is w*h, the area of your rectangle. Newlines are excluded. In other words, code-golf, newlines not counted.

The score for the Ruby example is 49 (though of course it is invalid since it has comments).

Notes

  • Your code must really be rectangular with no missing characters at the end of lines.
  • If you wish you may output other legal "mod 90°" values instead of 0 1 2 3. So 8 is fine instead of 0, and -1 is fine instead of 3, etc.
  • The output may go to the console or into a file.
  • Standard loopholes apply.

I hope this, my first question, really intrigues some people. Enjoy!

\$\endgroup\$
10
  • 1
    \$\begingroup\$ To be more specific about what a comment is, is a comment any unevaluated code? Unparsed code? \$\endgroup\$
    – isaacg
    Jul 8, 2014 at 21:59
  • \$\begingroup\$ I mean that none of your language's traditional "comment characters" should appear in any of the 4 rotated versions. So for C++, two slashes next to each other should never appear, though one may be used alone. Likewise with /*. I hope that clarifies it. \$\endgroup\$ Jul 8, 2014 at 22:09
  • \$\begingroup\$ What about languages that do not have comment characters? \$\endgroup\$
    – isaacg
    Jul 8, 2014 at 22:19
  • \$\begingroup\$ So code like echo 0;exit;e in bash is allowed? \$\endgroup\$
    – jimmy23013
    Jul 8, 2014 at 22:22
  • \$\begingroup\$ If there is no way to comment then you needn't worry. @user23013 That bash is fine. \$\endgroup\$ Jul 8, 2014 at 22:40

36 Answers 36

1
2
1
\$\begingroup\$

Japt, 2*2=4 bytes

Outputs 0, 1, 2 & -1.

ÄÄ
JT

Test it | Rotated: once, twice, or thrice

Outputs 0-3.

ÄÄ
ÑV

Try it

I'm struggling to find anything in the spec that disallows trivial solutions of double, or even single, digit numbers.

\$\endgroup\$
0
\$\begingroup\$

Chip, (2x5) 10

b~
+a
~t
e*
 f

* activates all neighbor elements: north, east, south and west (source)
~ if not activated from the west, activates the east neighbor (NOT-gate) (never activated here)
t terminates execution after printing the current byte
a sets the bit 0x01 of the output
b sets the bit 0x02 of the output
e sets the bit 0x10 of the output
f sets the bit 0x20 of the output
+ if activated by any neighbor, activate all other neighbors (wire)

Chip requires either the -w flag (to allow execution without input), or some input in order to run.

Prints 0, 1, 2, or 3 in ASCII. If code points 0x00 to 0x03 are desired, remove the e and f, then move the space up to fill the gap.

\$\endgroup\$
0
\$\begingroup\$

><> (Fish), 11 bytes

0v1
vnv
3v2

Try it

Starts in a corner, pushing whatever the rotated value is. Then gets sent in a infinite downwards loop which will soon crash since the stack is empty.

\$\endgroup\$
0
\$\begingroup\$

Thunno, 4 bytes (2x2)

2y
3x

(The last one outputs 23 but that's ok because 23 % 4 = 3)

Port of Kevin Cruijssen's 05AB1E answer.

x defaults to 0 and y defaults to 1.

\$\endgroup\$
0
\$\begingroup\$

TI-Basic, 2x2 = 4

03
12

This is the exact same as this answer, for the same reason.

3x3 = 9

2:3
:::
1:0
\$\endgroup\$
0
\$\begingroup\$

Pyt, 9

2ĉ3
ĉĉĉ
1ĉ0

Try it online!

The key here is that ĉ clears the stack, so for every rotation, only the last number is implicitly printed.

\$\endgroup\$
1
2

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.