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
Side note: this is A004736 in the OEIS. Also, the first example (with newlines) is an invalid output, as specified in the rules.
1 21 321 4321 54321 654321 Without newlines (valid output): 121321432154321654321
Your code may take any kind of input (graphical, STDIN) in the form of an integer or number.
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.
- 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
121321), 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.
Thanks @Emigna, I used his algorithm to calculate these 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
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. \$\endgroup\$
[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
mickey321211mouse. Really the
\Dparts have no reason to be there \$\endgroup\$