Calculate n
modulo 12
for an unsigned 32 bit integer.
The Rules:
- Must work for all
n
between 0 and 23. Other numbers optional. - Must only use any of the operators
+-*
,~&^|
or<<
,>>
as commonly defined on 32 bit uints. - May use arbitrary number of constant uints.
- May not use any form of pointers, including arrays, or any
if
statements, including things that compile to if statements such as ternary operators or "greater than" operators.
The scoring:
- Operators
+ -
and the bitwise operators~ & ^ | << >>
(NOT, AND, XOR, OR, bit shifts) give a score of1
,*
gives a score of2
. - Lowest total score wins.
+-*
are add, subtract, multiply;~&^|
are bitwise NOT,AND,XOR,OR; and<< >>
are bitshifts. \$\endgroup\$for i in x:y:z, .dostuff
? \$\endgroup\$n % 12
to a multiplication and a shift like in hacker's delight, so this is trivial, just output the assembly and see \$\endgroup\$