30
\$\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\$
6
  • \$\begingroup\$ May we take the input as 0-indexed? Like, 0 -> 4, 7, 10? \$\endgroup\$ – Mr. Xcoder Dec 29 '17 at 21:20
  • 10
    \$\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

39 Answers 39

1
2
1
\$\begingroup\$

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
    1+               \ add 1

 : 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 
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
0
1
\$\begingroup\$

Perl 5 -a, 27 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica) 20 bytes

Mod[#+{3,6,9},12,1]&

The normal modulus operation, threaded over a list, offset by 1.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Husk, 8 bytes

tĊ3ṙḣ12←

Try it online!

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 8 bytes

ƵžS+12%>

At the time of writing this, this submission has the lowest score submitted. Technically I am winning!

Try it online!

How?

ƵžS                   # Push the list [2, 5, 8]
   +                  # Add the input to each number
    12%               # Mod each result by 12
       >              # Increment each
                      # And print the ending list implicitly!

See this tip of Kevin to know why Ƶž is 258!

\$\endgroup\$
0
\$\begingroup\$

Wolfram Language (Mathematica) 35 bytes

Range@12~RotateLeft~#~Take~{3,9,3}&

The above asserts, in infix notation, what can be expressed more clearly as

Function[Take[RotateLeft[Range[12],Slot[1]],List[3,9,3]]]

RotateLeft rotates Range[12], the sequence 1,2,...12, leftward by the input number. Slot[1] or # holds the input number, n.

For example, with n = 4,

Function[RotateLeft[Range[12],4]]]

returns the list

{5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4}

Take...{3,9,3} returns every third element in that list from position 3 through position 9, namely

{7, 10, 1}
\$\endgroup\$
1
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

Ruby, 29 bytes

->n{3.times{p 12+(n+=3)%-12}}
\$\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.