4 nouveaux défis

This commit is contained in:
2022-10-09 22:21:01 +02:00
parent 3b054d370c
commit 34b88066f0
4 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import datetime
days = (len("lundi"), len("mardi"), len("mercredi"), len("jeudi"), len("vendredi"), len("samedi"), len("dimanche"))
d = datetime.datetime.strptime("01/01/2000", "%d/%m/%Y")
end = datetime.datetime.now()
ctr = 0
while True:
if (days[d.weekday()] + d.day)%10 == 0:
ctr += 1
d = d + datetime.timedelta(days=1)
if d > end:
break
print(d, ctr)

36
Le cours de potions.py Normal file
View File

@@ -0,0 +1,36 @@
fioles = [20, 20, 20, 0]
for i in range(12):
current = i%4
next1 = (i+1)%4
next2 = (i+2)%4
next3 = (i+3)%4
#1/3 de N versé dans N+1
tiers = fioles[current]/3
if fioles[next1]+tiers > 25:
versé = 25-fioles[next1]
else:
versé = tiers
fioles[next1] = fioles[next1] + versé
fioles[current] = fioles[current] - versé
#1/3 de N versé dans N+2
tiers = fioles[current]/3
if fioles[next2]+tiers > 25:
versé = 25-fioles[next2]
else:
versé = tiers
fioles[next2] = fioles[next2] + versé
fioles[current] = fioles[current] - versé
#1/3 de N versé dans N+3
tiers = fioles[current]/3
if fioles[next3]+tiers > 25:
versé = 25-fioles[next3]
else:
versé = tiers
fioles[next3] = fioles[next3] + versé
fioles[current] = fioles[current] - versé
print(i+1, fioles)

13
Les dragées surprises.py Normal file
View File

@@ -0,0 +1,13 @@
dragees = ["A", "B", "E", "C", "G", "F", "M", "O", "H", "P", "S", "V"]
ctr = 0
while True:
ctr += 1
idx1 = (ctr * 5) % 12
idx0 = idx1-1 if idx1>0 else 11
dragees[idx0-1], dragees[idx1-1] = dragees[idx1-1], dragees[idx0-1]
if "A" in dragees[0:4] and "E" in dragees[0:4] and "G" in dragees[0:4] and "H" in dragees[0:4]:
break
print(ctr)
print(dragees)

View File

@@ -0,0 +1,21 @@
def next(x, y, z, n):
return y, z, (x+y+z)%n
if __name__ == "__main__":
x0, y0, z0 = 0, 0, 1
res = {}
for n in range(2, 201):
x, y, z = x0, y0, z0
ctr = 0
while True:
ctr += 1
x, y, z = next(x, y, z, n)
if x == x0 and y == y0 and z == z0:
print(n, ctr)
res[n] = ctr
break
for n in {k: v for k, v in sorted(res.items(), key=lambda item: item[1])}:
#print(n, res[n])
print(f"{n}, ", end = "")