renforcement + livre

This commit is contained in:
Debucquoy 2022-11-09 16:22:14 +01:00
parent d574695633
commit 948d17166a
No known key found for this signature in database
GPG Key ID: 3B9EEB701C9E2919
15 changed files with 186 additions and 1 deletions

16
livres/ex_cpp/Makefile Normal file
View File

@ -0,0 +1,16 @@
CXX = c++
CXXFLAGS = -Wall -g
LDFLAGS= -lm
SOURCE_POINTS= points.cpp main.cpp
all: points
points: $(SOURCE_POINTS)
$(CXX) $(CXXFLAGS) -o $@ $(SOURCE_POINTS) $(LDFLAGS)
run: points
./points
clean:
rm -f *.o ./points

16
livres/ex_cpp/main.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "points.h"
#include <iostream>
int main(int argc, char *argv[])
{
Points p(5,5);
std::cout << p.abscisse() << ' ' << p.ordonnee() << std::endl;
std::cout << p.rho() << ' ' << p.theta() << std::endl;
p.deplace(3.1, 2);
std::cout << p.abscisse() << ' ' << p.ordonnee() << std::endl;
return 0;
}

BIN
livres/ex_cpp/points Executable file

Binary file not shown.

39
livres/ex_cpp/points.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "points.h"
#include "math.h"
Points::Points(float m_x, float m_y)
: x(m_x), y(m_y){}
// SETTERS
void Points::deplace(float m_dx, float m_dy){
x += m_dx;
y += m_dy;
}
void Points::homothetie(float k){
x *= k;
y *= k;
}
void Points::rotation(float angle){
}
// GETTERS
float Points::abscisse(){
return x;
}
float Points::ordonnee(){
return y;
}
float Points::rho(){
return sqrt(x*x + y*y);
}
float Points::theta(){
return atan(y/x);
}

24
livres/ex_cpp/points.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef POINTS_H
#define POINTS_H
class Points
{
private:
float x, y;
public:
Points(float x, float y);
void deplace(float, float);
void homothetie(float);
void rotation(float);
float abscisse();
float ordonnee();
float rho();
float theta();
};
#endif /* POINTS_H */

Binary file not shown.

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