Commit 3a360615 authored by jonas.stirnema's avatar jonas.stirnema
Browse files

[+] Added some more exercices, probably not fonctionnal...

parent 6e44e618
......@@ -10,8 +10,6 @@
// DEFINE
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
long PPCM(unsigned long m, unsigned long n);
long PPCM_V2(unsigned long m, unsigned long n);
long PPCD(unsigned long n, unsigned long m);
......
CC := gcc
CC_FLAGS := -Wall -Wextra
BIN := bin
SRC := src
INCLUDE := include
LIB := lib
LIBRARIES := #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)/*
# * 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()
/*
* CODE MAIN
* Author : Jonas S.
* Date : 06/10/2021
! DESCRIPTION
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
// PROTO
bool checkPalindrome(char *tab);
int main()
{
char pal[] = "kayak";
if (checkPalindrome(pal))
{
printf("PAL");
return 0;
}
printf("NOT PAL");
}
bool checkPalindrome(char *tab)
{
for (uint64_t i = 0; i < strlen(tab); i++)
{
if(tab[i] != tab[i*(-1) - 1]){return false;}
}
return true;
}
\ No newline at end of file
CC := gcc
CC_FLAGS := -Wall -Wextra
BIN := bin
SRC := src
INCLUDE := include
LIB := lib
LIBRARIES := #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)/*
# * 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()
/*
* MIN TAB
* Author : Jonas S.
* Date : 06/10/2021
! FIND THE SMALLEST VALUE IN A TAB
*/
#include <stdio.h>
#include <stdint.h>
//DEFINES
#define TAB_SIZE 7
// PROTO
void tab_get_smallest_value(double *tab, uint64_t tabSize, uint64_t *index, double *value);
void tab_lth_sort(double *tab, uint64_t tabSize);
int main()
{
uint64_t index = 0;
double value = 0;
double tab[TAB_SIZE] = {-10, 2, 3, -5, 1, 6,-9};
tab_get_smallest_value(tab, TAB_SIZE, &index, &value);
printf("Value : %lf | Index : %ld\n", value, index);
tab_get_smallest_value((tab+2), TAB_SIZE-2, &index, &value);
printf("Value : %lf | Index : %ld\n", value, index);
// Print tab
for (uint64_t i = 0; i < TAB_SIZE; i++)
{
printf(" %lf |", tab[i]);
}
printf("\n");
tab_lth_sort(tab, TAB_SIZE);
// Print tab
for (uint64_t i = 0; i < TAB_SIZE; i++)
{
printf(" %lf |", tab[i]);
}
return 0;
}
void tab_get_smallest_value(double *tab, uint64_t tabSize, uint64_t *index, double *value)
{
*value = 0;
for (uint64_t i = 0; i < tabSize; i++)
{
if (*value > tab[i])
{
*value = tab[i];
*index = i;
}
}
}
void tab_lth_sort(double *tab, uint64_t tabSize)
{
uint64_t min_i;
double min_v, tmp_v;
for (uint64_t i = 0; i < tabSize; i++)
{
tab_get_smallest_value(tab+i, tabSize-i, &min_i, &min_v);
printf("DEBUG - Smallest Value : %lf | Smallest Index : %ld\n", min_v, min_i);
tmp_v = tab[i];
tab[i + min_i] = min_v;
tab[min_i] = tmp_v;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment