# Output the hours at 90 degrees

Today while playing with my kids I noticed that an apparently simple toy in the park hid a challenge.

The wheel has a triangle that points to a number, but also has three circles that point to the numbers every 90 degrees from the first one. So:

Challenge (really simple)

Given an integer between 1 and 12 (the one pointed by the triangle) in any acceptable form, output also in any acceptable form and order the three numbers pointed by the circles (the ones every 90 degrees).

Test cases

In       Out
1        4, 7, 10
2        5, 8, 11
3        6, 9, 12
4        7, 10, 1
5        8, 11, 2
6        9, 12, 3
7        10, 1, 4
8        11, 2, 5
9        12, 3, 6
10       1, 4, 7
11       2, 5, 8
12       3, 6, 9


This is , so may the shortest code for every language win!

• May we take the input as 0-indexed? Like, 0 -> 4, 7, 10? – Mr. Xcoder Dec 29 '17 at 21:20
• @Mr.Xcoder sorry, this time I'm going to say no. – Charlie Dec 29 '17 at 21:26
• Is this the fourth challenge now based on some activity involving your kids? :P – FlipTack Dec 29 '17 at 21:58
• @FlipTack Perhaps we need an inspired-by-kids tag ;) – Steadybox Dec 29 '17 at 22:13
• @FlipTack I've lost count. :-) But given that I spent most of my free time with my kids, guess where does my inspiration come from... – Charlie Dec 29 '17 at 22:17

# Python 3, 33 bytes

lambda n:{*range(n%3,13,3)}-{n,0}


Try it online!

# Python 2, 35 bytes

lambda n:[(n+c)%12+1for c in 2,5,8]


Try it online!

# Jelly, 8 bytes

12Rṙ’m3Ḋ


A monadic link taking a number and returning a list of numbers.

Try it online! or see all cases.

### How?

12Rṙ’m3Ḋ - Link: number, n   e.g. 5
12       - literal twelve         12
R      - range                  [1,2,3,4,5,6,7,8,9,10,11,12]
’    - decrement n            4
ṙ     - rotate left            [5,6,7,8,9,10,11,12,1,2,3,4]
3  - literal three          3
m   - modulo slice           [5,8,11,2]
Ḋ - dequeue                [8,11,2]

• Alternative solution: 12Rṙm-3Ḋ (output in reverse order) – user202729 Dec 30 '17 at 2:14

# Python 2, 35 bytes

lambda n:(range(1,13)*2)[n+2:n+9:3]


Try it online!

# R,  29  28 bytes

Thanks to @Giuseppe for saving a byte!

function(n)(n+1:3*3-1)%%12+1


Try it online!

# MATL, 9 bytes

I:I*+12X\


Try it online!

### Explanation

Consider input 4 as an exmaple.

I:     % Push [1 2 3]
% STACK: [1 2 3]
I      % Push 3
% STACK: [1 2 3], 3
*      % Multiply, element-wise
% STACK: [3 6 9]
+      % Add implicit input, element-wise
% STACK: [7 10 13]
12     % Push 12
X\     % 1-based modulus. Implicit display
% STACK: [7 10 1]


# APL+WIN, 13bytes

(⎕⌽⍳12)[3×⍳3]


Explanation:

⎕ Prompt for screen input of indicated time t

⍳12 Create a vector of integers from 1 to 12

⌽ Rotate the vector by t elements front to back

[3×⍳3] Select 3rd, 6th and 9th elements.

• Quite neat. I like that indexed rotation approach – Uriel Dec 30 '17 at 18:47

# C (gcc), 48 bytes

i;f(n){for(i=4;--i;printf("%d ",n%12?:12))n+=3;}


Try it online!

# JavaScript (ES6), 29 bytes

n=>[2,5,8].map(k=>(n+k)%12+1)


### Demo

let f =

n=>[2,5,8].map(k=>(n+k)%12+1)

for(n = 1; n <= 12; n++) {
console.log(n + ' -> ' + f(n));
}

