Guest User

1000 bottles

a guest
Aug 27th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. from random import randrange
  3.  
  4. class mouse(object) :
  5.     def __init__(self) :
  6.         self.alive = True
  7.        
  8.     def drink(self,bottle) :
  9.         if bottle.isPoisoned() == True :
  10.             self.alive = False
  11.     def isAlive(self) :
  12.         return self.alive
  13.  
  14. class wine(object) :
  15.     def __init__(self,num) :
  16.         self.number = num
  17.         self.poisoned = False
  18.     def setPoisoned(self) :
  19.         self.poisoned = True
  20.     def isPoisoned(self) :
  21.         return self.poisoned
  22.     def getNum(self) :
  23.         return self.number 
  24.  
  25. mice = []
  26. bottles = []
  27.  
  28. for i in range(0,1000) :
  29.     bottles.append(wine(i+1))
  30. for i in range(0,10) :
  31.     mice.append(mouse())
  32.  
  33. r = randrange(0,len(bottles))
  34. bottles[r].setPoisoned()
  35.  
  36. for bottle in bottles :
  37.     binbot = list(map(lambda a: int(a),"{0:010b}".format(bottle.getNum())))
  38.     for i in range(0,10) :
  39.         if binbot[i] == 1 :
  40.             if mice[i].isAlive() == False :
  41.                 continue #дохлая мышь не пьет, технически ненужный момент для имитации real life
  42.             mice[i].drink(bottle)  
  43.  
  44. answer = ''
  45. for m in mice :
  46.     if m.isAlive() == True :
  47.         answer += '0'
  48.     else :
  49.         answer += '1'
  50. print(int(answer,2))
Advertisement
Add Comment
Please, Sign In to add comment