I wrote it from memory
This commit is contained in:
parent
2a372c5d6f
commit
701a403eee
|
@ -1,80 +1,79 @@
|
||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
from string import digits
|
|
||||||
|
|
||||||
matchs = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
motchs = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
|
||||||
|
|
||||||
|
|
||||||
def getBarthday(inp):
|
def getBarthday(inp):
|
||||||
|
date = datetime.date(2000, 1, 1)
|
||||||
dates = []
|
dates = []
|
||||||
for i in range(1, int(inp) + 1):
|
for i in range(1, int(inp) + 1):
|
||||||
data = datetime.date(2000, 1, 1)
|
rand_day = datetime.timedelta(random.randint(1, 364))
|
||||||
rand_days = datetime.timedelta(random.randint(1, 364))
|
rand_date = date + rand_day
|
||||||
rand_date = data + rand_days
|
|
||||||
dates.append(rand_date)
|
dates.append(rand_date)
|
||||||
return dates
|
return dates
|
||||||
|
|
||||||
|
def sameDate(dates):
|
||||||
|
if len(dates) == len(set(dates)):
|
||||||
|
return None
|
||||||
|
for a, barthdeyA in enumerate(dates):
|
||||||
|
for b, barthdeyB in enumerate(dates[a + 1:]):
|
||||||
|
if barthdeyA == barthdeyB:
|
||||||
|
return barthdeyA
|
||||||
|
|
||||||
|
def getMonth(dates):
|
||||||
|
for i, date in enumerate(dates):
|
||||||
|
if i != 0:
|
||||||
def getMatch(list_date):
|
|
||||||
for a, barthdayA in enumerate(list_date):
|
|
||||||
for b, barthdayB in enumerate(list_date[a + 1:]):
|
|
||||||
if barthdayA == barthdayB:
|
|
||||||
return barthdayB
|
|
||||||
|
|
||||||
|
|
||||||
def numMatch(inp):
|
|
||||||
dates = getBarthday(inp)
|
|
||||||
for a, date in enumerate(dates):
|
|
||||||
if a != 0:
|
|
||||||
print(', ', end='')
|
print(', ', end='')
|
||||||
barthday = matchs[date.month - 1]
|
motch = motchs[date.month - 1]
|
||||||
print(f"{barthday} {date.day}", end='')
|
print(f"{motch} {date.day}", end='')
|
||||||
|
|
||||||
def sameMath(list_date):
|
def sameMonth(dates):
|
||||||
|
date = sameDate(dates)
|
||||||
if len(list_date) == len(set(list_date)):
|
if date != None:
|
||||||
print("\nNo such same birthday")
|
same_date = motchs[date.month - 1]
|
||||||
|
print(f"\nSame a {same_date} {date.day}")
|
||||||
else:
|
else:
|
||||||
same_math = getMatch(list_date)
|
print("Nohing same")
|
||||||
barthday = matchs[same_math.month - 1]
|
|
||||||
print(f"\nRepeat date {barthday} {same_math.day}")
|
|
||||||
|
|
||||||
def simulations(inp):
|
def simualtion(inp):
|
||||||
digit = 0
|
digit = 0
|
||||||
for i in range(100_000):
|
for i in range(100_000):
|
||||||
dates = getBarthday(inp)
|
dates = getBarthday(inp)
|
||||||
same_date = getMatch(dates)
|
sam_date = sameDate(dates)
|
||||||
if i % 10_000 == 0:
|
if i % 10_000 == 0 and i != 0:
|
||||||
print(f"{i} simulations...")
|
print(f"Simulations {i}")
|
||||||
if same_date != None:
|
if sam_date != None:
|
||||||
digit += 1
|
digit += 1
|
||||||
number = round((digit / 100_000) * 100, 2)
|
chanse = round((digit/100_000) * 100, 2)
|
||||||
print(f"Number same barthday = {digit}\n")
|
print(f"Same = {digit}")
|
||||||
print(f"And chance same birhday = {number}")
|
print(f"Chanse = {chanse}")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
print("Enter number no more than 100")
|
|
||||||
inp = ''
|
inp = ''
|
||||||
while not inp.isdecimal() or 0 > int(inp) > 100:
|
while not inp.isdecimal() or int(inp) > 100:
|
||||||
|
print("Enter number no more than 100")
|
||||||
inp = input("> ")
|
inp = input("> ")
|
||||||
list_date = getBarthday(inp)
|
dates = getBarthday(inp)
|
||||||
numMatch(inp)
|
getMonth(dates)
|
||||||
sameMath(list_date)
|
sameMonth(dates)
|
||||||
simulations(inp)
|
simualtion(inp)
|
||||||
print("You want repeat?")
|
print("You want play again?")
|
||||||
resp = input("(yes or no)> ")
|
if not input("(yes/no)> ").startswith('y'):
|
||||||
if not resp.lower().startswith('y'):
|
|
||||||
print("Thanks for playing")
|
print("Thanks for playing")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue