diff --git a/01dec/compress.py b/01dec/compress.py index 6b7e7bd..59877a5 100755 --- a/01dec/compress.py +++ b/01dec/compress.py @@ -10,15 +10,15 @@ Options: --version Show Version -c Compress -d Decompress - -t Choose Compression Type + -t Choose Compression Type (currently supported: lz, rle) --in Input file --out Output file """ -def read_file(filename:str): +def read_file(filename:str) -> str: try: with open(filename) as file: - return file.readall() + return file.read() except e: print(e) @@ -32,8 +32,59 @@ def lz_compression(text:str): """ 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[''].lower() == 'lz': + if argument['-d']: + result = lz_decompression(read_file(argument[''])) + print(result) + if argument['-c']: + w_list, k_list = lz_compression(read_file(argument[''])) + save_lz('test.Ltxt', w_list, k_list) + elif argument[''].lower() == 'rle': + if argument['-d']: + result = rle_decompression(read_file(argument[''])) + print(result) + if argument['-c']: + result = rle_compression(read_file(argument[''])) + print(result) + else: + raise TypeError("choose a type between lz and rle") diff --git a/q2/cours2/Couple.class b/q2/cours2/Couple.class new file mode 100644 index 0000000..c845b3d Binary files /dev/null and b/q2/cours2/Couple.class differ diff --git a/q2/cours2/Couple.java b/q2/cours2/Couple.java new file mode 100644 index 0000000..7904d25 --- /dev/null +++ b/q2/cours2/Couple.java @@ -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; + } + +} diff --git a/q2/cours2/Division.class b/q2/cours2/Division.class new file mode 100644 index 0000000..a953c46 Binary files /dev/null and b/q2/cours2/Division.class differ diff --git a/q2/cours2/Division.java b/q2/cours2/Division.java new file mode 100644 index 0000000..d31f3e3 --- /dev/null +++ b/q2/cours2/Division.java @@ -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); + + } +} diff --git a/renforcement/dhcp-4.4.3.P1-1-x86_64.pkg.tar.zst b/renforcement/dhcp-4.4.3.P1-1-x86_64.pkg.tar.zst deleted file mode 100644 index 27d557c..0000000 Binary files a/renforcement/dhcp-4.4.3.P1-1-x86_64.pkg.tar.zst and /dev/null differ