Display a clock face

39

3

Display the 12 numbers on a clock face exactly like this:

           12            
     11           1      

 10                   2  


9                       3


  8                   4  

      7           5      
            6            

To better see the grid, here's one with dots:

...........12............
.....11...........1......
.........................
.10...................2..
.........................
.........................
9.......................3
.........................
.........................
..8...................4..
.........................
......7...........5......
............6............

Note that the grid is stretched in width by a factor of two to make it look more square.

Also note that two-digit numbers are aligned with their ones digit in place. The 9 digit should be flush against the left.

Return or print the result as a multiline string (not a list of lines). Any trailing spaces are optional. The final newline also optional.

xnor

Posted 2018-08-09T01:33:30.760

Reputation: 115 687

Answers

25

Charcoal, 40 bytes

F¹²«M⁻↔⁻¹⁴⊗÷×⁴鳦⁸⁻⁴↔⁻⁷÷×⁴﹪⁺³ι¹²¦³P←⮌I⊕ι

Try it online! Link is to verbose version of code. Explanation: Computes the offsets between each digit mathematically. Charcoal is 0-indexed (thus the to output \$ 1 \ldots 12 \$), so the formulae for the horizontal and vertical offsets are as follows:

$$ \begin{align} \delta x &= \left \lvert 14 - 2 \left \lfloor \frac {4i} 3 \right \rfloor \right \rvert - 8 \\ \delta y &= 4 - \left \lvert 7 - \left \lfloor \frac {4i'} 3 \right \rfloor \right \rvert \end{align} $$

where \$ i' = i + 3 \pmod {12} \$.

Neil

Posted 2018-08-09T01:33:30.760

Reputation: 95 035

22

JavaScript (Node.js), 91 bytes

Not a very clever approach, but I've failed to find anything shorter at the moment.

_=>`K12
E11K1

A10S2


9W3


B8S4

F7K5
L6`.replace(/[A-Z]/g,c=>''.padEnd(Buffer(c)[0]&31))

Try it online!

Arnauld

Posted 2018-08-09T01:33:30.760

Reputation: 111 334

4I love the use of Buffer() as alternative to charCodeAt() – Downgoat – 2018-08-09T18:32:45.443

1@Downgoat Which makes me wonder if we should have a Tips for golfing in Node.js question, for Node specific features. Not sure it's worth it, though. – Arnauld – 2018-08-09T22:09:28.080

Maybe add a separate answer that contains all the Node specific features, or at least a list linking all the different answers? – None – 2018-08-11T13:25:21.490

15

05AB1E, 39 33 31 bytes

Thanks to Magic Octopus Urn for saving 6 bytes!

Code

6xsG12N-N•°£•NèØú«тR∞Nè¶×]\6».c

Some 33 byte alternatives:

711ćŸā•Σ°w•₂вú‚øJƵt3в¶×‚ø»6xŠ».c¦
6xsŸ5L•Σ°w•₂вúõ¸ì‚ζJï2Ý«ƶ×)ø».c
6xsG¶12N-N•Θ{©•₂вNèú«ƵB∞Nè¶×]6J.c
6xsG12N-N•Θ{©•₂вNèú«тR∞Nè¶×]6s».c

Uses the 05AB1E encoding. Try it online!

Adnan

Posted 2018-08-09T01:33:30.760

Reputation: 41 965

Nice answer! I like the use of ÿ with .V, very original! And funny how you've used 12¤ to get both 12 and 2 on the stack. I probably would have just used 12Y, but I guess how is irrelevant, since both have 12 and 2 on the stack. If I would have tried this challenge in 05AB1E I would have ended way higher in byte-count.. Guess I still have much to learn. ;) – Kevin Cruijssen – 2018-08-09T09:52:59.777

@KevinCruijssen Oh yeah, I forgot about Y. That would have been an easier option hahaha. – Adnan – 2018-08-09T11:29:53.287

I don't know if I'm fixing the 6 in under 6 bytes: 6xsŸ5L•δ;Ì’•2ôúð.ø‚ζJ012∞S¶×‚ζJ.c but you're welcome to anything of use in here. – Magic Octopus Urn – 2018-08-09T15:05:35.307

1@MagicOctopusUrn Nice trick with the zip, I did not think of that. – Adnan – 2018-08-09T17:00:45.257

1@adnan props on 6xŠ» too, I would've never thought of that. – Magic Octopus Urn – 2018-08-09T17:19:14.730

10

6502 machine code (C64), 82 76 73 bytes

00 C0 A2 0E BD 38 C0 29 03 A8 A9 0D 20 25 C0 BD 38 C0 4A 4A A8 A9 20 20 25 C0
BD 29 C0 20 D2 FF CA 10 E1 60 20 D2 FF 88 10 FA 60 36 35 37 34 38 33 39 32 30
31 31 31 31 32 31 31 2C 1A 4C 0B 5C 03 4C 00 06 2C 00 15 00 2C
  • -6 bytes, thanks to Arnauld for the clever idea :)
  • another -3 bytes after Arnauld's idea not to treat leading 1 digits specially

The idea here is to only store the digits of all the numbers in the order they are needed. Additional info required is the number of newlines to prepend and the number of spaces in front.

The maximum number of newlines is 3, so we need 2 bits for this, and the maximum number of spaces is 23, therefore 5 bits are enough. Therefore, for each digit to print, we can squeeze this info in a single "control byte".

So, the data for this solution takes exactly 30 bytes: 15 single digits and 15 associated "control bytes".

Online demo

Usage: SYS49152 to start.

Commented disassembly:

         00 C0                          ; load address
.C:c000  A2 0E       LDX #$0E           ; table index, start from back (14)
.C:c002   .mainloop:
.C:c002  BD 38 C0    LDA .control,X     ; load control byte
.C:c005  29 03       AND #$03           ; lowest 3 bits are number of newlines
.C:c007  A8          TAY                ; to Y register for counting
.C:c008  A9 0D       LDA #$0D           ; load newline character
.C:c00a  20 25 C0    JSR .output        ; repeated output subroutine
.C:c00d  BD 38 C0    LDA .control,X     ; load control byte
.C:c010  4A          LSR A              ; and shift by two positions for ...
.C:c011  4A          LSR A              ; ... number of spaces
.C:c012  A8          TAY                ; to Y register for counting
.C:c013  A9 20       LDA #$20           ; load space character
.C:c015  20 25 C0    JSR .output        ; repeated output subroutine
.C:c018  BD 29 C0    LDA .digits,X      ; load current digit
.C:c01b  20 D2 FF    JSR $FFD2          ; output
.C:c01e  CA          DEX                ; decrement table index
.C:c01f  10 E1       BPL .mainloop      ; still positive -> repeat
.C:c021  60          RTS                ; and done.
.C:c022   .outputloop:
.C:c022  20 D2 FF    JSR $FFD2          ; output a character
.C:c025   .output:
.C:c025  88          DEY                ; decrement counting register
.C:c026  10 FA       BPL .outputloop    ; still positive -> branch to output
.C:c028  60          RTS                ; leave subroutine
.C:c029   .digits:
.C:c029  36 35 37 34 .BYTE "6574"
.C:c02d  38 33 39 32 .BYTE "8392"
.C:c031  30 31 31 31 .BYTE "0111"
.C:c035  31 32 31    .BYTE "121"
.C:c038   .control:
.C:c038  31 2C 1A 4C .BYTE $31,$2C,$1A,$4C
.C:c03c  0B 5C 03 4C .BYTE $0B,$5C,$03,$4C
.C:c040  00 06 2C 00 .BYTE $00,$06,$2C,$00
.C:c044  15 00 2C    .BYTE $15,$00,$2C

Felix Palmen

Posted 2018-08-09T01:33:30.760

Reputation: 3 866

2Could you save 2 bytes by using a subroutine doing JSR $FFD2 / DEY / BNE loop / LDA .control,X / RTS called for both newlines and spaces? I think it would be +10 bytes long and save -12 bytes in the main code. – Arnauld – 2018-08-09T15:06:25.907

1Actually, I think you can save more bytes if the subroutine is doing JSR $FFD2 / DEY / BPL loop / LDA .control,X / RTS and the entry point is the DEY. This way, you don't have to test 0 in the main code. – Arnauld – 2018-08-09T15:25:13.053

Thanks nice idea, will edit later. The latter however won't work, I need a case that skips the whole loop. – Felix Palmen – 2018-08-09T16:12:14.283

1If Y=0, DEY / BPL / RTS will exit immediately without processing any JSR $FFD2. (Note that with that scheme, the entry point of the subroutine must be DEY.) – Arnauld – 2018-08-09T16:14:40.353

@Arnauld Yep, that's clever :) Used this idea now, thanks! – Felix Palmen – 2018-08-10T09:15:27.497

I like the way you stored the extra "1" in the control byte. However, this is currently costing 9 bytes (BPL / LDA / JSR and the AND $7F). Encoding them as 3 extra 'standard' digits would cost only 6 bytes. – Arnauld – 2018-08-10T09:55:27.483

@Arnauld plus load LDA digit2,X and output JSR $FFD2 which is 6 bytes as well? Or do you have a better idea here? – Felix Palmen – 2018-08-10T10:10:40.947

Ah now I get what you mean. Indeed, this should work :) – Felix Palmen – 2018-08-10T10:17:12.637

Maybe ... it still avoids two times explicit 0 checking (4 bytes) and one instance of JSR/DEY/BNE (6 bytes) at the expense of 2 times JSR (6 bytes) and one RTS (1 byte) ... should still be better, but I'll double-check :) – Felix Palmen – 2018-08-10T11:06:50.937

1@Arnauld after quite some experimentation, I think it's shortest to keep the subroutine while using your suggestion of storing all digits :) – Felix Palmen – 2018-08-17T11:17:07.537

6

Perl 6, 76 74 bytes

$_="K12
E11K1

A10S2


9W3


B8S4

F7K5
L6";say S:g/<:Lu>/{" "x$/.ord-64}/

Try it online!

Port of Arnauld's answer until I can come up with something shorter.

