1
1
Write the shortest code that implements a:
The program should accept as input:
- a string(that we want to see if is accepted or not)
- the delta function, represented in whichever way it's more convenient.
- the "set" of final states of the automaton
And it should output Accepted! if the string is accepted by the automaton, and the string Not a chance! otherwise.
Note that all inputs should be taken from stdin or the command line.
The total points should be computed as (L1 + 2*L2 + 3*L3) / 6 where Li is the length, in bytes, of the code solving point i and the winner will be the answer with smallest score.
Edit: You can assume the starting state, so that it is not required as input.
The epsilon transitions can be labelled in any way you want.
Edit2: An example of input for the DFA:
0100
{'q_0': {'0': 'q_1', '1': 'q_0'}, 'q_1': {'0': 'q_2', '1': 'q_3'}, 'q_2': {'0': 'q_2', '1': 'q_3'}, 'q_3': {'1': 'q_0', '0': 'q_1'}}
{'q_2', 'q_3'}
Output:
Accepted!
An other input:
010010
{'q_0': {'0': 'q_1', '1': 'q_0'}, 'q_1': {'0': 'q_2', '1': 'q_3'}, 'q_2': {'0': 'q_2', '1': 'q_3'}, 'q_3': {'1': 'q_0', '0': 'q_1'}}
{'q_2', 'q_3'}
Output:
Not a chance!
I want to stress that you are free to use a different formatting for the inputs. Choose the simpler to "parse" in your target language. The above is simple to use in python since you can eval it to obtain the real objects.
How do we choose between 1, 2, and 3? – Keith Randall – 2013-03-24T16:29:54.963
...or do we write 3 separate programs? – Keith Randall – 2013-03-24T16:38:39.633
@KeithRandall the scoring indicates three programs are desired. – John Dvorak – 2013-03-24T16:47:29.300
Exactly, you have to produce three different programs, one for the DFA, one for the NFA and one for the epsilon-NFA. I chose to do so since they are stricly related(hence it doesn't make sense to ask 3 different questions). – Bakuriu – 2013-03-24T18:38:17.117
Can we get some example inputs / outputs? – boothby – 2013-03-24T20:08:38.770
@boothby I'll now add an example, but keep in mind that you are free to change the formatting of the input if a different formatting is more convenient. The example I'll write is probably a convenient way for the python solution. – Bakuriu – 2013-03-24T20:24:49.777