RollingStone によると、すべての時間の26の最高の歌手:
Aretha Franklin Al Green
Ray Charles Robert Plant
Elvis Presley Mick Jagger
Sam Cooke Tina Turner
John Lennon Freddie Mercury
Marvin Gaye Bob Marley
Bob Dylan Smokey Robinson
Otis Redding Johnny Cash
Stevie Wonder Etta James
James Brown David Bowie
Paul McCartney Van Morrison
Little Richard Michael Jackson
Roy Orbison Jackie Wilson
これをここの文字列のリストとして取得できます。
仕事
歌手の名前が与えられたら、この歌手を一意に識別する A
から Z
に文字を印刷するか返します。 (コードが Bob Dylan に対して A
を返した場合、他の歌手にとっては A を返すことはできません)。
他の同様の課題とは異なり、衝突のない限り マッピングはあなた次第です
。
ルール
- The input is guaranteed to be one of the 26 singer names listed
above with this exact spelling and without any leading or trailing
whitespace. - You may output the letter in either lowercase or uppercase. But
it must be consistent. - You are encouraged to provide a test suite for all 26 possible
inputs. - This is code-golf,
so the shortest answer in bytes wins!
ベストアンサー
Python
2, 80 71 bytes
def f(s):i=sum(map(ord,s))%98%40;return chr(i-i/26*18+i/32*3-i/37*8+65)
オンラインで試してみよう!
The sums of ordinals modded give numbers between 0
and 38
25を超える数は、次のように空白を埋めるようにシフトされます(並べ替えられたシーケンスが表示されます)。
0 1 2 3 4 5 6 7 8 - - - - 13 14 - 16 - 18 - - - 22 23 24 25 - 27 28 29 30 - 32 - 34 35 36 - 38
Subtract 18
if i>25
:
0 1 2 3 4 5 6 7 8 - - - - 13 14 - 16 - 18 - - - 22 23 24 25
- 27 28 29 30 - 32 - 34 35 36 - 38
Add 3
if i>31
:
0 1 2 3 4 5 6 7 8 - - - - 13 14 - 16 - 18 - - - 22 23 24 25
- 27 28 29 30
- 32 - 34 35 36 - 38
Subtract 8
if i>37
:
0 1 2 3 4 5 6 7 8 - - - - 13 14 - 16 - 18 - - - 22 23 24 25
- 27 28 29 30
- 32 - 34 35 36
- 38
Which gives the sequence 0..25
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
These are then converted to A-Z
with
chr(i+65)