last day (14 days later) » 

04:55
8
Q: Split string into n pieces (or pieces of length n)

DenkerAffeThe Challenge 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 split s into pieces of length n if s comes first. The last element will be shorter if necessary. split s...

@Dennis This was just meant to rule out builtins that solve this directly. I clarified.
If our language does not support arrays, how should we output? Would a newline between each result of the string be acceptable?
Also, for languages where the input is an array of ambiguous numbers, what should the procedure be?
@CᴏɴᴏʀO'Bʀɪᴇɴ Can't happen. s will never contain only digits. Also You may output the resulting list in any resonable format as long as it clearly indicates the particular pieces and their order which includes multiline output of course.
@DenkerAffe Let me clarify. The input to the program 65, "Hello!" would be read by the program as 65,72,101,108,108,111,33, so it cannot disambiguate which is the string and which isn't. To compensate, could one take a number that represents the order of the arguments? So the input could be 1 <n> <s> or 0 <s> <n>. Secondly, you say the input can have printable ASCII characters, including newlines, which would make my output ambiguous as well.
@CᴏɴᴏʀO'Bʀɪᴇɴ I don't count newlines as printable ASCII, so thats one problem solved. However, taking a number which indicates the input order would be a huge advantage, so I can't really allow that, sorry.
04:56
Okay. How about a null-byte terminator? E.g. (number) (null byte) (string) or (string) (null byte) (number)?
you mean [number or string]\0[number or string]\0, right? As I said, you can only take 2 inputs.
Yeah. The input would look like, say, 3 0 "programming", or, 3 "\0programming".
that should be fine then
Either would be fine?
well, you need to use always the same separator of course, but a plain zero should work, since it is no valid input anyway
05:01
Alright, that should work perfect then. Thanks!
out of curiosity, int what language are planning on doing this?
My own, Reng.
It's like ><> and befunge
Ah, I saw you posting some answers in that. Looking forward to another one :)
Thanks! Really nice challenge you have :D

last day (14 days later) »