When writing code-golf programs, I usually end up using some numeric constants. I always put them in decimal because that's how I think, but I just realized that my language supports other number formats that might let me shorten my code slightly.
Given a non-negative integer less than 2^53-1, decide whether that integer has the shortest representation in:
- Scientific Notation
Since this is the default format of my language, there is no extra notation needed for this format. Every number is represented as usual for decimal.
My languages uses the
0x prefix for hexadecimal constants. This means that if a number has 4 hexadecimal digits, it will take 6 bytes to represent that number.
My language uses the following format for scientific notation:
[Real base]e[Integer exponent of 10]
700 would be represented as
699 would be represented as
6.99e3, because the base must be between -10 and 10 (non-inclusive). For the purposes of this challenge, the base will always be at least 0, since the inputted number is non-negative.
You should return a way of identifying which format is shortest (i.e. 0 for decimal, 1 for hex, 2 for scientific). Alternatively, you may output the smallest representation of the number itself.
Decimal | Hexadecimal | Scientific | Winner --------------|--------------|-------------------|------------- 0 | 0x0 | 0e0 | Decimal 15 | 0xF | 1.5e1 | Decimal 6999 | 0x1B57 | 6.999e3 | Decimal 7000 | 0x1B58 | 7e3 | Scientific 1000000000000 | 0xE8D4A51000 | 1e12 | Scientific 1000000000001 | 0xE8D4A51001 | 1.000000000001e12 | Hexadecimal 1000000001000 | 0xE8D4A513E8 | 1.000000001e12 | Hexadecimal 1000001000000 | 0xE8D4B45240 | 1.000001e12 | Scientific
This is code-golf, so the answer in the shortest bytes for each language wins.