In the absurdist play Rosencrantz and Guildenstern are Dead, the two main characters Rosencrantz and Guildenstern(or are they?) are always mixing up which of them is who—or sometimes which of their own body parts is which—because of a perceived lack of individual identity. Wouldn't it be absurd if they even shuffled around their names?
Your task it to write a function which takes in a string of an even length(and by design, a multiple of 4) that is greater than 7 characters, split it, and shuffle it.
The splitting shall be as follows:
the string will be of format "abscd"
, with s acting as a seperator character. The first section and the separator, abs
will be the first half of the string, whereas the second half will be cd
The length of a
will be (string length / 4) - 1
The length of b
will be (string length / 4)
The length of s
will be 1
The length of c
will be (string length / 4) + 1
The length of d
will be (string length / 4) - 1
This may be really confusing, so let me show you with some examples
("a" + "bb" + "s" + "ccc" + "d").length //8
1 2 1 3 1
|-------4--------| |----4-----| <--- (4 is half of 8)
("rosen" + "crantz" + "&" + "guilden" + "stern").length //24
5 6 1 7 5
("foo" + "barr" + "?" + "barry" + "foo").length
3 4 1 5 3
Finally:
You then shuffle the parts around, outputting adscb
ex. "rosencrantz&guildenstern" --> "rosenstern&guildencrantz"
"foobarr?barryfoo" --> "foofoo?barrybarr"
Rulez:
- Standard Loopholes are prohibited
- Acceptable answers: a function which takes input through one input string and returns one output string
- If the input string doesn't match the requirements provided above,
your code MUST error out(doesn't matter what kind of
Exception
orError
) - This is
code-golf
, so the shortest(valid)answer (in each language) wins! - Bonus points for a one-liner :-) (Not really tho, just cool points)