In this challenge you have to do two different (but related) tasks depending of the order of the input.
Your program will recieve a string
s and an integer
n as input and will
sinto pieces of length
scomes first. The last element will be shorter if necessary.
npieces of equal length if
ncomes first. If
len(s)is not a multiple of
len(s) mod nelements will be one longer.
You may only take those 2 inputs.
s will never contain only digits.
- You may use the reverse mapping. Note this in your answer if you do that.
swill only contain printable ASCII characters (no newlines).
- You may not use any builtins that solve either those two tasks directly. All other builtins are allowed.
- You have to take both arguments from the same source.
- You may take the arguments in an ordered list or any other format which clearly indicates their order as long as it is unambiguous.
- You may take the input as one string/ stream and use a character which is not a valid input (like a nullbyte) to separate them.
nwill always be equal or less than the length of
sand greater than zero.
- You may output the resulting list in any resonable format as long as it clearly indicates the particular pieces and their order.
The last element contains only 2 characters, because 11 is not divisible by 3.
["pro", "gra", "mmi", "ng"]
11 is not a multiple of 3, so the first 2 elements will be one longer:
["prog", "ramm", "ing"]
- Function or full program allowed.
- Default rules for input/output.
- Standard loopholes apply.
- This is code-golf, so lowest byte-count wins. Tiebreaker is earlier submission.
The test cases got generated with this Pyth program (uses builtins, so no valid answer). Thanks to @FryAmTheEggman for providing the base version of that!
3, helloworld -> ['hell', 'owo', 'rld'] helloworld, 3 -> ['hel', 'low', 'orl', 'd'] 1, programming -> ['programming'] programming, 1 -> ['p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g'] 8, programming -> ['pr', 'og', 'ra', 'm', 'm', 'i', 'n', 'g'] programming, 8 -> ['programm', 'ing'] 9, code golf -> ['c', 'o', 'd', 'e', ' ', 'g', 'o', 'l', 'f'] code golf, 9 -> ['code golf'] 4, 133tspeak -> ['133', 'ts', 'pe', 'ak'] 133tspeak, 4 -> ['133t', 'spea', 'k']