Coding Around The Clock

47

5

Write a single line program two or more characters long that contains no line terminators and takes no input. For example, your program might be:

MyProgram

When your program is arranged into the shapes a clock's hands make at 12, 3, 6, and 9 o'clock, it needs to output the corresponding hour number. No other times need be supported.

Specifically:

  • When your program is arranged like clock hands at 12 o'clock ()

    m
    a
    r
    g
    o
    r
    P
    y
    M
    

    running it should output 12.

  • When your program is arranged like clock hands at 3 o'clock ()

    m
    a
    r
    g
    o
    r
    P
    y
    MyProgram
    

    running it should output 3.

  • When your program is arranged like clock hands at 6 o'clock ()

    m
    a
    r
    g
    o
    r
    P
    y
    M
    y
    P
    r
    o
    g
    r
    a
    m
    

    running it should output 6.

  • When your program is arranged like clock hands at 9 o'clock ()

    ........m
    ........a
    ........r
    ........g
    ........o
    ........r
    ........P
    ........y
    margorPyM
    

    running it should output 9.

Notes

  • The first character in your program is always placed at the center of the clock. (Note how there is only one M in the 6 o'clock example.)

  • Any one non-newline character may be used to indent the program for the 9 o'clock arrangement. In the examples . is used, but space or / or # would be just as valid.

  • For the 3 o'clock arrangement, no characters should be in the empty upper right region. (i.e. keep it empty, don't fill it with spaces.)

  • The initial program arrangement (MyProgram as is) does not need to do anything. Only the 12, 3, 6, and 9 o'clock arrangements need to have correct, well-defined output.

  • Code that only works as a function or REPL command is not allowed. Each of the four arrangements should be ready to run as full programs as is.

The shortest program in bytes wins. e.g. MyProgram has a length of 9 bytes.

Calvin's Hobbies

Posted 2016-04-26T02:55:34.547

Reputation: 84 000

27I have no idea how to even begin doing this – Fund Monica's Lawsuit – 2016-04-26T03:16:40.473

You can see what programs you need to account for using this: function all(e,n){n=n||" ";var i=e.split("").reverse().join("\n"),l=i+e.slice(1),r=i+e.split("").join("\n").slice(1),s=i.replace(/^./gm,n.repeat(e.length-1)+"$&").replace(/\n.+$/,"\n"+e.split("").reverse().join(""));return[i,l,r,s].join("\n\n")} (javascript); e is the program, and n is the filler character – Conor O'Brien – 2016-04-26T03:17:56.580

So, in Python, for instance, no lambda, no functions, and no REPL commands? This is going to take some miracle to get done on my part... – R. Kap – 2016-04-26T03:45:15.487

1Is it OK if a character is printed and then erased with backspace? – feersum – 2016-04-26T03:48:51.673

And here comes the magic, thanks to @feersum – R. Kap – 2016-04-26T03:49:52.987

@R.Kap Not exactly. What I mean is each arrangement should be a valid full program - if it also works as a function or REPL command (as it might indeed in Python) that's fine. – Calvin's Hobbies – 2016-04-26T03:51:15.523

@feersum Yes, that sounds ok – Calvin's Hobbies – 2016-04-26T03:51:55.400

Oh, okay, that makes it a bit easier. – R. Kap – 2016-04-26T03:53:24.277

5

Here's a CJam script to generate all four codes from a single line and a padding character: http://cjam.tryitonline.net/#code=bDpMVyVOKk1MVyVOKkwxPitNTFclTDE-K04qTUwxPlclOnNMLGxjOlg7ZntYZVt9TFclYStOKl1OKg&input=TXlQcm9ncmFtCi4 Feel free to include it in the post.

– Martin Ender – 2016-04-26T07:45:41.433

@MartinBüttner That's the definition of meta-metagolf right there. There should be a challenge just for that. – cat – 2016-04-26T14:42:29.053

4I was gonna attempt this in Brainfuck, but it turns out the challenge fucked my brain before BF could. – cat – 2016-04-26T14:43:33.133

2@cat I believe that's impossible because programs 3 and 6 would be indistinguishable to Brainfuck as they only differ in whitespace. – Martin Ender – 2016-04-26T14:45:17.357

@MartinBüttner Yeah, I think so too. – cat – 2016-04-26T14:54:13.963

Also out of curiosity, does "any character" for indentation include backspaces or NULs? What about Unicode combining characters? – user253751 – 2016-04-27T02:56:25.827

@immibis Yes. Any character means any character. – Calvin's Hobbies – 2016-04-27T03:07:46.107

Answers

37

GolfScript, 11 10 bytes

21;;3#9];6

