Quoting this question on SO (Spoiler alert!):
This question has been asked in an Oracle interview.
How would you divide a number by 3 without using *, /, +, -, %, operators?
The number may be signed or unsigned.
The task is solvable, but see if you can write the shortest code.
Rules:
- Perform the required integer division (
/3
) - Do not use the non-text-based operators
*
,/
,+
,-
, or%
(or their equivalents, such as__div__
oradd()
). This also applies to incrementing and decrementing operators, likei++
ori--
. Use of operators for string concatenation and formatting are OK. Using these characters for different operators, such as unary-
operator for negative numbers, or*
to represent a pointer in C is OK as well. - Input value can be arbitrarily large (whatever your system can handle), both positive and negative
- Input can be on STDIN or ARGV or entered any other way
- Create the shortest code you can to do the above