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.
- Perform the required integer division (
- Do not use the non-text-based operators
%(or their equivalents, such as
add()). This also applies to incrementing and decrementing operators, like
i--. 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