fork download
  1. import numpy as np
  2. import hashlib
  3.  
  4. # 추첨 인원수
  5. winner_num = 5
  6. # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
  7. info = """
  8. 3 bwgreen 3 / 999 1 / 960 2 / 1087 2 / 1099 1 / 1092 5 / 1291 1 / 2214 7 / 8742
  9. 4 glnthd02 3 / 2040 1 / 2358 1 / 3100 3 / 3788 3 / 3194 2 / 3825 1 / 4248 7 / 22553
  10. 5 codingstarfish 1 / 3966 1 / 3972 2 / 4005 1 / 4009 2 / 4042 1 / 4332 3 / 4417 7 / 28743
  11. 6 haerizian 2 / 1566 1 / 1683 1 / 1714 3 / 2811 2 / 2830 2 / 3073 10 / -- 6 / 13677
  12. 7 hms0510 2 / 1528 1 / 1293 1 / 2341 4 / 2662 2 / 3033 4 / 3012 0 / -- 6 / 13869
  13. 8 choiseoo 1 / 1316 1 / 1359 1 / 1519 1 / 2838 2 / 2888 0 / -- 0 / -- 5 / 9920
  14. 9 jung0722 1 / 3908 1 / 3930 1 / 3948 1 / 3992 1 / 4036 0 / -- 0 / -- 5 / 19814
  15. 10 psh030122 2 / 2295 1 / 2292 4 / 2701 1 / 5391 0 / -- 0 / -- 0 / -- 4 / 12679
  16. 11 bakbakwanwan 1 / 244 1 / 250 0 / -- 0 / -- 1 / 2670 0 / -- 0 / -- 3 / 3164
  17. 12 sjyoon1101 3 / 1273 1 / 1257 1 / 1458 8 / -- 0 / -- 0 / -- 0 / -- 3 / 3988
  18. 13 ansinbin000 1 / 1257 1 / 1283 3 / 1620 1 / -- 0 / -- 0 / -- 0 / -- 3 / 4160
  19. 14 upncol 0 / -- 0 / -- 0 / -- 2 / 4484 5 / 4703 1 / 4585 0 / -- 3 / 13772
  20. 15 gandori3 1 / 8305 1 / 8309 3 / -- 0 / -- 0 / -- 1 / 8101 0 / -- 3 / 24715
  21. 16 kelvin3596 2 / 8458 1 / 8440 2 / 8506 0 / -- 0 / -- 0 / -- 0 / -- 3 / 25404
  22. 17 osskch1 1 / 1297 1 / 1307 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 2604
  23. 18 yuujeong0816 1 / 5567 1 / 6953 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 12520
  24. 19 aarhrl2 0 / -- 0 / -- 0 / -- 1 / 5195 2 / 8359 0 / -- 0 / -- 2 / 13554
  25. 20 kdy06 1 / 8460 1 / 8489 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 16949
  26. 21 chipi2302 2 / 1596 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 1596
  27. 22 haein0684 1 / 6019 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 6019
  28. """
  29. info = info.splitlines(keepends = True)
  30. if info[0] == "\n": info.pop(0)
  31.  
  32. # 랜덤 시드
  33. mod = 4294967296 # 2^32
  34. seed_string = "250909"
  35. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  36. np.random.seed(random_seed)
  37.  
  38. participants = {}
  39. for participant in info:
  40. participant = participant.split('\t')
  41. user = participant[1]
  42. corrects = int(participant[-1].split(' / ')[0])
  43. if user in participants:
  44. participants[user] = max(participants[user], corrects + 3)
  45. else: participants[user] = corrects + 3
  46.  
  47. # 추첨 명단 제외 리스트
  48. except_list = ['aerae']
  49. for except_user in except_list:
  50. try:
  51. participants.pop(except_user)
  52. except:
  53. pass
  54.  
  55. # 추첨 확률 설정
  56. winner_percent = [0] * len(participants)
  57. correct_problems_sum = sum(participants.values())
  58.  
  59. for i, corrects in enumerate(list(participants.values())):
  60. winner_percent[i] = corrects / correct_problems_sum
  61.  
  62. print(f'랜덤 시드: {seed_string}')
  63. print(f'{len(participants)}명 {list(participants.keys())}')
  64. # print(f'맞은 문제 개수: {list(participants.values())}')
  65. # print(f'확률: {winner_percent}')
  66.  
  67. # 당첨자
  68. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  69. if winner_num < len(participants) else list(participants.keys())
  70. winner.sort()
  71. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 0.78s 41708KB
stdin
Standard input is empty
stdout
랜덤 시드: 250909
20명 ['bwgreen', 'glnthd02', 'codingstarfish', 'haerizian', 'hms0510', 'choiseoo', 'jung0722', 'psh030122', 'bakbakwanwan', 'sjyoon1101', 'ansinbin000', 'upncol', 'gandori3', 'kelvin3596', 'osskch1', 'yuujeong0816', 'aarhrl2', 'kdy06', 'chipi2302', 'haein0684']
당첨자: ['ansinbin000' 'choiseoo' 'gandori3' 'hms0510' 'upncol']