Jo King

Posted 2018-08-09T01:33:30.760

Reputation: 38 234

6

R, 75 68 bytes

write("[<-"(rep("",312),utf8ToInt('*`®÷ĥĹĚä—M'),1:12),1,25)

Try it online!

Compressed the digits positions. Did this after spending lots of time trying to come up with a trigonometric answer (see history of edits).

Inspired by this other R answer buy J.Doe - upvote it !

Saved 7 bytes thanks to J.Doe.

JayCe

Posted 2018-08-09T01:33:30.760

Reputation: 2 655

68 bytes - changed hash to avoid arithmetic and altered the write call to use the default separator. – J.Doe – 2018-09-03T08:51:22.557

1@J.Doe It makes more sense this way. Of course not having documented my golf I have no clue why I did a convoluted hash in the first place... – JayCe – 2018-09-03T15:11:35.437

5

Java 8 11, 141 138 bytes

v->{for(var x:"92BCN5BB92BNN1BA991CNNNJ995DNNN2I991ENN6H92FN93G".getBytes())System.out.print(x<59?" ".repeat(x-48):(char)(x>76?10:x-17));}

Try it online (NOTE: String.repeat(int) is emulated as repeat(String,int) for the same byte-count, because Java 11 isn't on TIO yet.)

Explanation is similar as below, but it uses " ".repeat(x-48) for the spaces instead of format with "%"+(x-48)+"s".


Java 8, 141 bytes

v->{for(var x:"92BCN5BB92BNN1BA991CNNNJ995DNNN2I991ENN6H92FN93G".getBytes())System.out.printf("%"+(x>58?"c":x-48+"s"),x>76?10:x>58?x-17:"");}

Try it online.

Explanation:

v->{                        // Method with empty unused parameter and no return-type
  for(var x:"92BCN5BB92BNN1BA991CNNNJ995DNNN2I991ENN6H92FN93G".getBytes())
                            //  Loop over the bytes of the above String:
    System.out.printf("%"+  //   Print with format:
     (x>58?                 //    If the character is a letter / not a digit:
       "c"                  //     Use "%c" as format
      :                     //    Else:
       x-48+"s"),           //     Use "%#s" as format, where '#' is the value of the digit
     x>76?                  //    If the byte is 'N':
      10                    //     Use 10 as value (newline)
     :x>58?                 //    Else-if the byte is not a digit:
      x-17                  //     Use 48-58 as value (the 0-9 numbers of the clock)
     :                      //    Else:
      "");}                 //     Use nothing, because the "%#s" already takes care of the spaces

Further explanation 92BCN5BB92BNN1BA991CNNNJ995DNNN2I991ENN6H92FN93G:

  • All the digits will be replaced with that amount of spaces. (For 11 spaces it's therefore 92.)
  • All 'N' are new-lines
  • All ['A','J'] are clock digits ([0,9])

Kevin Cruijssen

Posted 2018-08-09T01:33:30.760

Reputation: 67 575

5

HTML + JavaScript (Canvas), 13 + 161 = 174 bytes

Arbitrary canvas positioning uses 6 bytes.

with(C.getContext`2d`)with(Math)for(font='9px monospace',textAlign='end',f=x=>round(sin(x*PI/6)*6)*measureText(0).width*2,x=13;--x;)fillText(x,f(x)+80,f(9-x)+80)
<canvas id=C>

With grid for comparison:

with(C.getContext`2d`)with(Math){
    for(font='9px monospace',textAlign='end',f=x=>round(sin(x*PI/6)*6)*measureText(0).width*2,x=13;--x;)fillText(x,f(x)+80,f(9-x)+80)
    for(globalAlpha=0.2,y=-6;y<=6;y++)fillText('.'.repeat(25),6*measureText('.').width*2+80,y*measureText(0).width*2+80)
}
<canvas id=C>

Explanation of Positioning Formula

See my JavaScript with SVG answer.

darrylyeo

Posted 2018-08-09T01:33:30.760

Reputation: 6 214

8I don't think this counts because since this is ASCII-art we are supposed to generate the exact byte-stream specifies in the challenge while this renders an image that looks like output. – Downgoat – 2018-08-09T18:31:14.893

5

Haskell, 88 87 bytes

f=<<"k12{e11k1{{a10s2{{{9w3{{{b8s4{{f7k5{l6"
f c|c>'z'="\n"|c>'9'=' '<$['a'..c]|1<2=[c]

The encode-spaces-as-letters method (first seen in @Arnauld's answer) in Haskell. Using { and expanding it to \n is one byte shorter than using \n directly.

Try it online!

nimi

Posted 2018-08-09T01:33:30.760

Reputation: 34 639

5

R, 168 159 125 bytes

The naive solution of writing the numbers at the prescribed points in a text matrix. Points are stored as UTF-8 letters decoded via utf8ToInt

"!"=utf8ToInt
write("[<-"(matrix(" ",25,13),cbind(!"LMFGSBCWAYCWGSM",!"AABBBDDDGGJJLLM")-64,-64+!"ABAAAA@BICHDGEF"),1,25,,"")

Dropped 9 bytes with JayCe's suggestion to use write and avoid defining the matrix.

Dropped another 34 bytes with JayCe's storage suggestion.

J.Doe

Posted 2018-08-09T01:33:30.760

Reputation: 2 379

Hello and welcome to PPCG! I think the dots are supposed to help visualize the pattern, but not part of the output. – Jonathan Frech – 2018-08-09T18:42:58.673

Welcome to PPCG! you can asve some bytes not defining m and using write: TIO. PS: you are not obliged to include a TIO link in your answer but it formats the answer nicely for you, see link icon on top of TIO page.

– JayCe – 2018-08-09T18:49:47.853

You can store the points in a string and overload the ! operator to get to 125 chars. Really nice solution!

– JayCe – 2018-08-09T19:07:50.330

5

Rust, 96 bytes

||format!(r"{:13}
     11{:12}

 10{:20}


9{:24}


  8{:20}

{:7}{:12}
{:13}",12,1,2,3,4,7,5,6)

Try it online!

Herman L

Posted 2018-08-09T01:33:30.760

Reputation: 3 611

5

brainfuck, 240 235 bytes

++++++++++[>++>+>+++>+++++>++>++[<]>-]>>>++...........>-.+.<<.>.....>-..<...........>.<<..>.>.-.>-[<<.>>-]<++.<<...>>+++++++.>>+++[<<<.>>>-]<<------.<<...>..>+++++.<<<-[>>.<<-]>>>----.<<..>......>+++.<...........>--.<<.>............>+.

Try it online!

Commented code

++++++++++                              Put 10 in cell 0
[>++>+>+++>+++++>++>++[<]>-]            Loop 10 times incrementing to leave 0 20 10 30 50 20 20 in memory 
>>>++                                   30 plus 2 = 32 (ascii space)
...........>-.+.                        print 11spaces followed by 12 (ascii 49 50)
<<.>.....>-..<...........>.             print 1newline 5spaces 11 11spaces 1 
<<..>.>.-.>-[<<.>>-]<++.                print 2newlines 1space 10 19spaces 2
<<...>>+++++++.>>+++[<<<.>>>-]<<------. print 3newlines         9 23spaces 3
<<...>..>+++++.<<<-[>>.<<-]>>>----.     print 3newlines 2spaces 8 19spaces 4
<<..>......>+++.<...........>--.        print 2newlines 6spaces 7 11spaces 5
<<.>............>+.                     print 1newline  12spaces 6

A rare example where the text is repetitive enough that the brainfuck program is less than twice 1.6 times the length of the output!

2 bytes saved by suggestion from Jo King: >>>>>>- -> [<]>-

3 bytes saved by moving the third 20-place downcounter from far right of the ascii codes 10 30 50 to immediately to the left of them. Saves <<>> when filling the gap between 8 and 4 but adds 1 byte to the line >>>++ .

Original version

++++++++++                              Put 10 in cell 0
[>+>+++>+++++>++>++>++<<<<<<-]          Loop 10 times incrementing to leave 0 10 30 50 20 20 20 in memory 
>>++                                    30 plus 2 = 32 (ascii space)
...........>-.+.                        print 11spaces followed by 12 (ascii 49 50)
<<.>.....>-..<...........>.             print 1newline 5spaces 11 11spaces 1 
<<..>.>.-.>-[<<.>>-]<++.                print 2newlines 1space 10 19spaces 2
<<...>>+++++++.>>+++[<<<.>>>-]<<------. print 3newlines         9 23spaces 3
<<...>..>+++++.>>>-[<<<<.>>>>-]<<<----. print 3newlines 2spaces 8 19spaces 4
<<..>......>+++.<...........>--.        print 2newlines 6spaces 7 11spaces 5
<<.>............>+.                     print 1newline  12spaces 6

Level River St

Posted 2018-08-09T01:33:30.760

Reputation: 22 049

4

C (gcc), 145 137 125 bytes

Only the tab positions are hard-coded: all the line spacings and clock values are generated in the loop.

Thanks again to ceilingcat for the suggestions.

i,j,k;f(char*t){for(i=7;i--;t=memset(t+sprintf(t,"%*d%*d"+3*!j,"NHDA"[j]-65,6+i,"AMUY"[j]-65,6-i),10,k=j+i/4)+k)j=i>3?6-i:i;}

Try it online!

ErikF

Posted 2018-08-09T01:33:30.760

Reputation: 2 149

Suggest "\r\7\3"[j] instead of "NHDA"[j]-65 – ceilingcat – 2019-10-22T22:01:58.620

4

Python 2, 97 bytes

for i in range(7):w=abs(3-i);print'%*d'%(1-~w*w,12-i),'%*d'%(24-3**w-2*w,i)*(w<3),'\n'*min(i,5-i)

Try it online!

Computes all spacings and newlines in the loop

TFeld

Posted 2018-08-09T01:33:30.760

Reputation: 19 246

4

Jelly, 32 bytes

⁶ẋ“¿×¿ Œ4ç4Œ!¿Ø‘ż“øn0œ’Œ?D¤Fs25Y

A full program which prints the result.

Try it online!

How?

(I have not yet thought of/found anything shorter than “¿×¿ Œ4ç4Œ!¿Ø‘ which seems long to me for this part - bouncing / base-decompression / increments, nothing seems to save!)

⁶ẋ“¿×¿ Œ4ç4Œ!¿Ø‘ż“øn0œ’Œ?D¤Fs25Y - Main Link: no arguments
⁶                                - space character
  “¿×¿ Œ4ç4Œ!¿Ø‘                 - code-page indices list = [11,17,11,32,19,52,23,52,19,33,11,18]
 ẋ                               - repeat (vectorises) -> [' '*11, ' '*17, ...]
                          ¤      - nilad followed by link(s) as a nilad:
                 “øn0œ’          -   base 250 number = 475699781
                       Œ?        -   first natural number permutation which would be at
                                 -   index 475699781 if all permutations of those same
                                 -   natural numbers were sorted lexicographically
                                 -   = [12,11,1,10,2,9,3,8,4,7,5,6]
                         D       -   to decimal lists = [[1,2],[1,1],[1],[1,0],[2],[9],[3],[8],[4],[7],[5],[6]]
                ż                - zip together = [[' '*11, [1,2]], [' '*17, [1,1]], ...]
                           F     - flatten = [' ',' ',...,1,2,' ',' ',...,1,1,...]
                            s25  - split into chunks of 25 (trailing chunk is shorter)
                               Y - join with new line characters
                                 - implicit print

Jonathan Allan

Posted 2018-08-09T01:33:30.760

Reputation: 67 804

LOL I'm actually surprised this is the naive approach. – Erik the Outgolfer – 2018-08-09T21:28:18.370

3

Powershell, 94 88 82 bytes

Direct Powershell format operator. {i,w} means a placeholder for a parameter with index i, width of the placeholder is w with right align.

"{11,13}
{10,7}{0,12}

 10{1,20}


9{2,24}


  8{3,20}

{6,7}{4,12}
{5,13}"-f1..12

Powershell, 88 bytes

Port of Arnauld's Javascript answer

-6 bytes thanks to @AdmBorkBork

[RegEx]::Replace("K12
E11K1

A10S2


9W3


B8S4

F7K5
L6",'[A-Z]',{' '*("$args"[0]-64)})

To better see the grid, use '.' instead ' '.

mazzy

Posted 2018-08-09T01:33:30.760

Reputation: 4 832

1

Why not string multiplication instead of .PadLeft for 88 bytes -- Try it online!

– AdmBorkBork – 2018-08-09T13:01:02.957

That's a clever use of -f. Why don't you include links to Try it online! so others can see how your code works?

– AdmBorkBork – 2018-08-10T12:51:50.640

I have the error This site can’t be reached only. Sorry. – mazzy – 2018-08-10T13:01:18.420

Ah, that's a shame. It's a good resource. :-( – AdmBorkBork – 2018-08-10T13:10:47.457

I'm agree. Thanks. – mazzy – 2018-08-10T13:11:28.333

3

PHP, 97 bytes

<?=gzinflate(base64_decode(U1CAA0MjLghtqIAkyMWlYGiggAmMuLi4LBWwA2OgnIKCBRYZEy6IHQrmSIKmXMhKzAA));

Try it online!

This is a hard coded compressed string. I couldn't find a solution shorter than this!

Night2

Posted 2018-08-09T01:33:30.760

Reputation: 5 484

Can you put the binary compressed string in the source file and skip the base64_decode? I tried this and I get a 'gzinflate(): data error', but it might be possible if the source file was written witha hex editor instead of a text editor. – bdsl – 2018-08-09T19:35:01.443

@bdsl actually I did that before and you don't need a HEX editor, you can just use PHP itself file_put_contents($path, '<?=gzinflate("'.gzdeflate($clockString,9).'");');, but I'm not sure how to post a code with binary data inside it. A file like that is 70 bytes. – Night2 – 2018-08-10T04:28:45.723

3

C (gcc), 125 109 105 bytes

x,*d=L"<;1:2938475640P`P05";main(i){for(;i=d[12];printf("%*d",i/4,*d++-48))for(x=i&3;x--;)puts("");}
  • -16 bytes (-3 for better loop arrangement, -13 for directly including the non-printable chars) thanks to Jonathan Frech.
  • -4 bytes by replacing a division for a shift and abusing the fact that on many systems (like the one hosting TIO), sizeof(wchar_t) == sizeof(int) -- won't work on windows :) Thanks ErikF for the idea.

Try it online!

This is a port of my general idea from the 6502 solution to C. It's a bit modified: Instead of having a flag for a leading 1, the character is printed as a decimal by subtracting 48, so 10 - 12 are encoded as : to <.

Felix Palmen

Posted 2018-08-09T01:33:30.760

Reputation: 3 866

1109 bytes. – Jonathan Frech – 2018-08-09T14:14:15.340

@JonathanFrech nice loop rearrangement, I wonder how I missed that one :o But really didn't expect gcc to accept non-printable characters in the source :) – Felix Palmen – 2018-08-09T14:24:30.033

As long as the character can be represented in UTF-8, it's technically acceptable by the compiler. Whether that's a good thing rather depends on what you're doing :-)

– ErikF – 2018-08-09T15:28:59.983

Speaking of Unicode, you can save 3 more bytes by using wide characters: Try it online!

– ErikF – 2018-08-09T15:37:06.387

Nice trick ... would break on windows because it assumes wchar_t==int, but will edit later ;) – Felix Palmen – 2018-08-09T15:56:50.743

1That's why I like code golfing: I get to abuse UB and use all those "things you shouldn't do" that you pick up over time! – ErikF – 2018-08-09T22:55:38.870

@ErikF used your idea now :) In fact, I've seen it in your submission and just forgot later. – Felix Palmen – 2018-08-10T06:54:04.213

One last thing I saw: replace i>>2 with i/4 to save another byte (and possibly move main to the footer for another 3): Try it online!

– ErikF – 2018-08-10T07:01:13.670

@ErikF thanks again, used the division! Although I guess it's allowed to submit a function that only works a single time, this "feels" somehow wrong :o – Felix Palmen – 2018-08-10T07:21:44.140

3

Pyke, 37 bytes

3B 32 35 75 07 0d 13 0c 22 14 35 18 44 74 5F 74 2B 46 6F 68 32 C4 52 7D 74 2A 31 32 25 31 32 7C 60 52 2D 29 73

Try it here! (raw bytes)

;25Dt_t+Foh2.DR}t*12%12|`R-)s

Try it here! (Human readable)

                              - o = 0
;25                           - set line width to 25 characters
                              -      `[13, 19, 12, 34, 20, 53, 24]`
                              -       (In hex version, encoded in base 256, regular version in input field)
    t_t                       -     reversed(^[1:])[1:]
   D   +                      -    ^^ + ^
        Foh2.DR}t*12%12|`R-)  -   for i in ^:
         o                    -            o++
          h                   -           ^+1
           2.DR               -          divmod(^, 2)
               }t             -         (remainder*2)-1
                 *            -        quotient * ^
                  12%         -       ^ % 12
                     12|      -      ^ or 12 (12 if 0 else ^)
                        `     -     str(^)
                         R-   -    ^.rpad(i) (prepend spaces such that length i)
                            s -  sum(^)
                              - output ^ (with newlines added)

Blue

Posted 2018-08-09T01:33:30.760

Reputation: 26 661

3

brainfuck, 315 313 bytes

saved 2 bytes thanks to ovs!

++++[>++++<-]>[>+++>+++>+++>+++>>++>+++>+++>+++<<<<<<<<<-]>+++++>++++>+++>++>++++++++++>>+++++++>+><<<...........>>.<<<<.>.>.....>>..<<...........>>.<<<..>.>>.>.<<<...................<<.>...>>++.<.......................<<<.>>...>..>-.<...................<<<<.>>>..>......>-.<...........<<<<<.>>>>.>............>-.

Try it online!

all in one code block:

++++[>++++<-]>[>+++>+++>+++>+++>>++>+++>+++>+
++<<<<<<<<<-]>+++++>++++>+++>++>++++++++++>>+
++++++>+><<<...........>>.<<<<.>.>.....>>..<<
...........>>.<<<..>.>>.>.<<<................
...<<.>...>>++.<.......................<<<.>>
...>..>-.<...................<<<<.>>>..>.....
.>-.<...........<<<<<.>>>>.>............>-.

Conor O'Brien

Posted 2018-08-09T01:33:30.760

Reputation: 36 228

You can use ++++[>++++<-]> for the 16 at the beginning. – ovs – 2018-08-09T19:17:23.633

@ovs Ah, of course, thanks!! – Conor O'Brien – 2018-08-09T19:56:58.797

Lol, you have >< in your code – Jo King – 2018-08-10T09:19:57.180

2

Attache, 69 bytes

{ReplaceF["l12
f11l1

b10t2


9x3


c8t4

g7l5
m6",/"\\l",sp&`*@STN]}

Try it online!

This encodes each run of spaces as: NTS[count of spaces]; NTS is the "numeric to short" builtin, which allows numbers to be expressed as strings. E.g., NTS[95] = $R1 and NTS[170297] = $XQO. STN is the inverse of this builtin.

This answer replaces (ReplaceF) all occurences of letters (/\l/) in the input with the result of the function sp&`*@STN, which firsts decodes the letter and then repeats sp (a space) that many times.

Conor O'Brien

Posted 2018-08-09T01:33:30.760

Reputation: 36 228

2

Swift, 178 165 bytes

var b="";for c in"L12nF11L1nnB10T2nnn9X3nnnC8T4nnG7L5nM6"{let i=c.unicodeScalars.first!.value;if c=="n"{b+="\n"}else if i>64{for _ in 0..<(i-65){b+=" "}}else{b+="(c)"}};print(b)

Based on what Downgoat posted, I've reduced this to 165 bytes:

print("L12nF11L1nnB10T2nnn9X3nnnC8T4nnG7L5nM6".unicodeScalars.map{let x=Int($0.value);return x==110 ?"\n":(x>64 ?String(repeating:" ",count:x-65):"($0)")}.joined())

Expanded out, with $0 converted to a named variable:

print("L12nF11L1nnB10T2nnn9X3nnnC8T4nnG7L5nM6".unicodeScalars.map { c in let x = Int(c.value) return x == 110 ? "\n" : (x>64 ? String(repeating:" ", count: x-65) : "(c)") }.joined())

The input string is encoded as follows: Uppercase letters (A-Z) represent blocks of spaces, offset by 65. So A means 0 spaces, B means 1 space, the first L means 11 spaces, etc. ns are converted to newlines. All other characters are printed as-is.

Run it online here (thanks, mbomb007)

Ezekiel Elin

Posted 2018-08-09T01:33:30.760

Reputation: 121

Welcome to PPCG! Many of us use Try It Online (TIO) for online interpreters to include a hyperlink to the program in our answers. Here is the one for your answer: https://tio.run/##JY1BC4IwGIb/yvpOSjScqRW2DgV1sVMeOgQx14SBfMacdhB/@1p2eeF5eV7e7qNrmzg3CEMqDpDXrSGSaISCxXhmrGAZ4pFFZYyIu/va52lbJoiXTZHiNYOxUdb7lkvao5btS92kaITpaK1NZxd0EE2vcl0TyTkgjNWSwwNhUk2niK/99pAl4@/46YFElO4DX66yNJxlAtMs/5eBDD3nb@OVoAqd@wI

– mbomb007 – 2018-08-09T17:40:57.043

Here's a golf of your answer that's 172 bytes. It uses a function instead: {"L12NF11L1NNB10T2NNN9X3NNNC8T4NNG7L5NM6".unicodeScalars.map({(c)->String in let x=c.value;return x==78 ? "\n" : x>64 ?String(repeating:" ",count:x-65) : "\(c)"}).joined()} (swift 3 (-swift-version 3 on repl) because swift 4 dropped subtraction it looks like) – Downgoat – 2018-08-09T18:52:18.613

@Downgoat I reduced it another 3 bytes and made it compatible with Swift 4. See updated post. – Ezekiel Elin – 2018-08-09T19:43:54.363

2

Pure Bash, 123

printf does the heavy-lifting here:

n=" 0 a 0 a"
printf -vo %*s%*s\\n 0 a 13 12 7 11 12 1 $n 3 10 20 2$n$n 1 9 24 3$n$n 3 8 20 4$n 7 7 12 5 13 6
echo "${o//a}"

Try it online!

Digital Trauma

Posted 2018-08-09T01:33:30.760

Reputation: 64 644

1

Red, 151 bytes

foreach[a b c d][13 12 1""7 11 12 1 1""1""3 10 20 2 1""1"^/"0 9 24 3 1""1"^/"3 8 20 4 1""1""7 7 12 5 13 6 1""][print rejoin[pad/left b a pad/left d c]]

Try it online!

Galen Ivanov

Posted 2018-08-09T01:33:30.760

Reputation: 13 815

1

JavaScript with SVG, 188 bytes

Arbitrary line height of 120% uses 4 bytes.

with(Math)for(s='<pre><svg viewBox=-8-8+16+16 style=font-size:1;text-anchor:end>',f=x=>round(sin(x*PI/6)*6),x=13;--x;)s+=`<text x=${f(x)*2}ch y=${f(9-x)*1.2}>${x}</text>`
document.write(s)

With grid for comparison:

with(Math)for(s='<pre><svg viewBox=-8-8+16+16 style=font-size:1;text-anchor:end>',f=x=>round(sin(x*PI/6)*6),x=13;--x;)s+=`<text x=${f(x)*2}ch y=${f(9-x)*1.2}>${x}</text>`
for(y=-6;y<=6;y++)s+=`<text x=12ch y=${y*1.2} style=fill:#0002>${'.'.repeat(25)}</text>`
document.write(s)


