Compare commits
16 Commits
5c73c32975
...
master
Author | SHA1 | Date | |
---|---|---|---|
2b23ebf562
|
|||
15c3bf45ff
|
|||
00d0cdfaf3
|
|||
d0ef521917
|
|||
690720e54d
|
|||
a526edbd8d
|
|||
dcb24a67d0
|
|||
820bd8d1ad
|
|||
cac30ebbb1
|
|||
23a079c89a
|
|||
454ac6e17e
|
|||
c561eda0cf | |||
5456020f7c | |||
d3c715a655
|
|||
2109fa74c0 | |||
93ae5a67d2 |
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
__pycache__/
|
||||
*.tar
|
||||
*.class
|
||||
|
@ -1,39 +0,0 @@
|
||||
#!/bin/python
|
||||
""" Compression
|
||||
Usage:
|
||||
compression.py (-c|-d) -t <type> --in <input> [--out <output>]
|
||||
compression.py -h | --help
|
||||
compression.py --version
|
||||
|
||||
Options:
|
||||
-h --help Show this screen
|
||||
--version Show Version
|
||||
-c Compress
|
||||
-d Decompress
|
||||
-t Choose Compression Type
|
||||
--in Input file
|
||||
--out Output file
|
||||
"""
|
||||
|
||||
def read_file(filename:str):
|
||||
try:
|
||||
with open(filename) as file:
|
||||
return file.readall()
|
||||
except e:
|
||||
print(e)
|
||||
|
||||
|
||||
def lz_compression(text:str):
|
||||
"""compress all duplicate word
|
||||
put each word into a list and make make a string of all the occurence
|
||||
|
||||
:text: string to compress
|
||||
:returns: tuple with (list of word, decoding string)
|
||||
|
||||
"""
|
||||
splitted_text = text.split()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from docopt import docopt
|
||||
argument = docopt(__doc__, version="V1")
|
BIN
project/bonnes-pratiques.pdf
Normal file
90
q1/01dec/compress.py
Executable file
@ -0,0 +1,90 @@
|
||||
#!/bin/python
|
||||
""" Compression
|
||||
Usage:
|
||||
compression.py (-c|-d) -t <type> --in <input> [--out <output>]
|
||||
compression.py -h | --help
|
||||
compression.py --version
|
||||
|
||||
Options:
|
||||
-h --help Show this screen
|
||||
--version Show Version
|
||||
-c Compress
|
||||
-d Decompress
|
||||
-t Choose Compression Type (currently supported: lz, rle)
|
||||
--in Input file
|
||||
--out Output file
|
||||
"""
|
||||
|
||||
def read_file(filename:str) -> str:
|
||||
try:
|
||||
with open(filename) as file:
|
||||
return file.read()
|
||||
except e:
|
||||
print(e)
|
||||
|
||||
|
||||
def lz_compression(text:str):
|
||||
"""compress all duplicate word
|
||||
put each word into a list and make make a string of all the occurence
|
||||
|
||||
:text: string to compress
|
||||
:returns: tuple with (list of word, decoding string)
|
||||
|
||||
"""
|
||||
splitted_text = text.split()
|
||||
word_list = list()
|
||||
key = dict()
|
||||
key_value = 0
|
||||
for v in splitted_text:
|
||||
if v not in key.keys():
|
||||
key[v] = key_value
|
||||
key_value += 1
|
||||
word_list.append(key[v])
|
||||
return word_list, key
|
||||
|
||||
def save_lz(filename, word_list, key_list):
|
||||
with open(filename, 'w') as file:
|
||||
word_list = map(str, word_list)
|
||||
file.writelines(' '.join(word_list))
|
||||
file.writelines(' '.join(list(key_list.items())))
|
||||
|
||||
|
||||
def lz_decompression(text:str):
|
||||
pass
|
||||
|
||||
|
||||
def rle_compression(text:str):
|
||||
"""compress all duplicate word
|
||||
put each word into a list and make make a string of all the occurence
|
||||
|
||||
:text: string to compress
|
||||
:returns: tuple with (list of word, decoding string)
|
||||
|
||||
"""
|
||||
splitted_text = text.split()
|
||||
|
||||
|
||||
def rle_decompression(text:str):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from docopt import docopt
|
||||
argument = docopt(__doc__, version="V1")
|
||||
print(argument)
|
||||
if argument['<type>'].lower() == 'lz':
|
||||
if argument['-d']:
|
||||
result = lz_decompression(read_file(argument['<input>']))
|
||||
print(result)
|
||||
if argument['-c']:
|
||||
w_list, k_list = lz_compression(read_file(argument['<input>']))
|
||||
save_lz('test.Ltxt', w_list, k_list)
|
||||
elif argument['<type>'].lower() == 'rle':
|
||||
if argument['-d']:
|
||||
result = rle_decompression(read_file(argument['<input>']))
|
||||
print(result)
|
||||
if argument['-c']:
|
||||
result = rle_compression(read_file(argument['<input>']))
|
||||
print(result)
|
||||
else:
|
||||
raise TypeError("choose a type between lz and rle")
|
1
q1/01dec/test.Ltxt
Normal file
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 256 KiB |
Before Width: | Height: | Size: 321 KiB After Width: | Height: | Size: 321 KiB |
Before Width: | Height: | Size: 261 KiB After Width: | Height: | Size: 261 KiB |
Before Width: | Height: | Size: 790 KiB After Width: | Height: | Size: 790 KiB |
Before Width: | Height: | Size: 727 KiB After Width: | Height: | Size: 727 KiB |
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
27
q1/15dec/fonctions.py
Normal file
@ -0,0 +1,27 @@
|
||||
def plus_grand_bord(w):
|
||||
for k, v in enumerate(w[1:]):
|
||||
if v == w[0]:
|
||||
if w[k+1:] == w[:len(w[k+1:])]:
|
||||
return w[k+1:]
|
||||
return None
|
||||
|
||||
def intersection(v, w):
|
||||
max_inter = ''
|
||||
for (k, v) in enumerate(v):
|
||||
if v in w:
|
||||
i = 1
|
||||
while v[k:k+i] in w:
|
||||
i += 1
|
||||
if i >= len(w):
|
||||
break
|
||||
if len(v[k:k+i]) > len(max_inter):
|
||||
max_inter = v[k:k+i]
|
||||
return max_inter
|
||||
|
||||
|
||||
def palyndrome(mot):
|
||||
inv = [mot[len(mot)-1-i] for i in range(len(mot))]
|
||||
return inv
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(palyndrome('anticonstitutionnelement'))
|
BIN
q1/15dec/serie12.pdf
Normal file
16
q1/renforcement/entrainement_0712/cup.py
Normal file
@ -0,0 +1,16 @@
|
||||
tab = map(int, input().split)
|
||||
|
||||
def nombre_tasse(tab):
|
||||
"""count the ammount of tasse following weird set of rules """
|
||||
start_cup = 0
|
||||
in_cup = False
|
||||
for k, v in enumerate(tab):
|
||||
if v < tab[k+1]:
|
||||
in_cup = True
|
||||
start_cup = k
|
||||
elif v < tab[k-1]:
|
||||
if
|
||||
|
||||
return count
|
||||
|
||||
print(nombre_tasse(tab))
|
BIN
q1/renforcement/entrainement_0712/entrainement.pdf
Normal file
68
q1/renforcement/entrainement_0712/member_list.py
Normal file
@ -0,0 +1,68 @@
|
||||
from datetime import datetime
|
||||
|
||||
class Member:
|
||||
|
||||
"""Represente un membre dans la base de donnee de l'umons """
|
||||
|
||||
def __init__(self, name, surname, faculty, section, register_date = datetime.now().strftime("%Y%m%d"), seen = 0, seen_dates = list()):
|
||||
"""TODO: to be defined.
|
||||
|
||||
:seen: number of time he came to CPUMONS
|
||||
:seen_dates: date when he came
|
||||
|
||||
"""
|
||||
|
||||
self._name = name
|
||||
self._surname = surname
|
||||
self._mail = f"{name}.{surname}@studen.umons.ac.be"
|
||||
self._faculty = faculty
|
||||
self._section = section
|
||||
self._register_date = register_date
|
||||
self._seen = seen
|
||||
self._seen_dates = seen_dates
|
||||
|
||||
def __str__(self):
|
||||
return f"{self._name} {self._surname}, {self._faculty} -> {self._section}; seen {self._seen} time(s)"
|
||||
|
||||
def addSeen(self, date = datetime.now().strftime("%Y%m%d")):
|
||||
self._seen += 1
|
||||
self._seen_dates.append(date)
|
||||
|
||||
def interaction_menu(mbr_list):
|
||||
print("""
|
||||
1) Insert new member
|
||||
2) List members
|
||||
3) Delete a member
|
||||
4) Update member
|
||||
5) Quit
|
||||
""")
|
||||
try:
|
||||
menu_selection = int(input("select your action: "))
|
||||
except:
|
||||
return True
|
||||
|
||||
if menu_selection == 1: # Insert new member
|
||||
name, surname, faculty, section = input("enter: <name surname faculty section> (with space between each input): ").split(' ')
|
||||
mbr_list.append(Member(name, surname, faculty, section))
|
||||
elif menu_selection == 2: # List members
|
||||
for k, v in enumerate(mbr_list):
|
||||
print(k, v)
|
||||
elif menu_selection == 3: # Delete a member
|
||||
toDelUser = input("enter the index of the user you want to delete: ")
|
||||
mbr_list.pop(toDelUser)
|
||||
elif menu_selection == 4: # Update member
|
||||
toUpdateUser = int(input("enter the index of the user you want to update: "))
|
||||
datetime = input("enter the date where he has been seen ( let blank for the current date ): ")
|
||||
if not datetime:
|
||||
mbr_list[toUpdateUser].addSeen()
|
||||
else:
|
||||
mbr_list[toUpdateUser].addSeen(datetime)
|
||||
else: # Menu error/quit
|
||||
return False
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
user_list = list()
|
||||
exit = False
|
||||
while not exit:
|
||||
exit = not interaction_menu(user_list)
|
14
q1/renforcement/entrainement_0712/stringdiff.py
Normal file
@ -0,0 +1,14 @@
|
||||
def diff(in1: str, in2: str) -> list:
|
||||
ret = list()
|
||||
for k, v in enumerate(in1):
|
||||
if in2[k] != v :
|
||||
ret.append((k, v, in2[k]))
|
||||
return ret
|
||||
|
||||
if __name__ == "__main__":
|
||||
in1, in2 = input("entrez la phrase 1:") , input("entrez la phrase 2")
|
||||
diff_ins = diff(in1, in2)
|
||||
if len(diff_ins) == 0:
|
||||
print("Phrases identiques")
|
||||
else:
|
||||
print(diff_ins)
|
27
q2/algo/cours2/Couple.java
Normal file
@ -0,0 +1,27 @@
|
||||
public class Couple {
|
||||
|
||||
private int q;
|
||||
private int r;
|
||||
|
||||
public Couple(int q, int r) {
|
||||
this.q = q;
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public void setQ(int q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public int getQ() {
|
||||
return q;
|
||||
}
|
||||
|
||||
public void setR(int r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public int getR() {
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
11
q2/algo/cours2/Division.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class Division {
|
||||
public static void main(String[] args) {
|
||||
Couple test = Division(5, 3);
|
||||
System.out.println(test.getQ() + ": " + test.getR());
|
||||
|
||||
}
|
||||
public static Couple Division(int a, int b){
|
||||
return new Couple(a/b, a%b);
|
||||
|
||||
}
|
||||
}
|
8
q2/algo/cours3/test.java
Normal file
@ -0,0 +1,8 @@
|
||||
public class test {
|
||||
public String testM(){
|
||||
return "yay";
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(testM());
|
||||
}
|
||||
}
|
21
q2/algo/cours6/Question.java
Normal file
@ -0,0 +1,21 @@
|
||||
public class Question {
|
||||
private String text;
|
||||
private String response;
|
||||
|
||||
private String user_input;
|
||||
|
||||
public Question(text, response){
|
||||
this.text = text;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public void Poser(){
|
||||
Scanner resp = new Scanner(System.in);
|
||||
System.out.println(text + ": ")
|
||||
user_input = resp.nextLine();
|
||||
}
|
||||
|
||||
public boolean Verifier(){
|
||||
return user_input == response;
|
||||
}
|
||||
}
|
18
q2/algo/cours6/Questionnaire.java
Normal file
@ -0,0 +1,18 @@
|
||||
public class Questionnaire {
|
||||
private Question[] questions;
|
||||
|
||||
public void add_question;
|
||||
|
||||
public void poser_tout(){
|
||||
for(Question q: questions){
|
||||
q.Poser();
|
||||
if(q.Verifier())
|
||||
System.out.println("Bravo");
|
||||
else
|
||||
System.out.println("Pas ouf");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
4
q2/algo/cours6/TestsQuestionnaire.java
Normal file
@ -0,0 +1,4 @@
|
||||
public class TestsQuestionnaire {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
48
q2/algo/hashmap.java
Normal file
@ -0,0 +1,48 @@
|
||||
public class hashmap implements Map{
|
||||
|
||||
public static final TAB_SIZE = 1024;
|
||||
Object[] values = new Object[TAB_SIZE];
|
||||
class tuple{ public Object key, values;
|
||||
public tuple(Object key, Object value){
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public hashmap() {
|
||||
}
|
||||
|
||||
public void put(Object key, Object value){
|
||||
int pos = key.hashCode() % values.lenght();
|
||||
if (values[pos] == null){
|
||||
values[pos] = value;
|
||||
return;
|
||||
}
|
||||
if(value[pos] instanceof ArrayList<tuple> t){
|
||||
t.add(new tuple(key, value));
|
||||
return;
|
||||
}
|
||||
Object temp = values[pos];
|
||||
values[pos] = new ArrayList<tuple>;
|
||||
value[pos].add(temp);
|
||||
value[pos].add(new tuple(key, value));
|
||||
}
|
||||
|
||||
public Object get(Object key){
|
||||
int pos = key.hashCode() % values.lenght();
|
||||
if(values[pos].equals(key)){
|
||||
return values[pos].value;
|
||||
}
|
||||
if(values[pos] instanceof ArrayList<tuple> t){
|
||||
for (v : t) {
|
||||
if (v.key.equals(key)){
|
||||
return v.value
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
18
q2/algo/tp1/Cercle.java
Normal file
@ -0,0 +1,18 @@
|
||||
public class Cercle {
|
||||
public static final double PI = 3.14159265;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i <= 50; i++) {
|
||||
System.out.println("pour un cercle de rayon : " + i + " Perimetre:" + perimetre(i)+ " aire:" + aire(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static double perimetre(double rayon){
|
||||
return 2*PI*rayon;
|
||||
}
|
||||
|
||||
public static double aire(double rayon){
|
||||
return PI*rayon*rayon;
|
||||
}
|
||||
}
|
20
q2/algo/tp1/Droites.java
Normal file
@ -0,0 +1,20 @@
|
||||
public class Droites {
|
||||
public static void main(String[] args) {
|
||||
droite(1, 1, 2, 2);
|
||||
if(appartient(-1,1, 0, 2, 2)){
|
||||
System.out.println("yay");
|
||||
}
|
||||
|
||||
}
|
||||
public static void droite(double x1, double y1, double x2, double y2){
|
||||
double dir_x = x2 - x1, dir_y = y2 - y1;
|
||||
double a = -dir_y, b = dir_x;
|
||||
double c = a*x1 + b*y1;
|
||||
System.out.println("equation de la droite: " + a + "x + " + b + "y = " + c);
|
||||
}
|
||||
|
||||
public static boolean appartient(double a, double b, double c, double x, double y){
|
||||
return a * x + b * y == c ;
|
||||
|
||||
}
|
||||
}
|
18
q2/algo/tp1/HelloWorld.java
Normal file
@ -0,0 +1,18 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
String prenom = "Anthony";
|
||||
int age = 21;
|
||||
double taille = 1.85;
|
||||
printHello(prenom, age, taille);
|
||||
|
||||
}
|
||||
|
||||
public static void printHello(String prenom, int age, double taille)
|
||||
{
|
||||
System.out.println("Hello World");
|
||||
System.out.println("Mon nom est " + prenom);
|
||||
System.out.println("J'ai " + age + "ans et je mesure " + taille + "m :)");
|
||||
}
|
||||
|
||||
|
||||
}
|
32
q2/algo/tp1/Suite.java
Normal file
@ -0,0 +1,32 @@
|
||||
public class Suite {
|
||||
public static void main(String[] args) {
|
||||
// suiteArithmetique(5, 5, 3);
|
||||
// suiteGeometrique(5, 5, 3);
|
||||
suiteFibonacci(15);
|
||||
|
||||
}
|
||||
|
||||
public static void suiteArithmetique(int depart, int raison, int k){
|
||||
for (int i = 0; i < k; i++) {
|
||||
System.out.println(depart + raison * i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void suiteGeometrique(int depart, int raison, int k){
|
||||
for (int i = 0; i < k; i++) {
|
||||
System.out.println(depart + (int)Math.pow(raison, i));
|
||||
}
|
||||
}
|
||||
|
||||
public static void suiteFibonacci(int k){
|
||||
int el1 = 1;
|
||||
int el2 = 1;
|
||||
int temp;
|
||||
for (int i = 0; i < k-2; i++) {
|
||||
temp = el1;
|
||||
el1 = el2;
|
||||
el2 = temp + el2 ;
|
||||
}
|
||||
System.out.println(el2);
|
||||
}
|
||||
}
|
BIN
q2/algo/tp1/TP01.pdf
Normal file
60
q2/algo/tp2/Droite.java
Normal file
@ -0,0 +1,60 @@
|
||||
public class Droite {
|
||||
public double a, b, c;
|
||||
|
||||
public String toString(){
|
||||
return a + "x + " + b + "y = " + c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Represent a line in the space with the equation ax + by = c
|
||||
* @param a ax
|
||||
* @param b by
|
||||
* @param c c
|
||||
*/
|
||||
Droite(double a, double b, double c){
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the line is horizontal
|
||||
* @return true if the line is horizontal
|
||||
* @return false if the line is not horizontal
|
||||
*/
|
||||
public boolean isHorizontal(){
|
||||
if(a == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the intersection by 2 lines
|
||||
* @param other the other line you should find the intersection with
|
||||
* @return Point The Point of the intersection
|
||||
* @return Null if the lines are not intersecting
|
||||
* @return Null if the lines are the sames
|
||||
*/
|
||||
public Point intersection(Droite other){
|
||||
if(a * other.b - b * other.a == 0)
|
||||
return null;
|
||||
return new Point((other.b*c - b*other.c)/(a*other.b + b * other.a), (other.c - other.a*((other.b*c - b*other.c)/(a*other.b + b * other.a)))/other.b );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new line with the two points given
|
||||
* @param p1 the first point
|
||||
* @param p2 the second point
|
||||
* @return Droite the line that is between the given points
|
||||
*/
|
||||
public static Droite create(Point p1, Point p2){
|
||||
System.out.println(p1 + "; " + p2);
|
||||
Point directeur = new Point(p2.getX() - p1.getX(), p2.getY() - p2.getY());
|
||||
System.out.println(directeur);
|
||||
double a = -directeur.getY();
|
||||
double b = directeur.getX();
|
||||
return new Droite(a, b, a*p1.getX() + b*p1.getY());
|
||||
}
|
||||
}
|
33
q2/algo/tp2/DroiteTest.java
Normal file
@ -0,0 +1,33 @@
|
||||
public class DroiteTest {
|
||||
public static void main(String[] args) {
|
||||
Point p1 = new Point(1, 1);
|
||||
Point p2 = new Point(5, 3);
|
||||
Point p3 = new Point(0, 4);
|
||||
Point p4 = new Point(4, 6);
|
||||
|
||||
Droite d1 = new Droite(0, 1, 2);
|
||||
System.out.println(d1);
|
||||
|
||||
Droite d2 = Droite.create(p1, p2);
|
||||
Droite d3 = Droite.create(p3, p4);
|
||||
System.out.println(d2);
|
||||
System.out.println(d3);
|
||||
|
||||
if(d2.isHorizontal())
|
||||
System.out.println("d2 is horizontal");
|
||||
if(d3.isHorizontal())
|
||||
System.out.println("d3 is horizontal");
|
||||
|
||||
Point int1 = d1.intersection(d2);
|
||||
if(int1 == null)
|
||||
System.out.println("d1 et d2 sont paralleles ou confondues");
|
||||
|
||||
Point int2 = d1.intersection(d3);
|
||||
if(int2 == null)
|
||||
System.out.println("d1 et d3 sont paralleles ou confondues");
|
||||
|
||||
Point int3 = d2.intersection(d3);
|
||||
if(int3 == null)
|
||||
System.out.println("d2 et d3 sont paralleles ou confondues");
|
||||
}
|
||||
}
|
26
q2/algo/tp2/Point.java
Normal file
@ -0,0 +1,26 @@
|
||||
public class Point {
|
||||
private double x, y;
|
||||
|
||||
public String toString(){
|
||||
return "("+ x+ ":" + y + ")";
|
||||
}
|
||||
|
||||
Point(){
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
Point(double x, double y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|