• I had n=>[3,6,9].map(v=>(v+n)%12) then realized that it returns 0, not 12... – ericw31415 Dec 30 '17 at 0:47
• @ericw31415 Actually, my 1st approach was n=>[3,6,9].map(v=>(v+n)%12||12) (but that's 31 bytes). – Arnauld Dec 30 '17 at 1:19

# Octave, 25 bytes

@(x)[a=1:12 a](3+x:3:9+x)


Try it online!

Fairly simple anonymous function.

We first create an array of [1:12 1:12] - so two copies of the full number set. Then we index in to select the values of x+3, x+6, x+9, where x is the number input.

Octave is 1-indexed, so we can simply select the array elements based on the input (although to be honest 0-indexed would use the same number of bytes here).

This seems to use a method that is unique to the other answers in that by having two copies of the array, we don't have to wrap the indices using modulo.

• Very nice, but the "boring" mod approach is shorter! Try it online! – Giuseppe Dec 30 '17 at 12:45
• @Giuseppe lol, I'm sure I tried using mod and couldn't make it shorter. Well done! Feel free to post as an answer. – Tom Carpenter Dec 30 '17 at 13:02

# Befunge-93, 2019 18 bytes

852<_@#:.+1%+66+&p


Try it online!

Explanation

852                   Push 8, 5 and 2 onto the stack - the offsets we're going to add.
<                  Reverse direction, and start the main loop.
852                   Push 2, 5, and 8 onto the stack, but we don't actually want these.
p    So we use a "put" operation to drop the top three values.
&     Read the hour from stdin.
+      Add it to the topmost offset.
+1%+66       Mod 12 and add 1 to get it in the range 1 to 12.
.             Then output the result to stdout.
_@#:              Exit if the next offset is zero (i.e. nothing more on the stack).
<                  Otherwise start the main loop again.


This relies on behaviour specific to the reference interpreter: on end-of-file, the & operator returns the last value that was read. That's why we can safely re-read the hour from stdin on each iteration of the loop.

• Neat. I didn’t know & did that – Jo King Dec 30 '17 at 6:14
• @JoKing Technically it's a bug in the interpreter, another related side-effect being that & can also be used as a kind of one-off random number generator. That is less reliable, though, since it depends on the compiler that was used to build it. It's working on TIO at the moment, but there was a time when Dennis changed to a different version of gcc and we lost that functionality for a while. – James Holderness Dec 30 '17 at 13:45

# APL (Dyalog), 12 bytes

1+12|2 5 8∘+


Try it online!

# SOGL V0.12, 9 bytes

3{3+:6«‰P


Try it Here!

# C# (.NET Core), 42 bytes

h=>new[]{(2+h)%12+1,(5+h)%12+1,(8+h)%12+1}


Try it online!

Essentially just a port of many of the other answers to C#.

# Japt, 11 bytes

3ÆU±3 uC ªC


Try it

## Explanation

Implicit input of integer U. Generate a 3 element array (3Æ) and, for each element, increment U by 3 (U±3), modulo by 12 (uC) and, because 12%12=0, return the result OR 12 (ªC).

# K (oK), 11 bytes

Solution:

1+12!2 5 8+


Try it online!

Examples:

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


Explanation:

This was the first solution that came to mind. Might not be the best or shortest.

1+12!2 5 8+ / the solution
2 5 8+ / add 2, 5 and 8 to the input
12!       / apply modulo 12 to the results


# GolfScript, 46 bytes

~13,1>:x?:y;0:i;x y 3+12%=x y 6+12%=x y 9+12%=


This is the first time I'm doing code golf, so with my lack of experience I've probably not found the best solution, but I need to start somewhere, right?

• Hello, welcome to the site! This looks like a nice first answer :) Unfortunately, I don't know anything about golfscript, but you might be able to get some tips here – James Dec 31 '17 at 19:20

# Brain-Flak, 84 bytes

(()()()){({}<(()(){})(((()()()){}){}<>){(({})){({}[()])<>}{}}<>(([{}]{})<>)>[()])}<>


Try it online!

At least I beat Doorknob's face solution...

Explanation:

LOOP 3 TIMES: (()()()){({}<

n += 2:
(()(){})
push 12:
(((()()()){}){}<>)
n mod 12 + 1; pushing to both stacks:
{(({})){({}[()])<>}{}}<>(([{}]{})<>)

END LOOP: >[()])}<>


# Pyth, 12 bytes

%R12+LQ*R3S3


Try it online!

• Welcome to the site! :) – James Jan 5 '18 at 18:54

