0ì'-¡ÀDΣ2£<•88ΛηΣλšëÇñ0é≠>sîä&ζp°Lć®-αÅ®`•21вŽqT32в£Nèsè}Q
オンラインで試すか、チャレンジに記載されているすべての例を確認してください。
説明:
0ì # Prepend a "0" before the (implicit) input
# i.e. "2018-09-26" → "02018-09-26"
'-¡ '# Then split on "-"
# i.e. "02018-09-26" → ["02018","09","26"]
À # Rotate it once to the left (so [0yyyy,MM,dd] becomes [MM,dd,0yyyy])
# i.e. ["02018","09","26"] → ["09","26","02018"]
D # Duplicate this list
Σ # Sort this list by:
2£ # Leave only the first 2 digits of the current item
# (which is why the prepended 0 was there at the start for the year)
# i.e. "09" → "09"
# i.e. "02018" → "02"
< # Decrease it by 1 to make it 0-indexed
# i.e. "09" → 8
•88ΛηΣλšëÇñ0é≠>sîä&ζp°Lć®-αÅ®`•21в
# Push the list [7,3,7,0,7,7,7,0,13,10,10,0,4,12,17,6,4,17,15,2,9,17,2,19,17,6,4,17,15,2,9,19,19,19,19,19,19,19,19,19,19,17,17,11,20,18,5,5,16,14,1,8]
ŽqT32в # Push the list [12,31,9]
£ # Split the first list into parts of that size: [[7,3,7,0,7,7,7,0,13,10,10,0],
# [4,12,17,6,4,17,15,2,9,17,2,19,17,6,4,17,15,2,9,19,19,19,19,19,19,19,19,19,19,17,17],
# [11,20,18,5,5,16,14,1,8]]
Nè # Then only leave the relevant list of the three based on the sort-index
s # Swap to get the earlier integer at the top of the stack again
è # And use it to index into the list
# i.e. [7,3,7,0,7,7,7,0,13,10,10,0] and 8 → 13
} # Close the sort
Q # And check if the sorted list is equal to the duplicated list,
# so whether the order is still [MM,dd,0yyyy] after sorting
# (and output the result implicitly)
この05AB1Eのヒント(「整数リストを圧縮する方法」のセクション)を参照して、•88ΛηΣλšëÇñ0é≠>sîä&ζp°Lć®-αÅ®`•21вと[7,3,7,0,7,7,7,0,13,10,10,0,4,12,17,6,4,17,15,2,9,17,2,19,17,6,4,17,15,2,9,19,19,19,19,19,19,19,19,19,19,17,17,11,20,18,5,5,16,14,1,8]でŽqT32вある理由を理解してください[12,31,9]。
追加の一般的な説明:
ソート機能は、我々だけであればtruthy値が返されます場合は、同時にすべての3つのタイプ(日、月、年)をソートしますM < D < Y(ここで、これらのD、MとY私たちは圧縮されたリストから検索してきた値です)。
上記の3つのリストが選ばれる理由 すべての単語をタイプ別に分類すると、次の順序になります。
Sorting nr Type Which?
0 Month April, August, December
1 Year eight thousand
2 Day eighteenth, eighth, eleventh
3 Month February
4 Day fifteenth, fifth, first
5 Year five thousand, four thousand
6 Day fourteenth, fourth
7 Month January, July, June, March, May
8 Year nine thousand
9 Day ninteenth, ninth
10 Month November, October
11 Year one thousand
12 Day second
13 Month September
14 Year seven thousand
15 Day seventeenth, seventh
16 Year six thousand
17 Day sixteenth, sixth, tenth, third, thirteenth, thirtieth, thirty-first
18 Year three thousand
19 Day twelfth, twentieth, twenty-first through twenty-ninth
20 Year two thousand
次に、各タイプとその元の順序(年は1000、2000など、月は1月、2月など、日は1番目、2番目など)を見ると、上記のソート番号はこれらの順序で:
Years: [11,20,18,5,5,16,14,1,8]
Months: [7,3,7,0,7,7,7,0,13,10,10,0]
Days: [4,12,17,6,4,17,15,2,9,17,2,19,17,6,4,17,15,2,9,19,19,19,19,19,19,19,19,19,19,17,17]