Explanation of Positioning Formula

Let f(x) = round(sin(x * π/6) * 6).

Assuming the origin is the center of the clock, the grid coordinates of the right-most digit of any given clock number x is [f(x) * 2, f(9 - x)].

darrylyeo

Posted 2018-08-09T01:33:30.760

Reputation: 6 214

1

Bash, 225 bytes

s=(12 0 6 11 0 0 2 19 0 0 0 0 1 23 0 0 0 0 3 19 0 0 7 11 13 0)
n=(12 11 1 10 2 9 3 8 4 7 5 6) j=0;for i in {0..25};{
[ ${s[i]} = 0 ]||{ printf %${s[i]}s " ";echo -n ${n[j]}
j=$((j+1));};[ $((i%2)) -gt 0 ]&&echo;}|sed 's/ //'

Annoyingly this is longer than the naive solution of just printing each line in a loop (132 characters if making use of tabstops).

crystalgecko

Posted 2018-08-09T01:33:30.760

Reputation: 51

Would tr -d \<space> (where <space> is the space character) work instead of the sed substitution? – user41805 – 2018-08-28T15:24:04.200

@Cowsquack sadly not, tr -d\ would be equivalent to sed 's/ //g' – crystalgecko – 2018-08-29T12:41:27.403

1

T-SQL, 132 bytes

