fork download
  1. import numpy as np
  2. import hashlib
  3.  
  4. # 추첨 인원수
  5. winner_num = 5
  6. # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
  7. info = """
  8. 1 bwgreen 1 / 3 1 / 7 1 / 10 2 / 43 2 / 53 6 / 165 3 / 134 2 / 162 8 / 577
  9. 2 glnthd02 1 / 1474 2 / 1500 1 / 1490 2 / 1675 7 / 2103 4 / 1673 1 / 1892 1 / 7304 8 / 19111
  10. 3 hms0510 1 / 156 1 / 163 1 / 173 3 / 1576 3 / 1946 3 / 2854 4 / 6043 0 / -- 7 / 12911
  11. 4 kelvin3596 1 / 1980 1 / 1968 1 / 1946 3 / 1683 6 / 1788 12 / 2147 0 / -- 0 / -- 6 / 11512
  12. 5 gandori3 1 / 612 1 / 619 1 / 625 1 / 2765 2 / 3439 5 / 3543 0 / -- 0 / -- 6 / 11603
  13. 6 rlawoaks 1 / 71 2 / 108 3 / 318 5 / 5984 18 / 6340 0 / -- 0 / -- 0 / -- 5 / 12821
  14. 7 chipi2302 1 / 2097 1 / 3451 1 / 4894 1 / 6335 5 / 7356 0 / -- 0 / -- 0 / -- 5 / 24133
  15. 8 yuujeong0816 1 / 165 1 / 181 1 / 235 4 / -- 7 / 4767 8 / -- 0 / -- 0 / -- 4 / 5348
  16. 9 dksalsdn0226 1 / 3090 1 / 3100 1 / 3109 5 / 3214 0 / -- 0 / -- 0 / -- 0 / -- 4 / 12513
  17. 10 bakbakwanwan 1 / 578 1 / 603 1 / 620 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 3 / 1801
  18. 11 jung0722 1 / 1572 1 / 1589 1 / 1607 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 3 / 4768
  19. 12 choiseoo 1 / 1711 5 / 1825 1 / 1769 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 3 / 5305
  20. 13 harrysooin 1 / 112 0 / -- 1 / 2749 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 2861
  21. 14 kdy06 1 / 1886 1 / 1916 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 3802
  22. 15 aerae 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 1913 0 / -- 2 / 3084 2 / 4997
  23. 16 psh030122 1 / 4385 0 / -- 1 / 6338 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 10723
  24. 17 aarhrl2 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 7300 9 / 8772 0 / -- 2 / 16072
  25. 18 ansinbin000 1 / 1633 1 / -- 0 / -- 1 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 1633
  26. """
  27. info = info.splitlines(keepends = True)
  28. if info[0] == "\n": info.pop(0)
  29.  
  30. # 랜덤 시드
  31. mod = 4294967296 # 2^32
  32. seed_string = "250922"
  33. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  34. np.random.seed(random_seed)
  35.  
  36. participants = {}
  37. for participant in info:
  38. participant = participant.split('\t')
  39. user = participant[1]
  40. corrects = int(participant[-1].split(' / ')[0])
  41. if user in participants:
  42. participants[user] = max(participants[user], corrects + 3)
  43. else: participants[user] = corrects + 3
  44.  
  45. # 추첨 명단 제외 리스트
  46. except_list = ['aerae','likescape']
  47. for except_user in except_list:
  48. try:
  49. participants.pop(except_user)
  50. except:
  51. pass
  52.  
  53. # 추첨 확률 설정
  54. winner_percent = [0] * len(participants)
  55. correct_problems_sum = sum(participants.values())
  56.  
  57. for i, corrects in enumerate(list(participants.values())):
  58. winner_percent[i] = corrects / correct_problems_sum
  59.  
  60. print(f'랜덤 시드: {seed_string}')
  61. print(f'{len(participants)}명 {list(participants.keys())}')
  62. # print(f'맞은 문제 개수: {list(participants.values())}')
  63. # print(f'확률: {winner_percent}')
  64.  
  65. # 당첨자
  66. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  67. if winner_num < len(participants) else list(participants.keys())
  68. winner.sort()
  69. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 0.78s 41564KB
stdin
Standard input is empty
stdout
랜덤 시드: 250922
17명 ['bwgreen', 'glnthd02', 'hms0510', 'kelvin3596', 'gandori3', 'rlawoaks', 'chipi2302', 'yuujeong0816', 'dksalsdn0226', 'bakbakwanwan', 'jung0722', 'choiseoo', 'harrysooin', 'kdy06', 'psh030122', 'aarhrl2', 'ansinbin000']
당첨자: ['dksalsdn0226' 'glnthd02' 'hms0510' 'rlawoaks' 'yuujeong0816']