In the arcade version of the game, Pac-Man eats pac-dots. However, in this challenge, he's hungry for alphanumeric characters and punctuation in a string.
Your task is to create a function that feeds Pac-Man a string, evaluates if he can eat it or not, and returns the string with Pac-Man's location in it.
Pac-Man (<
) eats characters from left to right, leaving an underscore or space for each character as he goes, and his goal is to get from the first position-1 to the last position+1:
1. <Pac
2. _<ac
3. __<c
4. ___<
However, Pac-Man's natural enemy, the ghost, will stop him if he encounters one of the letters in the word "GHOST" (not case sensitive). Your function should return the string with Pac-Man's location as he encounters the ghost
character:
1. <No!
2. _<o!
The only thing that can defeat a ghost is a power pellet. If Pac-Man reaches a letter in the word "PELLET" (also not case sensitive) before coming to a ghost, he will eat the ghost and keep moving, and that pellet will be used up. Power pellets can stack (ie, in ppgg
both ghosts would be eaten). The T character exists as both as a ghost and a pellet, so it can be ignored (treated as any other letter, like a
).
1. <Pop
2. _<op
3. __<p
4. ___<
To further clarify, in the string "Pac-Man loses here", the following operations occur:
P <P, +1 Pellet (1 pellet)
a <a
c <c
- <-
M <M
a <a
n <n
<[space]
l <l, +1 Pellet (2 pellets)
o <o, -1 Pellet (1 pellet)
s <s, -1 Pellet (0 pellets)
e <e, +1 Pellet (1 pellet)
s <s, -1 Pellet (0 pellets)
<[space]
h <h, ghost wins, returns
e
r
e
Examples
Input: Pacman wins!
Output: ____________<
Input: Pacman loses wah-wah :(
Output: _______________<h-wah :(
Input: PELLET PELLET GHOST
Output: ___________________<
Input: Hello World!
Output: <Hello World!
Input: <_!@12<_<_<
Output: ___________<
This is code-golf--lowest score in bytes wins.
<
symbol... \$\endgroup\$