.
This commit is contained in:
BIN
bac1/q1/renforcement/entrainement_0311/entrainement0311.pdf
Normal file
BIN
bac1/q1/renforcement/entrainement_0311/entrainement0311.pdf
Normal file
Binary file not shown.
27
bac1/q1/renforcement/entrainement_0311/ex1.py
Normal file
27
bac1/q1/renforcement/entrainement_0311/ex1.py
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
def find(chambre, etiquette):
|
||||
"""Find all occurence of etiquette in chambre and return a list of all his position
|
||||
|
||||
:chambre: matrice of item in chambre
|
||||
:etiquette: Element to find in chambre as string
|
||||
:returns: list of positions
|
||||
|
||||
"""
|
||||
ret = list()
|
||||
for x in range(len(chambre)):
|
||||
for y in range(len(chambre[x])):
|
||||
if etiquette == chambre[x][y]:
|
||||
ret.append((x,y))
|
||||
return ret
|
||||
|
||||
# Tests
|
||||
if __name__ == "__main__":
|
||||
chambre = [
|
||||
[ "A" , "A" , "B" , "D" ],
|
||||
[ "C" , "P" , "U" , "A" ],
|
||||
[ "M" , "O" , "N" , "S " ],
|
||||
[ "A" , "B" , "D" , "A" ]
|
||||
]
|
||||
print(find(chambre, 'A'), "should print 5 elemets")
|
||||
print(find(chambre, 'C'), "Should print 1 element")
|
||||
print(find(chambre, 'Elephant'), "Should print nothing")
|
32
bac1/q1/renforcement/entrainement_0311/ex2.py
Normal file
32
bac1/q1/renforcement/entrainement_0311/ex2.py
Normal file
@ -0,0 +1,32 @@
|
||||
def champ():
|
||||
"""Create a field, ask for size, amount of orni and position of said orni
|
||||
:returns: number of plan
|
||||
"""
|
||||
(N, M) = tuple(input("Size Quantity:").split()[:2])
|
||||
field = [['🌱' for y in range(int(N))] for x in range(int(N))]
|
||||
for i in range(int(M)):
|
||||
(_X, _Y) = tuple(input(f"(orni {i}) X Y:").split()[:2])
|
||||
field[int(_Y)][int(_X)] = '🦝'
|
||||
|
||||
for x in range(int(N)):
|
||||
for y in range(int(N)):
|
||||
if field[y][x] == '🦝':
|
||||
for i in range(x-1, x+2):
|
||||
for j in range(y-1, y+2):
|
||||
if field[j][i] == '🥕':
|
||||
field[j][i] = '💀'
|
||||
if field[j][i] == '🌱':
|
||||
field[j][i] = '🥕'
|
||||
return field
|
||||
|
||||
def draw_field(field):
|
||||
"""draw a field """
|
||||
for x in range(len(field)):
|
||||
for y in range(len(field[x])):
|
||||
print(field[x][y], end=' ')
|
||||
print()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
draw_field(champ())
|
7
bac1/q1/renforcement/entrainement_0311/ex3.py
Normal file
7
bac1/q1/renforcement/entrainement_0311/ex3.py
Normal file
@ -0,0 +1,7 @@
|
||||
def check_ticket(ticket):
|
||||
while(:)
|
||||
tosumuup = [int(i)for i in list(ticket)]
|
||||
return sum(tosumuup)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(check_ticket('999999'))
|
24
bac1/q1/renforcement/entrainement_0311/ex4.py
Normal file
24
bac1/q1/renforcement/entrainement_0311/ex4.py
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
def permutation(mot):
|
||||
"""find all permutation of a word
|
||||
|
||||
:mot: TODO
|
||||
:returns: list of all permutations
|
||||
|
||||
"""
|
||||
return permutation_rec('' , mot)
|
||||
|
||||
def permutation_rec(pre, post):
|
||||
print(pre, post)
|
||||
if (post == ''):
|
||||
return pre
|
||||
ret = list()
|
||||
for i in list(post):
|
||||
_post = list(post)
|
||||
_post.remove(i)
|
||||
ret.append(permutation_rec(pre + i, str(_post)))
|
||||
return ret
|
||||
|
||||
if __name__ == "__main__":
|
||||
permutation('abc')
|
||||
|
Reference in New Issue
Block a user