Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NFA Simulator hole #1036

Open
stefangimmillaro opened this issue Nov 19, 2023 · 5 comments
Open

Add NFA Simulator hole #1036

stefangimmillaro opened this issue Nov 19, 2023 · 5 comments
Labels
hole-idea An idea for a new hole. idea

Comments

@stefangimmillaro
Copy link
Contributor

stefangimmillaro commented Nov 19, 2023

Collaboration with @msbranicky

by popularish demand...
image
image
image
we bring you Finite Automaton Chapter II

Description

See https://github.com/code-golf/code-golf/pull/1037/files

Example input (if any)

    | a | b | c |
→ 0 |{0}|{0}|{0,1}| 
  1 |{2}| ∅ |  ∅ |
  2 | ∅ |{3}|  ∅ |
 F3 | ∅ | ∅ | ∅ |
acbcab

Example output

{0,3} Accept
@btnlq
Copy link
Contributor

btnlq commented Nov 19, 2023

Every DFA is also an NFA. We can support contravariance here: every NFA Simulator solution should be a DFA Simulator solution.
It changes the example to something like this:

Example input

    a b c
> 0 0 0 01
  1 2 ∅ ∅
  2 ∅ 3 ∅
 F3 ∅ ∅ ∅
"acbcab"

Example output

03 Accept

We can also use {} instead of to avoid non-ASCII characters.

@SirBogman
Copy link
Contributor

I don't think DFA simulator is popular enough to justify adding related holes that are similar.

@stefangimmillaro
Copy link
Contributor Author

From SirBogman here

Based on the screenshots, I really dislike the "→" character used for the initial state. It's going to mess up the alignment of strings in languages where you have to deal with each UTF-8 byte separately. "∅" is going to cause the same issue and I don't like it.

One thing that the other hole didn't have that would be useful is some kind of indicator just to the left of the state names. Ex:

>FS0
 FS1
  S2

Where S indicates the definition of the state. It would be a lot easier to search for it in some languages. S is just a suggestion.

@stefangimmillaro
Copy link
Contributor Author

stefangimmillaro commented Nov 21, 2023

I am happy to update the arrow and empty set symbol to > and {}. I will ponder adding the S. I think there is an argument to be made that one of the interesting parts of DFA was to identify the correct next row. Adding this simplification has merit for this variant.

@5cw
Copy link
Contributor

5cw commented Nov 29, 2023

Seconding the call for a switch from → to >, I think the hole should mimic the DFA hole as much as possible. I personally don't feel the need for the S, the info is all found consistent distances after the newline, and the DFA hole didn't have it. I don't mind the ∅ much either way, the solution would be a little shorter and cleaner without it but it's not an unreasonable edge case to handle and it looks pretty.

Wasn't an issue in terms of the actual text processing, but for aesthetics I'd prefer if the table looked a little neater by padding the columns out to line up.

    |    g    |    6    |    w    |    h    |    q    |    n    |   r   |
 F0 |   {7}   |    ∅    |   {6}   |  {0,7}  | {0,2,7} | {0,6,7} |   ∅   |
 F2 |    ∅    | {2,6,7} |{0,2,6,7}|   {7}   |    ∅    |   {6}   |{0,6,7}|
> 6 |{0,2,6,7}|{0,2,6,7}|   {6}   |   {2}   | {2,6,7} |{0,2,6,7}|  {7}  |
 F7 |    ∅    |    ∅    |    ∅    |{0,2,6,7}|{0,2,6,7}| {0,2,7} | {0,7} |

or

    | g       | 6       | w       | h       | q       | n       | r     |
 F0 |{7}      | ∅       |{6}      |{0,7}    |{0,2,7}  |{0,6,7}  | ∅     |
 F2 | ∅       |{2,6,7}  |{0,2,6,7}|{7}      | ∅       |{6}      |{0,6,7}|
> 6 |{0,2,6,7}|{0,2,6,7}|{6}      |{2}      |{2,6,7}  |{0,2,6,7}|{7}    |
 F7 | ∅       | ∅       | ∅       |{0,2,6,7}|{0,2,6,7}|{0,2,7}  |{0,7}  |

and just for good measure, a wild, out there proposal that because the states are one-digit numbers, the set notation is not strictly necessary

    | g    | 6    | w    | h    | q    | n    | r   |
 F0 | 7    | ∅    | 6    | 07   | 027  | 067  | ∅   |
 F2 | ∅    | 267  | 0267 | 7    | ∅    | 6    | 067 |
> 6 | 0267 | 0267 | 6    | 2    | 267  | 0267 | 7   |
 F7 | ∅    | ∅    | ∅    | 0267 | 0267 | 027  | 07  |

neither are the dividers

     g    6    w    h    q    n    r
 F0  7    ∅    6    07   027  067  ∅
 F2  ∅    267  0267 7    ∅    6    067
> 6  0267 0267 6    2    267  0267 7
 F7  ∅    ∅    ∅    0267 0267 027  07

and for maximal minimalism

     g    6    w    h    q    n    r
 F0  7         6    07   027  067
 F2       267  0267 7         6    067
> 6  0267 0267 6    2    267  0267 7
 F7                 0267 0267 027  07

this would declutter the screen and make it look more similar to the DFA hole, but at the expense of some clarity. and who doesn't love brackets? So i think there's good cases to be made for many setups. But I had fun solving it and I think it's a good hole.

edit: didn't realize btnlq basically proposed option 4 already, my main point is the columns should line up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hole-idea An idea for a new hole. idea
Projects
None yet
Development

No branches or pull requests

4 participants