I came across this question and couldn’t figure out how to approach it. Can someone please help me out? The question is-
- Add numbers in base n (not any of the popular ones like 10, 16, 8 or 2 – I hear that Charles Simonyi, the inventor of Hungarian Notation, favors -2 when asking this question).
I just need the idea.
You didn’t specify a language, but you could just convert the base n number into a standard integer and add it.
Suppose base N number = ‘…d2d1d0’ where di = the i’th digit.
Number = … d2 * N^2 + d1 * N^1 + d0 * N^0
Then just add the numbers as usual.