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!
Challenge
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 (
AB
will be the transition from state A to state B.ABCD
will be the two transitionsA to B
andC 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.
Goal
Output a truthy value, telling the world if the input is a valid FSM (any equivalent for True
of False
is fine)
Bonus
- -20% if you add all the sequences of valid paths to the output
Examples
AB
should output (with bonus) true AB
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 false
ABACADCDBCDEBE
should output (with bonus) true ABE ADE ACDE ABCDE
Final word
If you think this challenge lacks something, please tell me, I'd really like to see the answers you can come up with
ABCD
represents only two transitionsA->B
andC->D
and notB->C
. Otherwise the challenge would be trivial. \$\endgroup\$