26
\$\begingroup\$

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

Clock

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!

\$\endgroup\$
  • \$\begingroup\$ May we take the input as 0-indexed? Like, 0 -> 4, 7, 10? \$\endgroup\$ – Mr. Xcoder Dec 29 '17 at 21:20
  • 8
    \$\begingroup\$ @Mr.Xcoder sorry, this time I'm going to say no. \$\endgroup\$ – Charlie Dec 29 '17 at 21:26
  • 3
    \$\begingroup\$ Is this the fourth challenge now based on some activity involving your kids? :P \$\endgroup\$ – FlipTack Dec 29 '17 at 21:58
  • 3
    \$\begingroup\$ @FlipTack Perhaps we need an inspired-by-kids tag ;) \$\endgroup\$ – Steadybox Dec 29 '17 at 22:13
  • 6
    \$\begingroup\$ @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... \$\endgroup\$ – Charlie Dec 29 '17 at 22:17

35 Answers 35

1
2
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Java 8, 46 bytes

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

Try it online.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Ruby, 29 bytes

->n{3.times{p 12+(n+=3)%-12}}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.