This challenge is inspired by Fortran's idiosyncratic implicit typing rules. Your task will be to determine the data type of the object GOD
according to the implicit typing rules explained below.
Background
Fortran 77 has six data types: CHARACTER
, COMPLEX
, DOUBLE PRECISION
, INTEGER
, LOGICAL
, and REAL
. Any object not explicitly declared to have one of these types is implicitly assigned a type by the compiler, as determined by the first letter of the object's name. The default implicit types are:
----------------------------
First letter | Implicit type
-------------+--------------
A-H | REAL
I-N | INTEGER
O-Z | REAL
----------------------------
For example, the object called NUMBER
(first letter N) has implied type INTEGER
whereas the object called DUMBER
(first letter D) has implied type REAL
. These rules lead to the old joke that GOD
is REAL
. . . unless declared INTEGER
.
The default implicit types can be overridden using IMPLICIT
statements. For example,
IMPLICIT DOUBLE PRECISION (D,X-Z), INTEGER (N-P)
means that all objects whose names start with D, X, Y, or Z now have implied type DOUBLE PRECISION
and those starting with N, O, or P have implied type INTEGER
. Objects whose names start with any other letter retain their default implied types (in this example, REAL
for A–C, E–H, and Q–W and INTEGER
for I–M).
For the purposes of this challenge, we will adopt a more concise syntax: the IMPLICIT
keyword (redundant here) will be dropped and we will use the single-character identifiers C
, D
, I
, L
, R
, and X
to represent the six data types (X
represents COMPLEX
). Thus, the example IMPLICIT
statement given above becomes
D(D,X-Z), I(N-P)
i.e. a series of identifier–range pairs.
The challenge
Assume that the object GOD
exists in a Fortran 77 program and does not have an explicitly declared type. Write a program or function that returns the implied type of GOD
, given a compact IMPLICIT
statement as input. This is code-golf: the shortest submission (in bytes) in each language wins.
Input
- Input is either empty or otherwise consists of 1 to 26 identifier–range pairs.
- Input may be taken in any reasonable format (e.g. one long string, list of identifier–range pairs). If you divide the input into identifier–range pairs, each pair may either be taken as is, e.g.
'D(D,X-Z)'
, or split, e.g.['D', '(D,X-Z)']
. - In ranges, letters appear in alphabetical order and are separated either by commas (for single letters) or dashes (indicating a span of letters). One-letter spans, e.g.
G-G
, are valid. The outer parentheses must be included, but may be replaced with other paired delimiters (e.g.[]
or{}
) if desired. IMPLICIT
statements are guaranteed not to overlap. That is, no letter has its implied type specified more than once.- Alphabetic characters must be uppercase.
Output
The uppercase identifier, C
, D
, I
, L
, R
, or X
, that represents the implied type of the object GOD
. If the input is empty, your code must return R
(the default type of GOD
).
Test cases
Input -> Output
'' -> R
I(M-Z) -> R
I(A-Z) -> I
I(G) -> I
I(G-G) -> I
L(A,B,D-H,M-X,Z) -> L
D(D,X-Z), I(N-P) -> R
L(B,D,F,H,J,L,N,P,R,T,V,X,Z), C(A,C,E,G,I,K,M,O,Q,S,U,W,Y) -> C
D(S-Z), D(J-Q), D(A-H) -> D
I(I-K,M,R-T), R(N-P,U-Z), D(D-F,H), X(C,G), C(A,B,Q), L(L) -> X
I(F), X(N), R(P-P), I(C-C), C(A-A), I(J-J), R(V), D(H-H), X(O), L(B-B), C(R), L(Q-Q), I(D), L(X), R(S-S), C(Y), L(T-T), L(Z), X(U), D(K-K), R(G), X(W-W), D(I), C(L-L), R(E), I(M) -> R
Note: In the first test case, single quotes denote string boundaries.
Bonus imaginary internet points!
Awarded to answers that only use characters from the standard Fortran 77 character set: the 26 uppercase letters A-Z
, the 10 digits 0-9
, the space
, and the 12 characters +-*/=().,’:$
1, 2, 3, 4, 5, 6
instead ofC, D, I, L, R, X
. \$\endgroup\$['D', '(D,X-Z)']
? So would['D', '[D,X-Z]']
be valid input?. \$\endgroup\$GOD
objects are widely thought to be an anti-pattern by most programming linguistic theologists. \$\endgroup\$