String Stairs
Disclaimer: This is the first challenge I propose. Any and all feedback is welcome. If this is a duplicate, please point it out.
Here's a link to the sandbox post.
Goal
The goal of this challenge is to, given a string and an integer, print the string into blocks of that integer's size. If a word has more characters than the size of a block, print it into a descending "stair" pattern.
Rules
- The "stair pattern" mentioned above means that, for every block of a same word, that block must begin exactly where the block above it ends. Check the test cases (or ask) if you have any questions.
- If a word is broken in multiple blocks, the following word must be printed with an adequate number of spaces, that is, it must be separated from the preceding word's lowermost block by exactly one whitespace. Check the test cases (or ask) for clarification.
- You can assume the input string will consist only of printable ASCII characters. Also, it will not have multiple whitespaces in a row.
- You can also assume that the integer will always be in the range [1, +∞).
- Trailing whitespace or newlines are allowed.
- You can use any reasonable method for I/O.
- Standard Loopholes apply.
- This is code-golf, so shortest code (in bytes, per language) wins. After a week (or so), I'll accept the overall shortest answer.
Test Cases
(String, Integer) => (Output)
"This is a large string", 3 => Thi is a lar str
s ge ing
"This is an even larger string!", 2 => Th is an ev la st
is en rg ri
er ng
!
"Ooooh dear, what a big string you have!", 3
=> Ooo dea wha a big str you hav
oh r, t ing e!
"Staphylococcus saprophyticus", 4 => Stap sapr
hylo ophy
cocc ticu
us s
"I hope you find this challenge interesting", 2
=> I ho yo fi th ch in
pe u nd is al te
le re
ng st
e in
g
"Well, this test case looks kinda pointless now doesn't it?", 15
=> Well, this test case looks kinda pointless now doesn't it?
"This one looks a lot more interesting!", 1 => T o l a l m i
h n o o o n
i e o t r t
s k e e
s r
e
s
t
i
n
g
!
"Keep in mind, people: 'Punctuation! Does! Matter!'", 2
=> Ke in mi pe 'P Do Ma
ep nd op un es tt
, le ct ! er
: ua !'
ti
on
!