I just thought of this idea: if we have NaN ("not a number") for floats, how about NaC ("not a character") for a single unknown character in a string?
Your input should be two strings. Both strings are assumed to contain only uppercase letters in A-Z and an NaC character (which can possibly be any letter in A-Z), which cannot be an uppercase letter in A-Z. For example, if your NaC is ?, then both strings should match [A-Z\?]*. Either string can be empty, and empty strings compare as before all other strings.
You should give distinct, unique outputs for:
- The first string comes first in alphabetical order, no matter what the NaC characters are. For example,
HELLOmust come beforeW????regardless of what the?s are, becauseHcomes beforeW. - The second string comes first in alphabetical order, no matter what the NaC characters are.
- Both strings contain the same characters. In this case, no NaCs must be present in either string.
- "Insufficient data": The strings cannot be compared because of NaCs, for example
HELLOandH????, because the second string may start withHFor evenHA, or it might even beHELLO, and we need the rest of the second string to determine which comes first.
This is code-golf, so fewest bytes wins.
Examples:
Key: ? NaC 1 first string first 2 second string first = strings are equal ~ insufficient data $ empty string Examples: Input -> Output ——————————————— CODE, CODE -> = CODE, C -> 2 CODE, HELLO -> 1 CODE, AND -> 2 CODE, GOLF -> 1 WHY, WHAT -> 2 $, $ -> = $, ANYTHING -> 1 ?, ? -> ~ H???, W???? -> 1 HELLO, HELLO????? -> 1 HELLO, HELL???? -> ~ $, ??? -> 1 ????, ANYTHING -> ~ FOREVERMORE, FOREVERMOS? -> 1 FOREVERMORE, FOREVERMON? -> 2 FOREVERMORE, FOREVERMOR? -> ~ FOREVERMOR?, FOREVERMOR? -> ~ HA, H? -> ~ HA, H?? -> 1 HAA, H? -> ~ HAA, H?? -> ~ H?, HZ -> ~ H?, HZZ -> 1 H??, HZ -> ~ H??, HZZ -> ~
?assumed to be fromAtoZ? For instance, what's the output forH?vsHA, or forH?vsHZZ? \$\endgroup\$FOREVERMOR?, FOREVERMOR?\$\endgroup\$H??is lexicographically afterHAregardless of what letter values the?take. \$\endgroup\$A?C?E, AAABC -> 2andA?C, AZCD -> 1(there are no cases with non-contiguous?s or non-trailing?s) \$\endgroup\$