Write a program or function that takes in a positive integer N. Output a list of all the distinct decimal numbers that can be written in exactly N characters using digits (0123456789), decimal points (.), and negative signs (-).
For example, some numbers that would be in the N = 4 output list are 1337, 3.14, .999, -789, -2.7, and -.09.
The numbers are to be written in the normal way, but in as short a form as possible. This means:
The decimal point should only be included if the number is not an integer.
- e.g.
45.0and45.should be written as plain45 -45.00should be written as-45
- e.g.
There should be no leading zeroes to the left of the decimal point.
03and003should be written as3, but30and300are fine as they are0.3and00.3should be written as just.3-03should be written as-3-0.3should be written as-.3
There should be no trailing zeroes to the right of the decimal point
.50and.500should be written as.5900.090should be written as900.09
The exception to the two last rules is zero itself, which should always be written as plain
0.Positive signs (
+) should not be used since they unnecessarily lengthen the number.
Also note that the negative sign (-) should not be used as a subtraction sign. It should only appear as the first character of numbers less than zero.
Formatting
The order of the output list of numbers does not matter. It could be ascending, descending, or completely mixed up. It only matters that all of the distinct numbers that can be written in N characters are present.
The list can be formatted in a reasonable way, using spaces, newlines, commas, or perhaps something else between the numbers, as long as things are consistent. Leading and trailing brackets (or similar) are alright but things like quotes around numbers are not. (i.e. don't visibly mix up strings and ints/floats in the output.)
For example, when N = 1, some valid outputs would be:
0 1 2 3 4 5 6 7 8 9 [1, 2, 3, 4, 5, 6, 7, 9, 0] ans = { 5 8 9 1 3 2 0 3 4 7 6 } But this would be invalid:
[0, 1, 2, 3, 4, "5", "6", "7", "8", "9"] Examples
N = 1 -> 0 1 2 3 4 5 6 7 8 9 N = 2 -> -9 -8 -7 -6 -5 -4 -3 -2 -1 .1 .2 .3 .4 .5 .6 .7 .8 .9 10 11 12 ... 97 98 99 N = 3 -> -99 -98 ... -11 -10 -.9 -.8 ... -.2 -.1 .01 .02 ... .98 .99 1.1 1.2 ... 1.9 2.1 2.2 ... 2.9 3.1 ...... 9.9 100 101 ... 998 999 Lists are in ascending order, ellipsized in some places for reading convenience.
Scoring
The shortest code in bytes wins. In case of ties, the higher voted answer wins
-0be valid output? \$\endgroup\$Also note that the negative sign (-) should not be used as a subtraction sign. It should only appear as the first character of numbers less than zero.\$\endgroup\$0". \$\endgroup\$