This challenge consist in adding commas to numbers every 3
spaces like:
123456789 => 123,456,789
Specifications:
- The possible inputs will be
1,000 <= input <= 100,000,000
- You can ONLY use Mathematical Operators
- (*) You can NOT do string, array, index or character manipulation
- You can NOT use any kind of built-in functions that add these commas
- The zeros should remain, ex
10000 => 10,000
- You need to print/alert/log the output (so "the output is at x var" is not allowed)
(*) the only exception is when forming/printing the output (but not in a manner that suggest cheating)
Examples
10100 => 10,100
120406 => 120,406
999999999 => 999,999,999
A basic idea on how to get numbers legally:
n = 123456;
m = roundDown(n / 10);//even if ends with .9
d = n - m;//we get the last number
123,45,6
acceptable output for the input123045006
, or do we need to include the leading zeros? I'd assume we do, but if not, I have a very nice 13-char GolfScript solution. :) \$\endgroup\$