There's a little improv warm up game where you arrange yourselves in a circle and send zips, zaps, and zops around by pointing to a person and saying the next word in the sequence, then they do the same until all of you are warmed up or whatever.
Your task is to create a program that gives the next word in sequence given an input word. (Zip --> Zap --> Zop --> Zip) Since there's a lot of different ways to say these three words and flairs that can be added to them, your program should imitate case and letter duplication and carry suffixes.
To elaborate, your input will be one or more Z
s, then one or more I
s, A
s, or O
s (all the same letter), then one or more P
s, (all letters up to this point may be in mixed case) followed by some arbitrary suffix (which may be empty). You should leave the runs of Z
s and P
s, as well as the suffix exactly as received, but then change the I
s to A
s, A
s to O
s, or O
s to I
s, preserving case at each step.
Example Test Cases
zip ==> zap
zAp ==> zOp
ZOP ==> ZIP
ZiiP ==> ZaaP
ZZaapp ==> ZZoopp
zzzzOoOPppP ==> zzzzIiIPppP
Zipperoni ==> Zapperoni
ZAPsky ==> ZOPsky
ZoPtOn ==> ZiPtOn
zipzip ==> zapzip
zapzopzip ==> zopzopzip
zoopzaap ==> ziipzaap
Rules and Notes
- You may use any convenient character encoding for input and output, provided that it supports all ASCII letters and that it was created prior to this challenge.
- You may assume the input word is some variant of Zip, Zap, or Zop. All other inputs result in undefined behavior.
- Valid inputs will full-match the regex
Z+(I+|A+|O+)P+.*
(in mixed case)
- Valid inputs will full-match the regex
Happy Golfing!
z
's and the firstp
. The suffix may contain anything. \$\endgroup\$ – Arnauld Feb 27 at 16:27