45
2
Main task
Your task is to print out integers in descending order, starting from 1, and increasing as you keep hitting 1 again, up until the given input is reached, then, print out the rest until you hit 1 again. Example with input 6
:
1
21
321
4321
54321
654321
Without newlines (valid output):
121321432154321654321
Side note: this is A004736 in the OEIS. Also, the first example (with newlines) is an invalid output, as specified in the rules.
Input
Your code may take any kind of input (graphical, STDIN) in the form of an integer or number.
Output
Your code should output the above described sequence, up until the input number is reached, then finish to output until it reaches 1 again. The output may be anything, therefore numbers, strings, integers, or graphical output. It is required to print out a single number (no newlines if it's a string). Your output can be in- and outroduced with as many characters as you need (e.g. []
).
Since there was some misunderstanding, here's a regex pattern you can try your outputs on.
^(\D*(\d)+\D*)$
Rules
- The output must be a full number, not split up by anything, not even newlines.
- The algorithm shouldn't check for the first instance of N appearing in any way (e.g. the
21
in121321
), but rather for the first instance of N as the actual number. - A single trailing newline is allowed.
- The handling for negative input is fully your choice, negative numbers aren't cases you should test.
Test cases
Input: 6
Output: 121321432154321654321
Input: 1
Output: 1
Input: 26
Output: 121321432154321654321765432187654321987654321109876543211110987654321121110987654321131211109876543211413121110987654321151413121110987654321161514131211109876543211716151413121110987654321181716151413121110987654321191817161514131211109876543212019181716151413121110987654321212019181716151413121110987654321222120191817161514131211109876543212322212019181716151413121110987654321242322212019181716151413121110987654321252423222120191817161514131211109876543212625242322212019181716151413121110987654321
Input: 0
Output: 0, Empty, or Error
Input: 21
Output: 121321432154321654321765432187654321987654321109876543211110987654321121110987654321131211109876543211413121110987654321151413121110987654321161514131211109876543211716151413121110987654321181716151413121110987654321191817161514131211109876543212019181716151413121110987654321212019181716151413121110987654321
Thanks @Emigna, I used his algorithm to calculate these test cases.
Winner
The winner has been chosen! It was ErikGolfer's answer with an impressive 5 bytes! Congratulations!
The output must be a full number ...
Do you mean the entire sequence, or only the different substrings (1, 2-1, 3-1 ...)? Your first example doesn't seem to match this statement. – steenbergh – 2016-12-19T14:46:23.0101If the output has to be a single number, how can it be "arrays"? – smls – 2016-12-19T15:50:15.173
Would this array be acceptable as output?
[1, 21, 321, 4321, 54321, 654321]
How about this one?
[1,2,1,3,2,1,4,3,2,1,5,4,3,2,1,6,5,4,3,2,1]
Or are you just talking about arrays with a single element, like
[121321432154321654321]
? – smls – 2016-12-19T16:00:00.597Can we assume that input is always positive? – Titus – 2016-12-19T16:06:33.727
Ah, so it's okay to write a lambda that outputs an array, only if the array's default stringification as used by the language's standard IO routines would turn it into that single number without anything to separate the digits? – smls – 2016-12-19T16:06:47.880
1I'm confused about the output format. Can you give examples of what is acceptable? Array of numbers? String with numbers separated by spaces? – Luis Mendo – 2016-12-19T16:19:29.750
I'm going to delete my comments to clean this up. All of your questions should've been answered in the question after editing. – devRicher – 2016-12-19T17:43:24.120
1Your regex allow output of
mickey321211mouse
. Really the\D
parts have no reason to be there – edc65 – 2016-12-20T13:45:06.273@edc65 It actually allows for an empty output too. The regex is
^(\D*(\d)*\D*|)$
, and if you note the last pipe|
, you will realize that empty output would have been allowed too. – Erik the Outgolfer – 2016-12-24T08:43:15.063Still allowing
mickey123mouse
after the edit. But now at least a digit is required – edc65 – 2016-12-24T10:56:43.530@edc65 It is on purpose, so outputs like
[123]
or123\n
are accepted. – devRicher – 2016-12-24T11:46:48.093Does this answer your question? Create an array with repeated numbers
– None – 2020-02-01T03:59:40.430