diff --git a/The Nook Games™.html b/The Nook Games™.html new file mode 100644 index 0000000..f8f8d32 --- /dev/null +++ b/The Nook Games™.html @@ -0,0 +1,2887 @@ + + +
1.0.2 2026-04-20 10:42 2026-04-27 10:42 submit-* (limit: 3 per week) archi-* (limit: 2 per hour) prog-104-p-05-2030-firstname.lastname
+├── The-Nook-GamesTM
+│ ├── Fundamentals
+│ │ ├── basic_tree.c
+│ │ ├── basic_tree.h
+│ │ ├── basic_tree_aux.c
+│ │ ├── expansion.c
+│ │ ├── expansion.h
+│ │ ├── expansion_aux.c
+│ │ ├── parsing.c
+│ │ ├── parsing.h
+│ │ ├── parsing_aux.c
+│ │ ├── vector_tree.c
+│ │ └── vector_tree.h
+│ └── Proficiencies
+│ ├── evaluate_rpn.c
+│ ├── evaluate_rpn.h
+│ ├── main.c
+│ ├── parse_exp.c
+│ ├── parse_exp.h
+│ ├── queue.c
+│ ├── queue.h
+│ ├── stack.c
+│ ├── stack.h
+│ └── utils.h
+├── .gitignore
+└── README
+firstname.lastname with your login. .gitignore file is mandatory. Tests folder. .gitignore file:*.a
+*.lib
+*.o
+*.obj
+*.out
+
+.idea/
+*~
+*.DotSettings.user
+queue struct. It is here to help you, don't hesitate to use it.Fundamentals/basic_tree.c basic_tree.h, containing the struct you will use along with some functions to help you in this journey in basic_tree_aux.c.struct node *insert(struct node *root, int value);
+ int main() {
+ struct node *root = insert(NULL, 0);
+ root = insert(root, 1);
+ root = insert(root, 2);
+ printf("%d, %d, %d\n", root->value, root->left->value, root->right->value); // 0, 1, 2
+}
+ NULL !void delete_leaf(struct node *root, int value);
+ int main() {
+ struct node *root = insert(NULL, 0);
+ root = insert(root, 1);
+ root = insert(root, 2);
+ delete_leaf(root, 2);
+ printf("%d, %d\n", root->value, root->left->value); // 0, 1
+}
+ struct node *delete_node(struct node *root, int value);
+ int main() {
+ struct node *root = insert(NULL, 0);
+ root = insert(root, 1);
+ root = insert(root, 2);
+ root = delete_node(root, 0);
+ printf("%d, %d\n", root->value, root->left->value); // 2, 1
+}
+ \t"), from left to right. Each line must end with a newline character ("\n").\t) and that the indentation must not appear before newlines.1
2 3void pretty_print(struct node *root);
+ int main(int argc, char *argv[]) {
+ if (argc == 1)
+ return 1;
+
+ struct node *root = NULL;
+ for (int i = 1; i < argc; i++) {
+ root = insert(root, atoi(argv[i]));
+ }
+
+ pretty_print(root);
+ return 0;
+}
+ 42sh $ ./pretty_print 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | cat -e
+1$
+2 3$
+4 5 6 7$
+8 9 10 11 12 13 14$
+42sh $
+ Fundamentals/vector_tree.c i :2 * i + 12 * i + 2vector_tree.h file, we advise you to take a look at it to better understand how it works.NULL, you must create it, set the size to two and insert the value as the root.NULL.struct vector *insert(struct vector *tree, int value);
+ int main() {
+ struct vector *tree = insert(NULL, 1);
+ tree = insert(tree, 2);
+ tree = insert(tree, 3);
+ for (size_t i = 0; i < tree->nb_elements; i++)
+ printf("%d ", tree->values[i]);
+ printf("\n"); // 1 2 3
+}
+ void delete_node(struct vector *tree, int value);
+ int main() {
+ struct vector *tree = insert(NULL, 1);
+ tree = insert(tree, 2);
+ tree = insert(tree, 3);
+ delete_node(tree, 1);
+ for (size_t i = 0; i < tree->nb_elements; i++)
+ printf("%d ", tree->values[i]);
+ printf("\n"); // 3 2
+}
+ pretty_print to display the tree with a row by line and with tabulations (\t) between nodes.1
2 3void pretty_print(struct vector *tree);
+ int main() {
+ struct vector *tree = insert(NULL, 1);
+ tree = insert(tree, 2);
+ tree = insert(tree, 3);
+ tree = insert(tree, 4);
+ tree = insert(tree, 5);
+ tree = insert(tree, 6);
+ pretty_print(tree);
+}
+ 42sh $ ./vector_pretty_print | cat -e
+1$
+2 3$
+4 5 6$
+42sh $
+ Fundamentals/parsing.c instruction[number of times it should be repeated]node_type[condition]\n[condition]” is optional and may not be here every time. But when it is present, the condition will either be a positive number or the word “left” or “right”. And when don't detect a condition, it is the same thing as having the condition being "[1]" (you will see later why).node_type is a unique character that represents an action. It can be one of the following :PRINT node typePLUS node typeMINUS node typeEMPTY node typeNULL.left and right variables as NULL, we will update them later.string.h) is very useful for this kind of work, do not hesitate to use functions like strcmp or strchr !struct node *create_node(const char *line);
+ int main() {
+ struct node *n1 = create_node("+[3]\n");
+ struct node *n2 = create_node(".\n");
+ struct node *n3 = create_node("E\n");
+ struct node *n4 = create_node("X\n");
+ printf("%d\n", n1 != NULL); // 1
+ printf("%d\n", n2 != NULL); // 1
+ printf("%d\n", n3 != NULL); // 1
+ printf("%d\n", n4 != NULL); // 0
+}
+ i, the left child is located at the line i * 2 and the right child is located at the line i * 2 + 1.NULL.struct node *parse_file(const char *filename);
+ // Given a file "example.nook" containing:
+// +[2]
+// .
+// E
+int main() {
+ struct node *root = parse_file("example.nook");
+ // root is a PLUS node with condition 2
+ // root->left is a PRINT node
+ // root->right is an EMPTY node
+ printf("%d\n", root != NULL); // 1
+}
+ node and an int value. The function will apply the operation specified by the node_type of node like so :PRINT, you will print the current value as a character (for example, printing the value 48 will print the char ‘0’).PLUS, you will increment the value by one.MINUS, you will decrement the value by one.EMPTY, nothing happensLEFT or RIGHT, you will execute the left or right child (depending on which one you find) a number of times equal to the calculated value of the current node (aka, after the current node operation).NULL, you must print the current value like with the PRINT command, but only once, even if the two children are NULL and thus, before the two children are called. Some characters don't have any representation in the terminal, so it is normal you don't see them appear. For example the number 2 won't display anything in the terminal.node is NULL or if value is strictly negative, you must return and do nothing.void execute_tree(struct node *node, int value);
+ // Given a file "hello.nook" containing:
+// +[72]
+int main() {
+ struct node *root = parse_file("hello.nook");
+ execute_tree(root, 0); // prints 'H' (ASCII 72)
+}
+ // Given a file "hello_weird.nook" containing:
+// +[2]
+// +[left] <- executes the left node 3 more times because the value is 3 after the value is updated, then executes both children
+// E
+// +[69]
+int main() {
+ struct node *root = parse_file("hello_weird.nook");
+ execute_tree(root, 0); // prints "HHHH" four times
+}
+ 0 and don't forget the newline at the end.1, else 0.42sh $ cat hello.nook
++[72]
+42sh $ ./parser hello.nook | cat -e
+H$
+42sh $ echo $?
+0
+42sh $ ./parser
+42sh $ echo $?
+1
+42sh $
+ node_type and only the node_type) associated with each instruction of your nodes.-p” or “--pretty-print” in the arguments of the binary. If any error occurs, print nothing and return 1, else 0.42sh $ cat empty.nook
+E
+E
+E
+42sh $ ./parser -p empty.nook
+E
+E E
+ Fundamentals/expansion.c expansion.h and implemented in expansion_aux.c, don’t hesitate to add your own functions or modify the given ones if they not please you.char *weird_copy(const char *input) function which takes a string as input and basically returns a copy, except for some exceptions.var1, var2, and var3 each represent different variables.var2 associated to the key var1, in this case, you can just copy this part of the line to the result.var3, let’s say that the value is toto here, and replace it by toto ($ included)."var1=var2\n
yes=$var1""var1=var2\n
yes=var2"yes will be associated with the value var2)."var1=toto\n
$var1=var1""var1=toto\n
toto=var1"var1 associated with the value toto AND the key toto associated with the value var1.NULL or if any malloc fails, you just return NULL.char *weird_copy(const char *input)
+ int main() {
+ char *result = weird_copy("a=hello\n$a\n");
+ printf("%s", result);
+ free(result);
+ return 0;
+}
+ 42sh $ ./expansion | cat -e
+a=hello$
+hello$
+42sh $
+ int main() {
+ char *result = weird_copy("a=var\ncoucou_$a\n");
+ printf("%s", result);
+ free(result);
+ return 0;
+}
+ 42sh $ ./expansion | cat -e
+a=var$
+coucou_var$
+42sh $
+ queue.c and stack.c.Proficiencies/ 3 4 + 2 *
+ (3 + 4) * 2
+ Proficiencies/parse_exp.c +-*/NULL.number number operator number operator ...
+ number
+ 3 -> 4 -> + -> 2 -> * -> NULL
+ 42 -> NULL
+ NULL
+ struct queue *parse_expression(const char *str);
+ Proficiencies/evaluate_rpn.c 00int evaluate_rpn(struct queue *queue);
+ 3 -> 4 -> + -> 2 -> * -> NULL, we get these steps :push 3
+push 4
++ -> pop 4 and 3 -> push 7
+push 2
+* -> pop 2 and 7 -> push 14
+ Proficiencies/main.c 42sh $ ./rpn "3 4 + 2 *" | cat -e
+14$
+42sh $
+ 42sh $ ./rpn "2 2 +" "minimake is coming"
+42sh $ echo $?
+1$
+42sh $
+ 1 if :0.1.0.2 ] 2026-04-23 18:30:00 expansion.c > expansion: added an example and some specifications parsing.c > binary: improved explenations parsing.c > pretty-print: improved explenations