This question already has an answer here:
- Golf Me An OOP! 4 answers
I've been around for a while, watching you golf and I really enjoy it. I came up with a challenge for you all so let's begin!
I assume that everyone knows what Finite State Machine (FSM) is, I will edit the the description if needed.
- Your program will take only one input consisting in a string that represents a FSM.
- The first character of the input is the FSM's initial state and the last character is the FSM's final state.
- Transitions are represented as two consecutive characters (
ABwill be the transition from state A to state B.
ABCDwill be the two transitions
A to Band
C to D)
- In this challenge, the FSM is considered valid when you have at least one path from the initial state to the final state.
Output a truthy value, telling the world if the input is a valid FSM (any equivalent for
False is fine)
- -20% if you add all the sequences of valid paths to the output
AB should output (with bonus)
ABC should output
false (No transition to state C)
ABCEBD should output (with bonus)
true ABD (The presence of unreachable states C and E doesn't make it false)
ISSTSFTF should output (with bonus)
true ISF ISTF
ABACBCCD should output (with bonus)
true ACD ABCD
ABACBCD should output
ABACADCDBCDEBE should output (with bonus)
true ABE ADE ACDE ABCDE
If you think this challenge lacks something, please tell me, I'd really like to see the answers you can come up with