46
10
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.
29So the pellets have no expiration date? – Rɪᴋᴇʀ – 2016-06-30T11:42:47.097
Are trailing tabulations accepted in the output? – Katenkyo – 2016-06-30T11:50:33.840
@Katenkyo the last character should be either the last character of the input or
<, barring any language quirks. – atlasologist – 2016-06-30T12:05:03.583The T character can be ignoredCan you clarify? Does that mean none of the inputs can contain a "t"? – James – 2016-06-30T14:38:16.880@DrGreenEggsandIronMan I think it means that a
Tis like say ana: it doesn't have any effect – Luis Mendo – 2016-06-30T14:41:40.993@DrGreenEggsandIronMan Luis is correct, it cancels itself and can be treated like any other character not in
GHOSPEL– atlasologist – 2016-06-30T15:27:51.4937+1 for the fact that "here" is where pacman loses. Clever test case. – Olivier Dulac – 2016-06-30T17:06:24.070
5> [I]n this challenge, he's hungry for alphanumeric characters and punctuation in a string. ... Yacc-man? – Kaz – 2016-07-01T01:13:15.823
9Now I see a camouflaged grey pacman with black lips every time i look at the
<symbol... – QBrute – 2016-07-01T05:49:23.700