Take an arbitrarily sized string as input. This string represents a baseball plate appearance, in which each character represents a pitch as follows:
- Strike:
S
- Ball:
B
- Foul ball:
F
- Hit by pitch:
H
- Ball in play:
X
(For those wondering, this is a very very simplified version of Retrosheet's notation)
Your program must output 1 of 3 possible outputs to signify 1 of the mutually exclusive outcomes:
- Strikeout
- Walk
- Ball in play
It doesn't matter what the outputs are exactly, as long as they are guaranteed to be distinct.
For those unfamiliar with the rules of baseball:
- 3 strikes results in a strikeout
- 4 balls results in a walk
- A foul ball is a strike UNLESS the batter already has 2 strikes, in that case nothing happens
- Hit by pitch immediately results in a walk
- "Ball in play" immediately results in the "Ball in play" outcome
You may assume that:
- the input string is encoded as ASCII
- the input string represents an entire plate appearance (in other words it will end in one of the 3 outcomes above)
- there are no other characters other than the ones above
You may not assume that:
- there are no extra pitches/characters after the plate appearance is supposed to legally end
- your program must return on the last pitch/character
Examples:
"Strikeout"fy:
SSS
SBSBS
BBBSSS
BSBSBS
BSFFBFS
BBSSFFFFFFFFS
SSSBBBB
FSS
"Walk"y:
BBBFB
BBBB
BBBSB
SSBBBB
SSH
SBSFFBFFFFBFFFFFFFFB
BBBBSSS
HSSS
SBBBBSS
"Ball in play"ly:
X
SSX
BBBX
SBSX
FFFFFFFFFFFFFFX
XBSBSBSB
This is code-golf, so fewest bytes wins.
(This challenge was inspired by this YouTube video)
X
, effectively ignoring the rest of the characters. \$\endgroup\$