Uses # as padding character.

12 o'clock

6
;
]
9
#
3
;
;
1
2

Try it online!

How it works.

  • 6 is pushed on the stack, ; discards it.

  • ] wraps the stack in an array (does not affect output).

  • 9 and 3 are pushed on the stack, ; and ; discard them.

  • Finally, 1 and 2 are pushed on the stack, and implicitly printed without separation.

3 o'clock

6
;
]
9
#
3
;
;
1
21;;3#9];6

Try it online!

How it works

  • 6 is pushed on the stack, ; discards it.

  • ] wraps the stack in an array (does not affect output).

  • 9 and 3 are pushed on the stack, ; and ; discard them.

  • 1 and 21 are pushed on the stack, ;; discards them.

  • 3 is pushed on the stack.

  • # begins a comment until the end of the line.

6 o'clock

6
;
]
9
#
3
;
;
1
2
1
;
;
3
#
9
]
;
6

Try it online!

How it works

  • 6 is pushed on the stack, ; discards it.

  • ] wraps the stack in an array (does not affect output).

  • 9 and 3 are pushed on the stack, ; and ; discard them.

  • 1, 2 and 1 are pushed on the stack.

  • ; and ; discard the last 1 and 2.

  • 3 and 9 are pushed on the stack.

  • ] and ; wrap the stack in an array and discard it, clearing the stack.

  • 6 is pushed on the stack.

9 o'clock

#########6
#########;
#########]
#########9
##########
#########3
#########;
#########;
#########1
6;]9#3;;12

Try it online!

How it works

  • All lines but the last are comments.

  • 6 is pushed on the stack, ; discards it.

  • ] wraps the stack in an array (does not affect output).

  • 9 is pushed on the stack.

  • # begins a comment until the end of the line.

Dennis

Posted 2016-04-26T02:55:34.547

Reputation: 196 637

25

><>, 20 bytes

X   n-+g+aa0g+9a2c!v

There's unprintables in there, namely:

  • After the X is \x06\t
  • After the c is \x03

The same part of source code is run each time, using g on two parts of the source code to determine what to subtract from 12.

v                         Make IP move downwards
 !\x03                    Jump over the \x03
      c                   Push 12
       2a9+g              Get the char at position (2, 19), i.e. the \t for
                          3 o'clock, the \x03 for 9 o'clock, 0 otherwise
            0aa+g         Get the char at position (0, 20), i.e. first char on
                          the line after the X, \x06 for 6 o'clock
                 +        Add
                  -       Subtract from the 12
                   n      Output as number
                    \t    Unrecognised instruction - errors out

12 o'clock | 3 o'clock | 6 o'clock | 9 o'clock (looks misaligned due to the tab)

Sp3000

Posted 2016-04-26T02:55:34.547

Reputation: 58 729

7

"12 votes 0 answers? Wait until Sp proves it's trivial please." –Helka, in chat

– Alex A. – 2016-04-26T04:41:07.650

1

ROOP, 54 bytes

OW    3#H V  1#1  H#6  WO#H V>V1#OW V>V9#OW   2#OW   1

Uses < as padding character.

12 o'clock | 3 o'clock | 6 o'clock | 9 o'clock

12 o'clock

The 1 and the 2 that are near the top fall for 3 cycles. When they reach the W operator, the operator places the number in O, which represents the output.

The 1 in this part

1


V

H

fell for 2 cycles, the V operator moves it below and at the next cycle activates the H operator that ends the program.

3 o'clock

O are also objects that move and fall. Since the code now has a line with more than one character, all other lines are filled with empty spaces. All O moves to the right and fall, causing the W operators to have no place to send the 1 and 2.

The only O that does not move is the one that is trapped in the center. The 3 above falls for 4 cycles to the W.

Then the numbers that fall are filling the 4 spaces between the W and3. When it is filled, another number can pass over all of them and reach the H operator that ends the program.

6 o'clock

1


H
#
6


W
O

Very similar to the 12, the 6 falls to the W and the 1 to the H. This occurs in 2 cycles, ending the program before the 12 case occurs.

9 o'clock

<9
<V
<>
<V
< 
<W
<O
<#
<1
<V
<>
<V
< 
<H

(I show a single column of < because the others do nothing).

The V picks up the 9 and moves it to the pipe below, which deflects the object to the left. The pipe < moves the object down and the next one to the right. The V operator put the 9 in the space below and then it is sent to the output.

The 1 makes equal movements and reaches the H, which ends the program. As the pipes move objects in the same cycle, all this takes a single cycle.

DarkPhantom

Posted 2016-04-26T02:55:34.547

Reputation: 191