Challenge
Given a string and a number, divide the string into that many equal-sized parts. For example, if the number is 3, you should divide the string into 3 pieces no matter how long the string is.
If the length of the string does not divide evenly into the number provided, you should round down the size of each piece and return a "remainder" string. For example, if the length of the input string is 13, and the number is 4, you should return four strings each of size 3, plus a remainder string of size 1.
If there is no remainder, you may simply not return one, or return the empty string.
The provided number is guaranteed to be less than or equal to the length of the string. For example, the input "PPCG", 7
will not occur because "PPCG"
cannot be divided into 7 strings. (I suppose the proper result would be (["", "", "", "", "", "", ""], "PPCG")
. It's easier to simply disallow this as input.)
As usual, I/O is flexible. You may return a pair of the strings and the remainder string, or one list of strings with the remainder at the end.
Test cases
"Hello, world!", 4 -> (["Hel", "lo,", " wo", "rld"], "!") ("!" is the remainder)
"Hello, world!", 5 -> (["He", "ll", "o,", " w", "or"], "ld!")
"ABCDEFGH", 2 -> (["ABCD", "EFGH"], "") (no remainder; optional "")
"123456789", 5 -> (["1", "2", "3", "4", "5"], "6789")
"ALABAMA", 3 -> (["AL", "AB", "AM"], "A")
"1234567", 4 -> (["1", "2", "3", "4"], "567")
Scoring
This is code-golf, so the shortest answer in each language wins.
Bonus points (not really 😛) for making your solution actually use your language's division operator.
;⁹/
\$\endgroup\$PPCG
,7
so the remainder isPPCG
\$\endgroup\$