How good am I at CS:GO?
JavaScript (ES6), 164 150 135 bytes
s=>'GE S1|S2|S3|S4|SE|SEMGN1GN2GN3GNMMG1MG2MGEDMGLE LEMSMFC'.search(s[r='replace'](/[a-z ]/g,'')[r]('IV',4)[r](/I+/,a=>a.length))/3||18
(Saved a bunch of bytes thanks to @Craig Ayre and @Steve Bennett.)
Explanation:
s[r='replace'](/[a-z ]/g,'')[r]('IV',4)[r](/I+/,a=>a.length)
converts Full names to the SN equivalents. It doesn't change SNs.
We then simply index into the array of SNs created by split
.
Snippet:
f=
s=>'GE S1|S2|S3|S4|SE|SEMGN1GN2GN3GNMMG1MG2MGEDMGLE LEMSMFC'.search(s[r='replace'](/[a-z ]/g,'')[r]('IV',4)[r](/I+/,a=>a.length))/3||18
console.log(f('Silver I')); // S1 -> 1
console.log(f('Silver II')); // S2 -> 2
console.log(f('Silver III')); // S3 -> 3
console.log(f('Silver IV')); // S4 -> 4
console.log(f('Silver Elite')); // SE -> 5
console.log(f('Silver Elite Master')); // SEM -> 6
console.log(f('Gold Nova I')); // GN1 -> 7
console.log(f('Gold Nova II')); // GN2 -> 8
console.log(f('Gold Nova III')); // GN3 -> 9
console.log(f('Gold Nova Master')); // GNM -> 10
console.log(f('Master Guardian I')); // MG1 -> 11
console.log(f('Master Guardian II')); // MG2 -> 12
console.log(f('Master Guardian Elite')); // MGE -> 13
console.log(f('Distinguished Master Guardian')); // DMG -> 14
console.log(f('Legendary Eagle')); // LE -> 15
console.log(f('Legendary Eagle Master')); // LEM -> 16
console.log(f('Supreme Master First Class')); // SMFC -> 17
console.log(f('Global Elite')); // GE -> 18
console.log(f('S1'));
console.log(f('S2'));
console.log(f('S3'));
console.log(f('S4'));
console.log(f('SE'));
console.log(f('SEM'));
console.log(f('GN1'));
console.log(f('GN2'));
console.log(f('GN3'));
console.log(f('GNM'));
console.log(f('MG1'));
console.log(f('MG2'));
console.log(f('MGE'));
console.log(f('DMG'));
console.log(f('LE'));
console.log(f('LEM'));
console.log(f('SMFC'));
console.log(f('GE'));
Ruby, 120 111 100 99 bytes
->x{x.tr!'a-z ','';x.gsub!(/I.*/){$&.sum%18%11};'
'[x.sum%36%20+x.ord%4].ord}
Hexdump, since the Stack Exchange software mangles lots of the unprintables in the source code:
00000000: 2d3e 787b 782e 7472 2127 612d 7a20 272c ->x{x.tr!'a-z ',
00000010: 2727 3b78 2e67 7375 6221 282f 492e 2a2f '';x.gsub!(/I.*/
00000020: 297b 2426 2e73 756d 2531 3825 3131 7d3b ){$&.sum%18%11};
00000030: 270e 0f0d 0920 2010 0102 0304 0511 0a20 '.... ........
00000040: 1206 200b 0c20 0708 275b 782e 7375 6d25 .. .. ..'[x.sum%
00000050: 3336 2532 302b 782e 6f72 6425 345d 2e6f 36%20+x.ord%4].o
00000060: 7264 7d rd}
Try it online!
(Note: I can't figure out how to get a carriage return into the "Code" box on TIO, so the TIO version has it replaced with an X
and hence outputs 88
instead of 13
for MGE.)
Explanation:
x.tr!'a-z ',''
This deletes all lowercase letters and spaces from the input.
x.gsub!(/I.*/){$&.sum%18%11}
This searches for an I
in the string and, if found, replaces it to the end of the string with the result of a black-magic algorithm (found by brute force search) that produces the numeric equivalent of the Roman numeral.
'junk'[more junk].ord
The first section of junk (and the ord
) maps the values [7, 8, 9, 10, 11, 16, 21, 22, 3, 13, 18, 19, 2, 0, 1, 6, 12, 15]
to the range 1..18
by indexing into the string, which contains the appropriate bytes at their corresponding indices.
The second section of junk maps the values ["S1", "S2", "S3", ...]
to the values [7, 8, 9, ...]
. The formula was produced by a simple brute force search minimizing the maximum value obtained while ensuring that 18 unique values still exist.
PHP, 151 Bytes
0-Indexing
Remove all characters that not Uppercase or digit
After that replace the digits with their roman numbers
Search and Output the Key in the Array
<?=array_flip([SI,SII,SIII,SIV,SE,SEM,GNI,GNII,GNIII,GNM,MGI,MGII,MGE,DMG,LE,LEM,SMFC,GE])[strtr(preg_replace("#[^C-V\d]#","",$argn),[_,I,II,III,IV])];
Try it online!
PHP, 158 Bytes
0-Indexing
Remove all characters that not Uppercase
After that replace the roman numbers with their digit
Search and Output the Key in the Array
<?=array_flip([S1,S2,S3,S4,SE,SEM,GN1,GN2,GN3,GNM,MG1,MG2,MGE,DMG,LE,LEM,SMFC,GE])[preg_replace(["#[^C-V]#","#IV#","#III#","#II#","#I#"],["",4,3,2,1],$argn)];
Try it online!
PHP, 295 Bytes
0-Indexing Without Regex
Search and Output the Key of an Array
If more than 4 characters are set in the input take the array with the longer names else take the array with the short names
<?=array_flip(explode(_,$argn[4]?strtr("0I_0II_0III_0IV_03_03 4_1I_1II_1III_14_45I_45II_453_Distinguished 45DMG_2_2 4_Supreme 4 First Class_Global 3",["Silver ","Gold Nova ","Legendary Eagle",Elite,Master," Guardian "]):S1_S2_S3_S4_SE_SEM_GN1_GN2_GN3_GNM_MG1_MG2_MGE_DMG_LE_LEM_SMFC_GE))[$argn];
Try it online!