Created
November 18, 2011 14:34
-
-
Save Nabb/1376606 to your computer and use it in GitHub Desktop.
NFA in Golfscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a response to http://swizec.com/blog/strangest-line-of-python-you-have-ever-seen | |
# Since the only input in golfscript is stdin, we'll assume the strings to test are on the last line of stdin, separated by spaces. | |
# 82B -- The first implementation avoids making assumptions about the data, prints one line for each input. Formatted as e.g. `ab YES' | |
n%)" ":s/\:|;{s|(s/(;3$1/{:c;{s+c+2|>\`{?)}+,~}%{.-1%s?~)>}%}/\0=s/&!"YNEOS">2%n}/ | |
# 71B -- Simplifying the output and printing just the matching strings saves 11B. Formatted as e.g. `["ab" "abb"]' | |
n%)" ":s/\:a;{a(s/(;@1/{:c;{s+c+2a>\`{?)}+,~}%{.-1%s?~)>}%}/\0=s/&!!},p | |
# 50B -- Assuming only one string is given. Assuming states are two characters. Prints something only when the string matches (consistent with the golfscript definition of true/false) | |
n%)\:a(" ":s/@1/{:c;{s+c+a\`{?!}+,~}%{8>}%}/\0=s/& |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment