All the numbers that fit in a string
Pyth, 57 bytes
j-f:T"^0$|^-?([1-9]\d*)?(\.\d*[1-9])?$"0{.P*Q+jkUT".-"Q\-
Try it on the online interpreter.
Way too long, and with horrific runtime (takes several seconds for N=4, running with N=5 is not recommended).
.P Q all permutations of length (input) of
jkUT ... the string "0123456789"
+ ".-" ... plus the chars "." and "-"
*Q ... whole thing times the input -- pyth has
no repeated_permutation, so this is necessary
{ uniquify
f filter by
:T"..."0 does it match the really long regex?
- \- get rid of "-"
j join on newline
Regex explanation:
^0$| "0", or...
^
-? optional negative sign
([1-9]\d*)? optional part-before-decimal
(\.\d*[1-9])? optional part-after-decimal
$
Julia, 126 117 bytes
n->filter(i->ismatch(r"^0$|^-?([1-9]\d*)?(\.\d*[1-9])?$",i)&&i!="-",∪(map(join,combinations((".-"join(0:9))^n,n))))
This is a lambda function that accepts an integer and returns an array of strings. To call it, assign it to a variable. The approach here is the same as Doorknob's Pyth answer.
Ungolfed:
function g(n::Int)
# Get all n-character combinations of .-0123456789
c = combinations((".-"join(0:9))^n, n)
# Join each group of n characters into a string and take unique
u = ∪(map(join, c))
# Filter to only appropriately formatted strings
filter(i -> ismatch(r"^0$|^-?([1-9]\d*)?(\.\d*[1-9])?$", i) && i != "-", u)
end
Pyth, 47 45 bytes
Thanks to FryAmTheEggman for noting that the order does not matter.
jf!sm:Td)c".- \..*\. ^-?0. [.-]0*$"d^{`c_T17Q
Try it online.
The runtime is horrible, basically O(12n), but I tested it for n
= 6 on my computer (which took 2 minutes). Running n
≥ 5 will time out online.
Due to the way I generate the characters 0123456789.-
the output is in a really weird order.
One could technically remove the {
near the end, but it would result in a complexity of O(19n). (It would also produce lots of duplicates, but that's allowed.)
Explanation
_T -10
c 17 -10 / 17 = -0.5882352941176471
` representation: "-0.5882352941176471"
{ uniquify: "-0.582394176"
^ Q input'th Cartesian power
f filter on:
c"…"d split this string by spaces
m:Td) check if the parts match the current string
!s true if none of the parts matched
j join by newlines
The main part of the code is ".- \..*\. ^-?0. [.-]0*$"
, which contains the regexes any output must not match.
.- minus must be first character
\..*\. there may only be one decimal point
^-?0. no extra leading zeroes
[.-]0*$ number must not end with decimal/minus and 0+ zeroes