PRINT SPACE(11)+'12
     11           1

 10'+SPACE(20)+'2


9'+SPACE(23)+'3


  8'+SPACE(19)+'4

      7           5
            6'

Only 12 bytes shorter than the trivial solution (PRINT of the entire string as-is).

Found a variation I like that is much longer (235 226 bytes), but much more SQL-like:

SELECT CONCAT(SPACE(PARSENAME(value,4)),PARSENAME(value,3),
              SPACE(PARSENAME(value,2)),PARSENAME(value,1))
FROM STRING_SPLIT('11.1..2,5.11.11.1,. .. ,1.10.20.2,. .. ,. .. ,.9.23.3,
                   . .. ,. .. ,2.8.19.4,. .. ,6.7.11.5,12.6.. ',',')

STRING_SPLIT breaks it into rows at the commas, and PARSENAME splits each row at the dots. The 1st and 3rd are used for how many spaces to print, the 2nd and 4th are used for what to display.

(line breaks in this one are just for readability)

BradC

Posted 2018-08-09T01:33:30.760

Reputation: 6 099

1

Python 3, 112 88 87 bytes

A solution using string interpolation.

print(f'''{12:13}
{11:7}{1:12}

 10{2:20}


9{3:24}


  8{4:20}

{7:7}{5:12}
{6:13}''')

Try it online!

-25 bytes thanks to ovs and Herman L.

mbomb007

Posted 2018-08-09T01:33:30.760

Reputation: 21 944

And if you use Hermans formatting string you can get this to ~85 bytes.

– ovs – 2018-08-09T20:52:10.413

One more byte with {11:7}. – ovs – 2018-08-09T21:11:58.273

1

C (gcc), 135 123 110 bytes

This uses a simple encoding where any c between 'a' and 'z' represents c-'a'+1 repeated spaces, '`' represents a newline, and all other characters are left unchanged.

f(i){char*s="k12`e11k1``a10s2```9w3```b8s4``f7k5`l6`";for(;i=*s;s++)i>96?printf("%*s",i-96,""):putchar(i%86);}

Try it online!

Curtis Bechtel

Posted 2018-08-09T01:33:30.760

Reputation: 601

Suggest *s=L"...";f(i){ instead of f(i){char*s="..."; – ceilingcat – 2018-08-30T19:27:29.587

1

Perl 6, 116 bytes

my@a=["  "xx 13]xx 13;($_=pi/6*++$;@a[0+|6*(1.1-.cos);0+|6*(1.1+.sin)]=fmt ++$: "%2s")xx 12;@a>>.join>>.&{say S/.//}

Try it online!

(Ta @JoKing for saving 26 bytes)

Perl 6, 142 bytes

my@a=[[[32,32]xx 13]xx 13];for 1..12 {$_=$^b*pi/6;@a[round 6*(1-.cos);round 6*(1+.sin)]=[" $b".ords.tail(2)]}
{say S/^.//}(.[*;*].chrs) for @a

Try it online!

I wanted to do something... different. So this one calculates the positions of all the digits, via pairs of characters, strips off the initial space and prints the lines.

Easily modifiable for different parameters, e.g. a 45 character wide version with 17 digits.

Phil H

Posted 2018-08-09T01:33:30.760

Reputation: 1 376

116 bytes – Jo King – 2018-08-31T05:53:14.130

@JoKing: Ta, I've pasted that in & made it a wiki. – Phil H – 2018-08-31T07:50:45.213

0

Perl 5, 73 bytes

Port of Arnauld's answer.

say"K12
E11K1

A10S2


9W3


B8S4

F7K5
L6"=~s,[A-Z]," "x(ord($&)-64),erg

Try it online!

As a one-liner:

perl -E'say"K12\nE11K1\n\nA10S2\n\n\n9W3\n\n\nB8S4\n\nF7K5\nL6"=~s,[A-Z]," "x(ord($&)-64),erg'

Another approach, but longer:

map$s.=$_%26?{12,12,32,11,44,1,80,10,100,2,157,9,181,3,237,8,257,4,293,7,
305,5,325,6}->{$_}||" ":"\n",1..338;
say$s

Kjetil S.

Posted 2018-08-09T01:33:30.760

Reputation: 1 049

0

Python, 99, 91

print"%13d\n%7d%12d\n\n%3d%20d\n\n\n9%24d\n\n\n%3d%20d\n\n%7d%12d\n%13d"%(12,11,1,10,2,3,8,4,7,5,6)

print"""%13d
%7d%12d

%3d%20d


9%24d


%3d%20d

%7d%12d
%13d"""%(12,11,1,10,2,3,8,4,7,5,6)

Thanks to Jo King

Spaces hardcoded in -- I'm sure its possible to golf the \ns down, by repeating but I don't know how...

Tobit

Posted 2018-08-09T01:33:30.760

Reputation: 1

You can use a multi-line string. Try it online!

– Jo King – 2018-08-31T05:17:27.687