Compare commits
No commits in common. "a4b8d55bc4e8bded140b581a08e39529943a0835" and "98eae2bd0e6a8b31a2fa7b79a7a6d47d60379126" have entirely different histories.
a4b8d55bc4
...
98eae2bd0e
6 changed files with 87 additions and 41 deletions
|
|
@ -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/10/10 17:59:41 by rparodi ### ########.fr #
|
# Updated: 2025/02/10 10:02: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:
|
||||||
@printf \
|
@echo \
|
||||||
"CompileFlags:\n" \
|
"CompileFlags:\n" \
|
||||||
" Add:\n" \
|
" Add:\n" \
|
||||||
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \
|
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \
|
||||||
|
|
|
||||||
|
|
@ -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/06/07 16:45:53 by rparodi ### ########.fr #
|
# Updated: 2025/05/02 15:21:09 by rparodi ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -53,23 +53,12 @@ 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:
|
||||||
|
|
@ -86,9 +75,6 @@ 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)
|
||||||
|
|
@ -117,7 +103,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 -g
|
debug: CPPFLAGS += -D DEBUG=1
|
||||||
debug: re
|
debug: re
|
||||||
|
|
||||||
# Footer
|
# Footer
|
||||||
|
|
@ -150,5 +136,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 run
|
.PHONY: all clean fclean re get_db clangd
|
||||||
-include ${OBJ:.o=.d}
|
-include ${OBJ:.o=.d}
|
||||||
|
|
|
||||||
|
|
@ -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/06/08 15:59:57 by rparodi ### ########.fr */
|
/* Updated: 2025/05/02 15:22:16 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -127,13 +127,9 @@ 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 {
|
||||||
|
|
@ -141,8 +137,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +188,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") {
|
||||||
|
|
@ -221,12 +215,15 @@ 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();
|
||||||
|
|
||||||
for (std::map<size_t, value>::iterator it_input = input.begin(); it_input != input.end(); it_input++) {
|
while (it_input != input.end()) {
|
||||||
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;
|
||||||
|
|
@ -258,6 +255,7 @@ void print_result(std::map<size_t, value> input, std::map<std::string, float> db
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
it_input++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/17 14:45:22 by rparodi ### ########.fr #
|
# Updated: 2025/04/27 18:52:30 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: re
|
test:
|
||||||
@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,8 +109,12 @@ test: re
|
||||||
@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
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,6 @@ 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
Normal file
61
flake.lock
generated
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue