# 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!

• @Mr.Xcoder sorry, this time I'm going to say no. Dec 29, 2017 at 21:26
• Is this the fourth challenge now based on some activity involving your kids? :P Dec 29, 2017 at 21:58
• @FlipTack Perhaps we need an inspired-by-kids tag ;) Dec 29, 2017 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... Dec 29, 2017 at 22:17
• @Steadybox That would be a meta tag, which is BAD. But yes, we do. (Perhaps a meta question with links would suffice?) Jan 1, 2018 at 10:32

# 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/… Jan 1, 2018 at 15:56 • @Cowsquack Note that the output in your link is wrong. Jan 1, 2018 at 16:29 # Perl 5, 30 bytes sub{map{($_+$_[0])%12+1}2,5,8}  Try it online! # PowerShell, 30 bytes param($a)2,5,8|%{($_+$a)%12+1}


Try it online!

# 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
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!

# Forth (gforth), 39 bytes

Input is taken from the stack and output is placed on the stack

: a 2 + 12 mod 1+ ; : f a dup a dup a ;


Try it online!

### Explanation

 : a 2 + 12 mod 1+ ; \ helper word to handle adding the hours
2 +              \ Add 2 to the input
12 mod           \ get the result modulo 12

: f a dup a dup a ; \ word that calculates and outputs the result
a dup            \ add 3 hours to the input and then duplicate the result
a dup            \ add 3 hours to the duplicate then duplicate the result
a                \ add 3 hours to the duplicate


# Java 8, 46 45 bytes

n->new int[]{1-~-~n%12,(5+n)%12+1,(8+n)%12+1}


-1 byte thanks to @ceilingcat.

Try it online.

# Perl 5-a, 27 bytes

say+(\$_+"@F")%12+1for 2,5,8


Try it online!

# Husk, 8 bytes

tĊ3ṙḣ12←


Try it online!

# x86-16 machine code, 12 bytes

00000000: b903 0004 02d4 0c40 aae2 f8c3              ...........


Listing

B9 0003     MOV  CX, 3          ; loop counter CX = 3
CLOOP:
04 02       ADD  AL, 2          ; AL = AL + 2
D4 0C       AAM  12             ; AL = AL % 12
40          INC  AX             ; AL = AL + 1
AA          STOSB               ; [DI++] = AL
E2 F8       LOOP CLOOP          ; if --CX > 0 goto CLOOP


Callable function, input in AL, output to buffer at [DI].

# Windows Batch, 137 125 111 68 bytes

@set/ab=(%1+2)%%12+1,c=(%1+5)%%12+1,d=(%1+8)%%12+1
@echo %b% %c% %d%


Port of the add value to input and mod 12 + 1

# Ruby, 29 bytes

->n{3.times{p 12+(n+=3)%-12}}


# J, 24 bytes

{&((,])}.i.13)@+&(2 5 8)


Try it online!

# Stax, 8 bytes

äÆL6C╪Θ♪


Run and debug it

### Approach

3 times:

An anonymous worksheet function that takes input from cell A1 and returns a 1x3 spilled array beginning at the calling cell.
=MOD(A1+{2,5,8},12)+1