https://ctf.cpaw.site/questions.php?qnum=14
CpawCTFのQ14をPython解いてみるメモです
配列を降順に並び替えるらしい
せっかくなのでPythonで記述したい
結果を先に書くとこんな感じ
list = [15,1,93,52,66,31,87,0,42,77,46,24,99,10,19,36,27,4,58,76,2,81,50,102,33,94,20,14,80,82,49,41,12,143,121,7,111,100,60,55,108,34,150,103,109,130,25,54,57,159,136,110,3,167,119,72,18,151,105,171,160,144,85,201,193,188,190,146,210,211,63,207]
sort_list = sorted(list, reverse=True)
answer = ''.join(map(str,sort_list))
print(answer)
※参考させていただいたURL
https://note.nkmk.me/python-list-sort-sorted/
https://note.nkmk.me/python-string-concat/
最初にjoinのところを
answer = ''.join(sort_list)
と記述したところ下記のようなエラーが出た
TypeError: sequence item 0: expected str instance, int found
どうもjoinはstr型じゃないといけないらしく、下記の通りmap()で型を変換できるらしいのでやってみたらエラーを吐かなくなった
answer = ''.join(map(str,sort_list))
調べればもっと簡単なのがありそうな気もするけどとりあえず解けたのでメモとして残しておく(´・ω・`)
###※追記
遠回りせずともIDLEで一発だった(´;ω;`)
>>> spam = [15,1,93,52,66,31,87,0,42,77,46,24,99,10,19,36,27,4,58,76,2,81,50,102,33,94,20,14,80,82,49,41,12,143,121,7,111,100,60,55,108,34,150,103,109,130,25,54,57,159,136,110,3,167,119,72,18,151,105,171,160,144,85,201,193,188,190,146,210,211,63,207]
>>>
>>>
>>> spam
[0, 1, 2, 3, 4, 7, 10, 12, 14, 15, 18, 19, 20, 24, 25, 27, 31, 33, 34, 36, 41, 42, 46, 49, 50, 52, 54, 55, 57, 58, 60, 63, 66, 72, 76, 77, 80, 81, 82, 85, 87, 93, 94, 99, 100, 102, 103, 105, 108, 109, 110, 111, 119, 121, 130, 136, 143, 144, 146, 150, 151, 159, 160, 167, 171, 188, 190, 193, 201, 207, 210, 211]