53
5
Players of the traditional board game Go measure their skill in a system of ranks:
- Players new to the game are ranked 30th kyū (written
30k
) and progress counting down to 1st kyū (written1k
). These are considered the student ranks. - A player may promote from 1st kyū to 1st dan rank (written
1d
), and then progress counting up to 7th dan rank (written7d
). These are the master ranks. - Exceptionally skilled players past
7d
may promote to the 1st professional dan rank1p
, and progress counting up to 9th professional dan rank (written9p
). This is the highest rank.
In short: ranks are ordered 30k < 29k < ··· < 1k < 1d < 2d < ··· < 7d < 1p < 2p < ··· < 9p
.
Task
Given two strings among {30k
, …, 1k
, 1d
, …, 7d
, 1p
, …, 9p
} as input, output the higher rank of the two. (If they are equal, simply output either input.)
(As usual, I/O is flexible — your answer may be a function or a full program, reading input in any reasonable fashion and producing output in any reasonable fashion.)
This is code-golf: the objective is to minimize your code's byte count.
Test cases
(Format: input1 input2 output
.)
29k 9k 9k
21k 27k 21k
6d 1p 1p
5d 17k 5d
1k 1d 1d
1d 1d 1d
1d 2d 2d
9p 1d 9p
2d 30k 2d
1p 1k 1p
1d 1p 1p
1p 2d 1p
7p 8p 8p
30k 30k 30k
Can the inputs require leading zeroes? I.e. 04k – Amphibological – 2018-07-07T21:04:11.350
6No; while I'm flexible about I/O methods, I'm afraid I won't allow any variation in the input strings themselves — I think they are a perfect level of "interesting" as-is. (I won't allow
4 k
or4K
or so, either.) – Lynn – 2018-07-07T21:10:50.4832Are we allowed to take the inputs as (int, string) pairs? – None – 2018-07-07T21:15:51.727
9No; again, the spirit of the challenge is to manipulate the exact text strings
30k
,29k
,1k
,1d
et cetera, so I won't allow any variation there. – Lynn – 2018-07-07T21:26:06.153