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

46 Answers 46

1
2
1
\$\begingroup\$

PowerShell, 30 bytes

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.

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

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

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

\$\endgroup\$
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\$

Husk, 8 bytes

tĊ3ṙḣ12←

Try it online!

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

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
C3          RET                 ; return to caller

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

\$\endgroup\$
1
+100
\$\begingroup\$

Piet + ascii-piet, 45 bytes (5×18=90 codels)

tAaaqreeumccsqqqijlVa rbiqaaueljnvea?_ t?B tt

Try Piet online!

My looping template is getting weirder and weirder... :P

inN 4    [n 4]; force toggle CC at the exit of 4 region
Loop:
  dup CC+    [n flag] switch CC on 3rd iteration so it will exit after the loop
  2 1 roll   [flag n]
  2 +        [flag n+2]
  3 dup dup * + %  [flag (n+2)%12]
  1 + d outN [flag next_n] compute and print the next number
  1 outC     [flag next_n] print the separator (ASCII 1)
  2 1 roll   [next_n flag]
  2 /        [next_n flag/2] divide flag by 2; flag becomes odd after two loops
\$\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\$
0
\$\begingroup\$

J, 24 bytes

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

Try it online!

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

Stax, 8 bytes

äÆL6C╪Θ♪

Run and debug it

Approach

3 times:
    add 2
    mod 12
    add 1
    print current value
\$\endgroup\$
0
\$\begingroup\$

Excel + Google Sheets Polyglot, 21 Bytes

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
\$\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.