Compare commits

...

10 commits

Author SHA1 Message Date
Raphael
a4b8d55bc4
style(make): using printf for unity w/ macos & linux 2025-12-25 01:38:39 +01:00
Raphael
6246c4b7a8 style(direnv): removing the flake.lock 2025-06-08 22:14:46 +02:00
Raphael
d3f6fb1e8f fix(09/00): wrong order at each time 2025-06-08 16:04:02 +02:00
Raphael
b023d3d375 fix(09/00): fix the makefile's rule get_db 2025-06-07 16:46:09 +02:00
Raphael
7687cf1568 fix(09/01): now handling before the db 2025-06-05 19:32:28 +02:00
Raphael
c2316b6eaf build(debug/run): improuved some stuff 2025-06-05 19:31:43 +02:00
Raphael
506397a281 build(getter): adding the rules to write auto the input given by the subject 2025-06-05 18:53:21 +02:00
Raphael
5edc9a2fa4 fix(09): checking other month 2025-05-18 21:35:34 +02:00
Raphael
5cedee4736 build(09): adding run on ex01 2025-05-17 14:46:09 +02:00
Raphael
56e57dd6e3 build(09): adding run on ex02 2025-05-17 14:43:38 +02:00
6 changed files with 41 additions and 87 deletions

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2025/02/10 10:02:41 by rparodi ### ########.fr # # Updated: 2025/10/10 17:59:41 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -113,7 +113,7 @@ footer:
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
clangd: clangd:
@echo \ @printf \
"CompileFlags:\n" \ "CompileFlags:\n" \
" Add:\n" \ " Add:\n" \
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \ " - \"-std=c++98 -Wall -Wextra -Werror\"\n" \

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2025/05/02 15:21:09 by rparodi ### ########.fr # # Updated: 2025/06/07 16:45:53 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -53,12 +53,23 @@ END = \033[0m
all: header $(NAME) footer all: header $(NAME) footer
get_db: get_db:
@rm -rf ./cpp_09.tgz ./cpp_09 ./data.csv &> /dev/null @rm -rf ./cpp_09.tgz ./cpp_09 ./data.csv > /dev/null
@wget https://cdn.intra.42.fr/document/document/33121/cpp_09.tgz &> /dev/null @wget https://cdn.intra.42.fr/document/document/33121/cpp_09.tgz > /dev/null
@tar -xvf cpp_09.tgz &> /dev/null @tar -xvf cpp_09.tgz > /dev/null
@cp ./cpp_09/data.csv . &> /dev/null @cp ./cpp_09/data.csv . > /dev/null
@rm -rf ./cpp_09.tgz ./cpp_09 &> /dev/null @rm -rf ./cpp_09.tgz ./cpp_09 > /dev/null
@printf '$(GREY)Downloaded $(END)$(GREEN)data.csv$(END)\n' @printf '$(GREY)Downloaded $(END)$(GREEN)data.csv$(END)\n'
@echo "date | value" > ./input.txt
@echo "2011-01-03 | 3" >> ./input.txt
@echo "2011-01-03 | 2" >> ./input.txt
@echo "2011-01-03 | 1" >> ./input.txt
@echo "2011-01-03 | 1.2" >> ./input.txt
@echo "2011-01-09 | 1" >> ./input.txt
@echo "2012-01-11 | -1" >> ./input.txt
@echo "2001-42-42" >> ./input.txt
@echo "2012-01-11 | 1" >> ./input.txt
@echo "2012-01-11 | 2147483648" >> ./input.txt
@printf '$(GREY)Writing the example $(END)$(GREEN)input.txt$(END)\n'
# Clean (make clean) # Clean (make clean)
clean: clean:
@ -75,6 +86,9 @@ fclean: clean
# Restart (make re) # Restart (make re)
re: header fclean all re: header fclean all
run: all
@./$(NAME) ./input.txt
# Dependences for all # Dependences for all
$(NAME): $(OBJ) $(NAME): $(OBJ)
@mkdir -p $(OBJDIRNAME) @mkdir -p $(OBJDIRNAME)
@ -103,7 +117,7 @@ header:
@printf '$(GOLD) ****** $(END)\n' @printf '$(GOLD) ****** $(END)\n'
@printf '$(GREY) Made by rparodi$(END)\n\n' @printf '$(GREY) Made by rparodi$(END)\n\n'
debug: CPPFLAGS += -D DEBUG=1 debug: CPPFLAGS += -D DEBUG=1 -g
debug: re debug: re
# Footer # Footer
@ -136,5 +150,5 @@ clangd:
@printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n' @printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n'
# Phony # Phony
.PHONY: all clean fclean re get_db clangd .PHONY: all clean fclean re get_db clangd run
-include ${OBJ:.o=.d} -include ${OBJ:.o=.d}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */ /* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */
/* Updated: 2025/05/02 15:22:16 by rparodi ### ########.fr */ /* Updated: 2025/06/08 15:59:57 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -127,9 +127,13 @@ std::string check_date(std::string name, enum error_code *error_code) {
return (name); return (name);
} }
std::string day = name.substr(8, 2); std::string day = name.substr(8, 2);
if (year < "2009" || (year == "2009" && month <= "01" && day < "02")) {
*error_code = NO_DATE;
return (name);
}
if (day > "28") { if (day > "28") {
if (month == "02" && day == "29") { if (month == "02" && day == "29") {
if ((atoi(year.c_str()) % 4 == 0) && (atoi(year.c_str()) % 100 != 0 || atoi(year.c_str()) % 400 == 0)) if (!((atoi(year.c_str()) % 4 == 0) && (atoi(year.c_str()) % 100 != 0 || atoi(year.c_str()) % 400 == 0)))
*error_code = NO_DATE; *error_code = NO_DATE;
} }
else { else {
@ -137,6 +141,8 @@ std::string check_date(std::string name, enum error_code *error_code) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (month == month_30[i] && day > "30") { if (month == month_30[i] && day > "30") {
*error_code = NO_DATE; *error_code = NO_DATE;
} else if (day > "31") {
*error_code = NO_DATE;
} }
} }
} }
@ -188,7 +194,7 @@ std::map<size_t, value>parse_input(std::string name) {
std::string tmpLine; std::string tmpLine;
std::string tmpDate; std::string tmpDate;
float tmpValue = 0; float tmpValue = 0;
std::getline(file, tmpLine); std::getline(file, tmpLine);
if (tmpLine != "date | value") { if (tmpLine != "date | value") {
@ -215,15 +221,12 @@ std::map<size_t, value>parse_input(std::string name) {
} }
void print_result(std::map<size_t, value> input, std::map<std::string, float> db) { void print_result(std::map<size_t, value> input, std::map<std::string, float> db) {
std::map<size_t, value>::iterator it_input = input.begin();
std::map<std::string, float>::iterator it_db = db.begin(); std::map<std::string, float>::iterator it_db = db.begin();
while (it_input != input.end()) { for (std::map<size_t, value>::iterator it_input = input.begin(); it_input != input.end(); it_input++) {
if (it_input->second.reason == NO_ERROR) { if (it_input->second.reason == NO_ERROR) {
while (it_db != db.end() && it_input->second.date > it_db->first) while (it_db != db.end() && it_input->second.date > it_db->first) {
it_db++; it_db++;
if (it_db == db.begin()) {
it_db--;
} }
if (it_db == db.end()) { if (it_db == db.end()) {
std::cerr << CLR_MAGENTA << it_input->second.date << CLR_RED << " => no data found" << CLR_RESET << std::endl; std::cerr << CLR_MAGENTA << it_input->second.date << CLR_RED << " => no data found" << CLR_RESET << std::endl;
@ -255,7 +258,6 @@ void print_result(std::map<size_t, value> input, std::map<std::string, float> db
break; break;
} }
} }
it_input++;
} }
} }

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2025/04/27 18:52:30 by rparodi ### ########.fr # # Updated: 2025/05/17 14:45:22 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -83,7 +83,7 @@ $(OBJDIRNAME)/%.o: %.cpp
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
@$(CXX) $(CXXFLAGS) -o $@ -c $< @$(CXX) $(CXXFLAGS) -o $@ -c $<
test: test: re
@printf '$(GREY) Testing with $(END)$(GOLD)./RPN ""$(END)\n' @printf '$(GREY) Testing with $(END)$(GOLD)./RPN ""$(END)\n'
@./$(NAME) "" @./$(NAME) ""
@printf '\n' @printf '\n'
@ -109,12 +109,8 @@ test:
@valgrind ./$(NAME) "1 2 * 2 / 2 * 2 4 - +" 2> /tmp/RPN_test @valgrind ./$(NAME) "1 2 * 2 / 2 * 2 4 - +" 2> /tmp/RPN_test
@cat /tmp/RPN_test | rg --color=always "ERROR SUMMARY" -A 10 @cat /tmp/RPN_test | rg --color=always "ERROR SUMMARY" -A 10
@printf '$(GREY) Testing with $(END)$(GOLD)./RPN "(1 + 1)"$(END)\n' @printf '$(GREY) Testing with $(END)$(GOLD)./RPN "(1 + 1)"$(END)\n'
@./$(NAME) "(1 + 1)"
@printf '\n'
@printf '$(GREY) MemCheck with $(END)$(GOLD)./RPN "(1 + 1)"$(END)\n'
@valgrind ./$(NAME) "(1 + 1)" 2> /tmp/RPN_test
@cat /tmp/RPN_test | rg --color=always "ERROR SUMMARY" -A 10
run: test
# Header # Header
header: header:
@clear @clear

View file

@ -88,6 +88,9 @@ debug: re
test: debug test: debug
@./$(NAME) $(shell shuf -i 1-100000 -n 3000 | tr "\n" " ") @./$(NAME) $(shell shuf -i 1-100000 -n 3000 | tr "\n" " ")
run: re
@./$(NAME) $(shell shuf -i 1-100000 -n 3000 | tr "\n" " ")
# Header # Header
header: header:
@clear @clear

61
flake.lock generated
View file

@ -1,61 +0,0 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1746328495,
"narHash": "sha256-uKCfuDs7ZM3QpCE/jnfubTg459CnKnJG/LwqEVEdEiw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "979daf34c8cacebcd917d540070b52a3c2b9b16e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}