There’s an old codegolf.SE question that goes something like this; “Take the name of a US state, and output its two letter abbreviation.” That puzzle had its time, but now we’re evolving.
Take in as an input a string of strictly alphabetic characters, at least 2 letters long. The output is; can the string be written as a concatenation of United States 2-letter USPS State codes, which may include a leading and/or trailing character? (Note: only the states, table-background light grey, are permitted for this challenge. Which means DC, Guam, etc. will be excluded)
For example;
“NEWYORK” as input would return TRUE since NE WY OR KS makes NEWYORKS, which is our input string with only one trailing letter.
Standard rules apply, I/O typing and display is flexible.
EDIT: One more rule - no web-pulling. Populating a database using Wikipedia is outside the spirit of the challenge.
Example inputs;
Input | Output |
---|---|
NEWYORK | TRUE (NE WY OR KS) |
GASCAR | TRUE (GA SC AR) |
TACTIC | FALSE |
WAILORD | TRUE (WA IL OR DE) |
NEW | TRUE (NE WA) |
DORK | TRUE (SD OR KS) |
Bonus question 0: Indicate whether the first/last letter needs to be removed in each output.
Bonus question 1: Output the abbreviations instead of just a TRUE output.
Bonus question 2: Output the full states’ names instead of just their abbreviations.
Fun solution-check: How many state names return TRUE in this function, like New York does?