diff --git a/jmaths/bin/main b/jmaths/bin/main index ce25a65a07bc049e448f13361d774287129c15f0..b985017ec3177668cc94ef1ecbe6dfa516c6d705 100755 Binary files a/jmaths/bin/main and b/jmaths/bin/main differ diff --git a/jmaths/include/jmath.h b/jmaths/include/jmath.h index 6304b53756f0f43bf5179a867c270a78b46c0eb0..c1a6e5c41cafa4828ba583d3aa9a57b6da909815 100644 --- a/jmaths/include/jmath.h +++ b/jmaths/include/jmath.h @@ -25,5 +25,6 @@ uint64_t GCD(uint64_t a, uint64_t b); uint64_t LCM(uint64_t a, uint64_t b); bool isPrime(uint64_t n); uint64_t fact(uint64_t n); +uint64_t fibo(uint64_t n); #endif \ No newline at end of file diff --git a/jmaths/src/jmath.c b/jmaths/src/jmath.c index dd832432cb70f67ff57f1b82b9ee06bf50b24f20..45560d843d603c11d1a3907c28479d3b6596a913 100644 --- a/jmaths/src/jmath.c +++ b/jmaths/src/jmath.c @@ -81,5 +81,16 @@ uint64_t fact(uint64_t n) return r; } +uint64_t fibo(uint64_t n) +{ + if(n > 1) + { + printf("%ld", (fibo(n -1) + fibo(n -2))); + } + else + { + return n; + } +} diff --git a/jmaths/src/main.c b/jmaths/src/main.c index e41f9e618ca3261ea4a2c874cc801fba8b5183dc..90a0ef6483d465f18d78d953f8a4357400201fed 100644 --- a/jmaths/src/main.c +++ b/jmaths/src/main.c @@ -56,6 +56,14 @@ int main() timeT = ((double)t) / CLOCKS_PER_SEC; printf("COMPUTED FACTORIAL IN %lfs\n", timeT); printf("FACT(%ld) = %ld \n", a, r); + + t = clock(); + r = fibo(b); + t = clock() - t; + timeT = ((double)t) / CLOCKS_PER_SEC; + printf("COMPUTED FIBO IN %lfs\n", timeT); + printf("FACT(%ld) = %ld \n", a, r); + return 0; } \ No newline at end of file diff --git a/tableaux_uni/Makefile b/tableaux_uni/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2a3a26302403f9b442cdc00a85e924edf18195ed --- /dev/null +++ b/tableaux_uni/Makefile @@ -0,0 +1,25 @@ +CC := gcc +CC_FLAGS := -Wall -Wextra + +BIN := bin +SRC := src +INCLUDE := include +LIB := lib +LIBRARIES := -lm #Library flags like -lm -lncurses +EXECUTABLE := main + +all: $(BIN)/$(EXECUTABLE) + +run: clean all + clear + @echo "🚀 Executing..." + ./$(BIN)/$(EXECUTABLE) + +$(BIN)/$(EXECUTABLE): $(SRC)/*.c + @echo "🚧 Building..." + $(CC) $(CC_FLAGS) -I $(INCLUDE) -L $(LIB) $^ -o $@ $(LIBRARIES) + +clean: + @echo "🧹 Clearing..." + -rm $(BIN)/* + diff --git a/tableaux_uni/bin/main b/tableaux_uni/bin/main new file mode 100755 index 0000000000000000000000000000000000000000..b6e316f2850932719f1506b91f64e01cc8826d35 Binary files /dev/null and b/tableaux_uni/bin/main differ diff --git a/tableaux_uni/include/jrandom.h b/tableaux_uni/include/jrandom.h new file mode 100644 index 0000000000000000000000000000000000000000..8b64fa040e2ed35c40f225bd4d10a539ecdfc155 --- /dev/null +++ b/tableaux_uni/include/jrandom.h @@ -0,0 +1,16 @@ +/* + * HEADER JRANDOM + * Author : Jonas S. + * Date : 12/10/2021 + ! DESCRIPTION +*/ + +#ifndef _JRANDOM_H_ +#define _JRANDOM_H_ + +// DEFINES + +// PROTOTYPE FUNCTIONS +uint64_t getRandomNumber(uint64_t highLimit, uint64_t lowLimit); + +#endif \ No newline at end of file diff --git a/tableaux_uni/include/jtableaux.h b/tableaux_uni/include/jtableaux.h new file mode 100644 index 0000000000000000000000000000000000000000..974ab81a3f0fc81f097d31ea3723c4a934bf1cfb --- /dev/null +++ b/tableaux_uni/include/jtableaux.h @@ -0,0 +1,32 @@ +/* + * HEADER TABLEAUX_UNI + * Author : Jonas S. + * Date : 12/10/2021 + ! DESCRIPTION +*/ + +#ifndef _JTABLEAUX_H_ +#define _JTABLEAUX_H_ + +// DEFINES + +// PROTOTYPE FUNCTIONS +void showTab(uint64_t *tab, uint64_t tabSize); +void fillTabRandom(uint64_t *tab, uint64_t tabSize, uint64_t min, uint64_t max); +void fillTabWithZeroes(uint64_t *tab, uint64_t tabSize); + +uint64_t getTabSmallestValue(uint64_t *tab, uint64_t tabSize); +uint64_t getTabBiggestValue(uint64_t *tab, uint64_t tabSize); +uint64_t getIndexOfTabElement(uint64_t *tab, uint64_t tabSize, uint64_t element); + +void sortTabLTH(uint64_t *tab, uint64_t tabSize); +void countOccurence(uint64_t *tab, uint64_t tabSize, uint64_t *occurences, uint64_t sizeOfTabOcc); + +double getMeanOfTab(uint64_t *tab, uint64_t tabSize); +double getVarianceOfTab(uint64_t *tab, uint64_t tabSize, double mean); +uint64_t getMedianOfTab(uint64_t *tab, uint64_t tabSize); + +void showVerticalHistoOfTab(uint64_t *tab, uint64_t tabSize); +void showHorizonalHistoOfTab(uint64_t *occurences, uint64_t tabSize); + +#endif \ No newline at end of file diff --git a/tableaux_uni/kreate.py b/tableaux_uni/kreate.py new file mode 100644 index 0000000000000000000000000000000000000000..4b4fc4bdc2b54fb6421cbeffe56fbf9d93b994d4 --- /dev/null +++ b/tableaux_uni/kreate.py @@ -0,0 +1,185 @@ +# * PROJ +# * Author: Jonas S. +# * Date: 11/07/21 +# ! OBJECTIVE +# ? CREATE A BASIC RUNNING PROJECT +# ? CREATE SIMPLE C OR HEADER FILE WITH HEADERS +# ? CREATE MAKEFILE +# ! NEED COLORAMA AND OS + + + + +import colorama +from colorama import Fore, Back + + +#HARD CODED STUFF +NAME = "Jonas S." +colorama.init() + +# ! FILE CREATION +def createFile(fileName, content): + with open(f"{fileName}", 'w', encoding = 'utf-8') as f: + f.write(content) + +def createHeaderFile(fileName): + from datetime import datetime + import os + from os import mkdir + + now = datetime.now() # current date and time + + content = ( + "/*\n" + f"\t* HEADER {fileName.upper()}\n" + f"\t* Author : {NAME}\n" + f"\t* Date : {now.strftime('%d/%m/%Y')}\n" + "\t! DESCRIPTION\n" + "*/\n\n" + f"#ifndef _{fileName.upper()}_H_\n" + f"#define _{fileName.upper()}_H_\n\n" + "// DEFINES\n\n" + "// PROTOTYPE FUNCTIONS\n\n" + "#endif" + ) + + if not os.path.exists('include'): + mkdir('include') + createFile(f"include/{fileName}.h", content) + +def createCodeFile(fileName): + from datetime import datetime + from datetime import datetime + import os + from os import mkdir + + now = datetime.now() # current date and time + + content = ( + "/*\n" + f"\t* CODE {fileName.upper()}\n" + f"\t* Author : {NAME}\n" + f"\t* Date : {now.strftime('%d/%m/%Y')}\n" + "\t! DESCRIPTION\n" + "*/\n\n" + ) + + # add basic printf if main + if fileName == "main": + content += "#include <stdio.h>\n\nint main()\n{\n\tprintf(\"ISSOU\\n\");\n\treturn 0;\n}" + + if not os.path.exists('src'): + mkdir('src') + createFile(f"src/{fileName}.c", content) + +def createMakefile(): + content = ( + "CC := gcc\n" + "CC_FLAGS := -Wall -Wextra\n\n" + + "BIN := bin\n" + "SRC := src\n" + "INCLUDE := include\n" + "LIB := lib\n" + "LIBRARIES := #Library flags like -lm -lncurses\n" + "EXECUTABLE := main\n\n" + + "all: $(BIN)/$(EXECUTABLE)\n\n" + + "run: clean all\n" + " clear\n" + " @echo \"🚀 Executing...\"\n" + " ./$(BIN)/$(EXECUTABLE)\n\n" + + "$(BIN)/$(EXECUTABLE): $(SRC)/*.c\n" + " @echo \"🚧 Building...\"\n" + " $(CC) $(CC_FLAGS) -I $(INCLUDE) -L $(LIB) $^ -o $@ $(LIBRARIES)\n\n" + + "clean:\n" + " @echo \"🧹 Clearing...\"\n" + " -rm $(BIN)/*\n\n" + + ) + createFile("Makefile", content) + +def createDirStructure(): + import os + from os import mkdir + + if not os.path.exists('bin'): + mkdir('bin') + if not os.path.exists('build'): + mkdir('build') + if not os.path.exists('include'): + mkdir('include') + if not os.path.exists('src'): + mkdir('src') + +# ! MENU CREATION +def createCompleteProject(): + # Base structure (SRC, BUILD, INCLUDE, BIN) + createDirStructure() + print(f"{Fore.GREEN}+ BASIC STRUCTURE CREATED{Fore.RESET}") + # Makefile + createMakefile() + print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}") + # Main + createCodeFile("main") + print(f"{Fore.GREEN}+ MAIN.C FILE CREATE{Fore.RESET}") + +def createCodeHeader(name): + # Code + createCodeFile(name) + print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}") + # Header + createHeaderFile(name) + print(f"{Fore.GREEN}+ HEADER FILE CREATED{Fore.RESET}") + + + +# ! MENU +def menu(): + choice = input( + "1 - COMPLETE PROJECT \n" + "2 - CODE + HEADER \n" + "3 - CODE ONLY \n" + "4 - HEADER ONLY \n" + "5 - MAKEFILE ONLY \n" + "\n" + + ) + + # PROJECT + if choice == '1': + print(f"{Fore.BLUE}FULL PROJECT IS BEING CREATED.{Fore.RESET}") + createCompleteProject() + + # CODE + HEADER + elif choice == '2': + print(f"{Fore.BLUE}A CODE AND HEADER FILE ARE BEING CREATED.{Fore.RESET}") + createCodeHeader(input("WHAT FILE NAME DO YOU WANT : ")) + + # CODE + elif choice == '3': + print(f"{Fore.BLUE}A CODE FILE IS BEING CREATED.{Fore.RESET}") + createCodeFile(input("WHAT FILE NAME DO YOU WANT : ")) + print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}") + + # HEADER + elif choice == '4': + print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.{Fore.RESET}") + createHeaderFile(input("WHAT FILE NAME DO YOU WANT : ")) + print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}") + + # MAKEFILE + elif choice == '5': + print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.") + createMakefile() + print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}") + +if __name__ == "__main__": + menu() + + + diff --git a/tableaux_uni/src/jrandom.c b/tableaux_uni/src/jrandom.c new file mode 100644 index 0000000000000000000000000000000000000000..49ec99c56d5bcdd31c1ca836f5ea02bdaf517942 --- /dev/null +++ b/tableaux_uni/src/jrandom.c @@ -0,0 +1,24 @@ +/* + * CODE JRANDOM + * Author : Jonas S. + * Date : 12/10/2021 + ! RANDOM LIB +*/ + +#include <stdlib.h> +#include <stdint.h> +#include <time.h> + +#include "../include/jrandom.h" + +/** + * @brief Returns a random number + * + * @param highLimit + * @param lowLimit + * @return uint64_t + */ +uint64_t getRandomNumber(uint64_t highLimit, uint64_t lowLimit) +{ + return (rand() % (highLimit - lowLimit + 1) + lowLimit); +} \ No newline at end of file diff --git a/tableaux_uni/src/jtableaux.c b/tableaux_uni/src/jtableaux.c new file mode 100644 index 0000000000000000000000000000000000000000..5ddf3d3a57c61eaaaecada8bab789395e96004c9 --- /dev/null +++ b/tableaux_uni/src/jtableaux.c @@ -0,0 +1,309 @@ +/* + * CODE TABLEAUX_UNI + * Author : Jonas S. + * Date : 12/10/2021 + ! Gestion de base de tableaux + ! https://malaspinas.academy/prog_seq_c_tp/tableaux_unidimensionnels/index.html +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdint.h> +#include <math.h> +#include "../include/jtableaux.h" +#include "../include/jrandom.h" + +/** + * @brief Print an array in the terminal + * + * @param tab + * @param tabSize + */ +void showTab(uint64_t *tab, uint64_t tabSize) +{ + for(uint64_t i = 0; i < tabSize; i++) + { + printf(" %ld,", tab[i]); + } + printf("\n"); +} + +/** + * @brief Fill a tab with random values + * from a min to a max value + * @param tab + * @param tabSize + * @param min + * @param max + */ +void fillTabRandom(uint64_t *tab, uint64_t tabSize, uint64_t min, uint64_t max) +{ + for(uint64_t i = 0; i < tabSize; i++) + { + tab[i] = getRandomNumber(max, min); + } +} + +/** + * @brief Get smallest value's index of an array + * + * @param tab + * @param tabSize + * @return uint64_t + */ +uint64_t getTabSmallestValue(uint64_t *tab, uint64_t tabSize) +{ + uint64_t value = tab[0]; + uint64_t index = 0; + + for (uint64_t i = 1; i < tabSize; i++) + { + if (value > tab[i]) + { + value = tab[i]; + index = i; + } + } + return index; +} + +/** + * @brief returns biggest value's index of an array + * + * @param tab + * @param tabSize + * @return uint64_t + */ +uint64_t getTabBiggestValue(uint64_t *tab, uint64_t tabSize) +{ + uint64_t value = 0; + uint64_t index = 0; + + for (uint64_t i = 1; i < tabSize; i++) + { + if (value < tab[i]) + { + value = tab[i]; + index = i; + } + } + return index; +} + +/** + * @brief Sort an array Low to High Selection + * + * @param tab + * @param tabSize + */ +void sortTabLTH(uint64_t *tab, uint64_t tabSize) +{ + uint64_t min_i; + uint64_t tmp_v; + + for (uint64_t i = 0; i < tabSize; i++) + { + tmp_v = tab[i]; + min_i = getTabSmallestValue(tab+i, tabSize-i) ; + tab[i] = tab[min_i + i]; + tab[min_i + i] = tmp_v; + } +} + +/** + * @brief Returns index of specified element in an array + * + * @param tab + * @param tabSize + * @param element + * @return uint64_t + */ +uint64_t getIndexOfTabElement(uint64_t *tab, uint64_t tabSize, uint64_t element) +{ + for(uint64_t i = 0; i < tabSize; i++) + { + if(tab[i] == element){return i;} + } + return -1; +} + +/** + * @brief Returns average value of an array + * + * @param tab + * @param tabSize + * @return double + */ +double getMeanOfTab(uint64_t *tab, uint64_t tabSize) +{ + uint64_t sum = 0; + for(uint64_t i = 0; i < tabSize; i++) + { + sum += tab[i]; + } + return (double)sum / tabSize; +} + +/** + * @brief Returns variance of an array + * + * @param tab + * @param tabSize + * @param mean + * @return double + */ +double getVarianceOfTab(uint64_t *tab, uint64_t tabSize, double mean) +{ + double var = 0; + for (uint64_t i = 0; i < tabSize; i++) + { + var += pow( (tab[i] - mean), 2); + } + return ( var / tabSize ); +} + +/** + * @brief Returns median of an array + * + * @param tab + * @param tabSize + * @return uint64_t + */ +uint64_t getMedianOfTab(uint64_t *tab, uint64_t tabSize) +{ + if( tabSize % 2 == 0 ) // pair + { + return tab[(tabSize - 1) / 2]; + } + return tab[(tabSize - 1) / 2] + tab[tabSize / 2] / 2; +} + +/** + * @brief Fill an array with occurences of numbers in inital array + * + * @param tab + * @param tabSize + * @param occurences + * @param sizeOfTabOcc + */ +void countOccurence(uint64_t *tab, uint64_t tabSize, uint64_t *occurences, uint64_t sizeOfTabOcc) +{ + fillTabWithZeroes(occurences, sizeOfTabOcc); + for(uint64_t i = 0; i < tabSize; i++) + { + occurences[tab[i]]++; + } +} + + +/** + * @brief Print a vertical histogram in terminal + * + * @param occurences + * @param tabSize + */ +void showVerticalHistoOfTab(uint64_t *occurences, uint64_t tabSize) +{ + uint64_t topValue = occurences[getTabBiggestValue(occurences, tabSize)]; + // PRINT ACTUAL BARS + for(uint64_t i = 0; i < tabSize; i++) + { + printf("%02ld | ", i); + for(uint64_t j = 0; j < occurences[i]; j++) + { + printf("* "); + } + printf("\n"); + } + + // PRINT X AXIS + printf(" └"); + for(uint64_t i = 1; i < topValue + 1; i++) + { + printf("---"); + } + + printf("\n "); + for(uint64_t i = 1; i < topValue + 1; i++) + { + printf(" %02ld", i); + } + printf("\n"); +} + +/** + * @brief Print an horizontal histogram in terminal + * + * @param occurences + * @param tabSize + */ +void showHorizonalHistoOfTab(uint64_t *occurences, uint64_t tabSize) +{ + uint64_t topValue = occurences[getTabBiggestValue(occurences, tabSize)]; + + // PRINT ACTUAL BARS + for(uint64_t i = topValue; i > 0; i--) // From topValue to 1 + { + printf("%02ld | ", i); + for(uint64_t j = 0; j < tabSize; j++) // go through whole tab + { + if( occurences[j] >= i) // High enough to be printed + { + printf("** "); + } + else{printf(" ");} + } + printf("\n"); + } + + // PRINT X AXIS + printf(" └"); + for(uint64_t i = 1; i < tabSize + 1; i++) + { + printf("---"); + } + printf("\n "); + for(uint64_t i = 1; i < tabSize + 1; i++) + { + printf(" %02ld", i); + } + printf("\n"); +} + +/** + * @brief Fill an array with zeroes + * + * @param tab + * @param tabSize + */ +void fillTabWithZeroes(uint64_t *tab, uint64_t tabSize) +{ + for(uint64_t i = 0; i < tabSize; i++) + { + tab[i] = 0; + } +} + + +/** + * @brief Get the pos where to place the element + * + * @param tab + * @param tabSize + * @return uint64_t + */ +uint64_t position(uint64_t *tab, uint64_t tabSize, uint64_t val) +{ + uint64_t currentPos = 0; + while( (currentPos < tabSize) && (val < tab[currentPos])) + { + currentPos++; + } + return c ←urrentPos; +} + +void shift(uint64_t *tab, uint64_t tabSize, uint64_t pos) +{ + +} diff --git a/tableaux_uni/src/main.c b/tableaux_uni/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..5db989908c28400dda4372cac84f2d0b54246926 --- /dev/null +++ b/tableaux_uni/src/main.c @@ -0,0 +1,73 @@ +/* + * CODE MAIN + * Author : Jonas S. + * Date : 12/10/2021 + ! DESCRIPTION +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <math.h> +#include <stdbool.h> +#include <stdint.h> + +#include "../include/jtableaux.h" + +int main() +{ + uint64_t sizeOfTab; + uint64_t frac_sizeOfTab; + + srand(time(NULL)); // Create seed + + printf("--------------------------------------------------\n"); + printf(" _ _____ _ ___ _ ___ _ _ ___ __\n"); + printf(" _ | |_ _/_\\ | _ ) | | __| /_\\| | | \\ \\/ /\n"); + printf("| || | | |/ _ \\| _ \\ |__| _| / _ \\ |_| |> <\n"); + printf(" \\__/ |_/_/ \\_\\___/____|___/_/ \\_\\___//_/\\_\\\n\n"); + printf("Jonas Stirnemann\n"); + printf("--------------------------------------------------\n"); + + // USER INPUT + printf("SIZE OF TAB : "); + scanf(" %ld", &sizeOfTab); + frac_sizeOfTab = sizeOfTab / 10 - 1; + + // FIND ELEMENT + uint64_t element; + printf("ELEMENT : "); + scanf(" %ld", &element); + + // RANDOM TAB + uint64_t tab[sizeOfTab]; + printf("\nFILLING TAB WITH RANDOM VALUES ... \n"); + fillTabRandom(tab, sizeOfTab, 0, frac_sizeOfTab); + + // SORT + printf("SORTING TAB ... \n\n"); + sortTabLTH(tab, sizeOfTab); + + printf("INDEX OF CHOSEN ELEMENT : %ld\n", getIndexOfTabElement(tab, sizeOfTab, element)); + + // GET MEAN + printf("MOYENNE : %.2lf\n", getMeanOfTab(tab, sizeOfTab)); + + // GET VARIANCE + printf("VARIANCE : %.2lf\n", getVarianceOfTab(tab, sizeOfTab, getMeanOfTab(tab, sizeOfTab))); + + // GET MEDIAN + printf("MEDIAN : %ld\n\n", getMedianOfTab(tab, sizeOfTab)); + + // SHOW HISTOS + uint64_t occurences[frac_sizeOfTab]; + countOccurence(tab, sizeOfTab, occurences, frac_sizeOfTab); + + printf("HISTO VERTICAL\n"); + showVerticalHistoOfTab(occurences, frac_sizeOfTab); + printf("\n\n"); + printf("HISTO VERTICAL\n"); + showHorizonalHistoOfTab(occurences, frac_sizeOfTab); + + return 0; +} diff --git a/tableaux_uni/stirnemann_tableauxUni.zip b/tableaux_uni/stirnemann_tableauxUni.zip new file mode 100644 index 0000000000000000000000000000000000000000..324966ea1f1164d0a2cffcf3cc6b51ac317d2f45 Binary files /dev/null and b/tableaux_uni/stirnemann_tableauxUni.zip differ