# Clean, 44 bytes

import StdEnv
@n=[(n+i)rem 12+1\\i<-[2,5,8]]


Try it online!

# Pushy, 12 bytes

258s{K+12%h_


Try it online!

258            \ Push 258
s           \ Split into digits, yielding [2, 5, 8]
{K+        \ Add input to each
12%     \ Modulo each by 12
h    \ Increment each
_   \ Print (space separated)


## 12 bytes

An alternative for the same byte count:

12R{:{;$...#  Try it online! 12R \ Push range(1, 12), inclusive {: ; \ Input times do: { \ Rotate left$       \ While there are items on stack:
...    \   Pop the top three
#   \   Print top item


-2 bytes thanks to Laikoni.

f n=[mod(n+i)12+1|i<-[2,5,8]]


Try it online!

Not very original, no...

{n in[2,5,8].map{($0+n)%12+1}}  Try it online! Port of many other answers to Swift # Perl 6, 23 bytes {map ($_+*)%12+1,2,5,8}


Try it online!

# PHP, 37+1 bytes

while($i++<3)echo(~-$argn+=3)%12+1,_;


Run as pipe with -nR or try it online.

## face, 96 94 bytes

(%d
@)$*,c'ooiim%*m1*6%+%%%11m!*mn*m~*3!m&!r!&!is!&pn3!:L+nn1+nn1%nn%+nn1p~>inw~>~o-!!1?!L  This simply adds two, mods by 12, adds one more, and prints. Then it does that two more times. Commented version: (%d @)$*,c'$ooii ( store format string in$, ip in *, get stdin/out )
m%*m1*6%+%%%11  ( initialize constants, %=12, 1=1 )
m!*mn*m~*       ( malloc space for a counter, input var, and length )
3!m&!r!&!i      ( read into & )
s!&$pn ( scan into n ) 3!:L ( start of main loop, executed thrice ) +nn1+nn1 ( add 2 to n ) %nn%+nn1 ( mod by 12 and add 1 more ) p~>$in        ( sprintf n into > )
w~>~o         ( output to stdout )
-!!1          ( decrement counter )
?!L             ( conditional jump back to loop start )


Try it online! (The trailing newline is required on TIO due to a bug that's been fixed in a newer version of face.)

• Creating a variable that holds the value 3 m3*33 allows you to replace the three +nn1s with one +nn3 tio.run/… – user41805 Jan 1 '18 at 15:56
• @Cowsquack Note that the output in your link is wrong. – Doorknob Jan 1 '18 at 16:29

# Perl 5, 30 bytes

sub{map{($_+$_[0])%12+1}2,5,8}


Try it online!

param($a)2,5,8|%{($_+$a)%12+1}  Try it online! Port of the other answers (e.g., xnor's Python 2 answer). Ho-hum. # Octave, 23 bytes @(x)mod(x+[2 5 8],12)+1  Try it online! Takes the same approach as most others; and it is golfier than Tom Carpenter's somewhat more unique solution. # Pyt, 12 11 bytes 258á←+26*%⁺  Explanation: 258 Pushes 2,5,8 onto the stack á Converts the stack to an array, and pushes the array onto the now-empty stack ←+ Adds input to [2,5,8] 26*%⁺ Mod 12 plus 1 (the 'plus 1' allows for '12' to be output)  Try it online! # Tcl, 45 bytes proc R i {lmap c {2 5 8} {expr ($i+\$c)%12+1}}


Try it online!

Different approach using the command line arguments:

# Tcl, 39 bytes

time {puts [expr [incr argv 3]%12+1]} 3


Try it online!