This commit is contained in:
Debucquoy
2023-09-20 15:18:20 +02:00
parent 00d0cdfaf3
commit 4fd7542f03
228 changed files with 351 additions and 12 deletions

View 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")

View 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())

View 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'))

View 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')