2
Write a function to produce, for a non-negative integer, a string containing a sum of terms according to the following:
3 -> "3"
805 -> "800 + 5"
700390 -> "700000 + 300 + 90"
0 -> "0"
13 -> "10 + 3"
200 -> "200"
Any input other than a non-negative integer can be ignored. Zero terms must be skipped unless the input is 0. Terms must go from largest to smallest. The plus signs must have only a single space on either side.
This is code golf; fewest number of bytes wins.
The edge case of an input of zero seems awkward and yet easily avoidable with "for a positive integer...". – Jonathan Allan – 2019-07-07T02:11:53.313
Thank you so much for detecting the inconsistency. Regarding the +, I'd like to see how people can golf the join, so it was intentional. I say "nonnegative" instead of "positive" on purpose as well. Nonnegative includes 0 which will indeed make the code longer and IMHO more of a challenge to golf. It's true that a list of positive integers (filtered to remove zeros) is way easier, but I did add the two complications as a challenge. I don't use this site too often so if these kinds of complications are frowned upon please let me know for sure. Thanks. – Ray Toal – 2019-07-07T02:16:16.307
1...not really frowned upon, just seems like the core of the challenge on its own would make for a better question. Are the single spaces required or optional? – Jonathan Allan – 2019-07-07T02:21:15.137
Required. Though I think I have an idea of how to ask next time. :) Cheers :) – Ray Toal – 2019-07-07T02:26:58.657
Flexibile output format is generally preferred – Luis Mendo – 2019-07-07T02:30:08.753
1Thanks good to know. For next time. – Ray Toal – 2019-07-07T02:39:35.017
Subset of this question. Enough so, that I would consider this a dupe
– Jo King – 2019-07-07T02:47:34.600Didn't see that. Should I delete? Okay if anyone wants to close it. – Ray Toal – 2019-07-07T02:49:04.843