177 Commits

Author SHA1 Message Date
Hugo LAMY
a602b3a78c a la norme et avec le dossier fillit de robin 2019-06-04 10:09:02 +02:00
Hugo LAMY
1aa695c85a mise a la racine des sous dossiers de libt 2019-06-03 22:01:27 +02:00
Hugo LAMY
700fb91632 a la norme et sans erreur 2019-06-03 13:00:46 +02:00
Hugo LAMY
d86dc433dc jsais pas ce qui a change 2019-06-03 09:54:19 +02:00
Hugo LAMY
9aa1acafe4 synchro maison ecole 2019-06-03 09:22:29 +02:00
pia Lepetit
602ebf070d ajout de l'effacement selectif lors de l'opti, pas ouf ouf 2019-06-03 08:16:18 +02:00
Hugo LAMY
f1471562f3 makefile lance la libft aussi 2019-06-01 17:00:52 +02:00
Hugo LAMY
58490cfb56 pret a rendre 2019-06-01 16:27:26 +02:00
Hugo LAMY
214dc0dc5c tout foncioooooone 2019-06-01 16:25:29 +02:00
Manzovince
47fcd0ec91 free bonus print 2019-06-01 16:25:28 +02:00
Hugo LAMY
ee2620e540 tout foncioooooone 2019-06-01 16:23:27 +02:00
Hugo LAMY
26a9c9cbac merge a la main c pas bien 2019-06-01 16:05:47 +02:00
Hugo LAMY
d7dc746779 catastrophe merge 2019-06-01 16:00:49 +02:00
Hugo LAMY
c81b7515be clean pour merge 2019-06-01 15:58:31 +02:00
Manzovince
c007a8299a handle error correct 2019-06-01 15:53:43 +02:00
Manzovince
fd696fc499 oubli dans le main.c 2019-06-01 15:27:46 +02:00
Manzovince
bfe7658388 Merge remote-tracking branch 'origin/ralentit' 2019-06-01 15:17:58 +02:00
Hugo LAMY
5bdc944da9 dernier leaks disparu avec nouvelle fonction dans read_file 2019-06-01 15:13:08 +02:00
Manzovince
482861a3c9 Auto stash before merge of "master" and "origin/ralentit" 2019-06-01 14:54:12 +02:00
Manzovince
5d4de7718e Merge remote-tracking branch 'origin/ralentit' 2019-06-01 14:52:37 +02:00
Hugo LAMY
f29d9d8e60 a la norme et flag e enleve la limite de 26 tetri 2019-06-01 14:49:30 +02:00
Hugo LAMY
2d06dcf837 merging ralentit branch 2019-06-01 14:08:35 +02:00
Manzovince
0c48e90449 Merge branch 'ralentit' 2019-06-01 14:04:23 +02:00
Manzovince
68bac851e2 free(map) in print_binary_map - Auto stash before rebase of "origin/master" 2019-06-01 14:03:37 +02:00
Hugo LAMY
f79d3812d0 il ne reste qu'un seul leaks 2019-06-01 13:57:39 +02:00
Hugo LAMY
56ca478503 version sans erreurs de valgrind autre que trois leaks 2019-06-01 13:47:21 +02:00
Hugo LAMY
27afcbe7e9 tentative d'enlever les leaks en cours 2019-06-01 12:36:34 +02:00
Hugo LAMY
04a4fef38b les sames ne s'impriment pas avec juste le flag p mais seulement le o en plus 2019-05-29 16:36:04 +02:00
Hugo LAMY
e7e944f1ac derniere erreur de valgrind resolu mais a tester sur les mauvais tetri 2019-05-29 15:53:08 +02:00
Hugo LAMY
819a14407d derniere erreur de valgrind resolu mais a tester sur les mauvais tetri 2019-05-29 15:51:41 +02:00
Manzovince
2bc1f50b46 README edit 2019-05-29 15:44:36 +02:00
Manzovince
7a07d84d6c README and few little corrections on code readability 2019-05-29 15:42:31 +02:00
Manzovince
0236573b6d all debug comments deleted for norm 2019-05-29 13:57:37 +02:00
Manzovince
fb1a41e94f correction of handle_errors.c (1 error still not solved)
Quand on a une nl après le dernier tetrimino du fichier input, on devrait sortir une erreur au lieu de résoudre le fillit
2019-05-29 13:52:41 +02:00
Manzovince
6ca294272f .dSYM deleted 2019-05-29 13:37:34 +02:00
Manzovince
bfd23d6211 gitignore edit for libft symlink 2019-05-29 13:37:13 +02:00
Manzovince
fa5f2e7f00 new version of fillit.h with details 2019-05-29 13:36:40 +02:00
Manzovince
246906a490 all test files grouped in folder 2019-05-29 13:15:53 +02:00
Manzovince
eea8110abd correction on main.c (working for me now) 2019-05-29 13:12:31 +02:00
Manzovince
79a5fb188c correction on fillit.h 2019-05-29 13:10:21 +02:00
Manzovince
59d2be2756 Merge remote-tracking branch 'origin/master' 2019-05-29 11:35:00 +02:00
Hugo LAMY
c82ba9bccb presque toutes les erreures de vlgrind resolues, sauf une derniere dans error_proxy 2019-05-28 19:36:21 +02:00
Hugo LAMY
ed06e3eb8e corrige deux bad read or write due au depassement de la taille de map, en ajoutant total_num dans la struct 2019-05-28 17:35:34 +02:00
Manzovince
2dfe395a9b Merge remote-tracking branch 'origin/master' 2019-05-28 13:23:15 +02:00
Hugo LAMY
77656ba113 sans l'opion o opti les sames ne s'affichent pas 2019-05-28 13:05:14 +02:00
Hugo LAMY
a9e62833bb flags organises 2019-05-27 19:53:27 +02:00
Hugo LAMY
6b9936b0cd en cours de reorganisation des fichiers pour gerer les flags 2019-05-24 18:05:18 +02:00
Hugo LAMY
1a16e305d3 a une ligne pret le programme fonctionne tout le temps aaaarg 2019-05-21 15:31:04 +02:00
Hugo LAMY
1811268725 fillit ultrrrrrrra rapide ! pas encore a la norme 2019-05-20 15:58:45 +02:00
Manzovince
184981a28d Merge remote-tracking branch 'origin/master' 2019-05-20 15:52:43 +02:00
Hugo LAMY
c2e87b7303 opti fonctionne super bien et super mal 2019-05-20 15:42:30 +02:00
Manzovince
2dbd5b7320 Auto stash before merge of "master" and "origin/master" + CLEANING 2019-05-20 13:53:01 +02:00
Hugo LAMY
0912e52a7a clean les comments 2019-05-18 15:34:47 +02:00
Hugo LAMY
f4b1da414c list s'imprime dans main 2019-05-17 18:43:33 +02:00
Hugo LAMY
94c0e5d57f search_map a la norme 2019-05-17 17:13:31 +02:00
Hugo LAMY
e5aea30023 backtracking fonctionne avec list->position directement 2019-05-16 16:51:09 +02:00
Hugo LAMY
6705bf9133 version clean sans modulos et divisions pour find_place 2019-05-15 18:05:37 +02:00
Hugo LAMY
2e53b04a9a optimisation en virant modulos et divisions semble marcher, gagne 10s 2019-05-15 17:47:32 +02:00
Manzovince
a639da4ac5 New test opti, strange behavior 2019-05-13 21:48:00 +02:00
Manzovince
b9bdc14db7 New samples added + First Try Optimisation 2019-05-13 18:26:39 +02:00
Hugo LAMY
af527c6316 fonctionne mais sans optimisation 2019-05-10 20:46:02 +02:00
Hugo LAMY
aa8ec6fe66 tentative echouee d'oter les modulo et division dans le fit_in_place 2019-05-10 20:40:16 +02:00
Hugo LAMY
213eff3255 rate pour l'opti qui ralenti mais find_place divisee avec fit_in_place 2019-05-10 17:00:55 +02:00
Hugo LAMY
67cb5dea38 en cours decriture de check_others 2019-05-09 18:04:08 +02:00
Manzovince
8a62783a6b WORKING VERSION FOR 42FileChecker test. All test passed ! 2019-05-09 12:46:59 +02:00
Manzovince
1c6e41e8bf 4 new samples for testing 2019-05-09 12:45:57 +02:00
Hugo LAMY
3977a73682 resolu les deux problemes de add_remove et find_place mais bcp bcp plus lent 2019-05-08 18:45:21 +02:00
Hugo LAMY
2738a5e24b plus de decalage a gauche mais bcp plus lent 2019-05-08 18:43:34 +02:00
Hugo LAMY
1ff7abafd6 rajout d'un if dans add_remove pour resoudre la superposition des ints 2019-05-08 17:55:38 +02:00
Manzovince
4a7ad39626 new samples + map_color modified 2019-05-08 15:42:49 +02:00
Manzovince
fe191054c9 New handle_errors and cleaner print_map_with_colors 2019-05-08 08:10:09 +02:00
Hugo LAMY
d057ef941b sans les codes de debug 2019-05-06 23:29:04 +02:00
Hugo LAMY
23c9e19ea6 map resolue mais peut-etre pas la meilleur solution 2019-05-06 23:24:24 +02:00
Hugo LAMY
74ef38e23a a priori le find place ne deborde plus a droite 2019-05-06 20:26:27 +02:00
Hugo LAMY
60d1d87b76 add_remove decidement.. semble fonctionner mieux mais avec deux modulo a chaque boucles 2019-05-06 20:04:27 +02:00
Hugo LAMY
e784b96efe imprime les lettres en couleur lors du debug 2019-05-06 16:35:16 +02:00
Hugo LAMY
b85454473d imprime les lettres pendant la recursive pour debug 2019-05-06 16:28:23 +02:00
Manzovince
6558b77ef2 Edit print_color for every tetri working 2019-05-04 19:16:38 +02:00
Manzovince
7872fac59e edit in fillit.h and print.c for color map feature 2019-05-04 19:10:33 +02:00
Manzovince
c1850f3fd6 Adding new ft for printing map with colors, WORKING 2019-05-04 19:09:25 +02:00
Manzovince
fdb4c53787 map_hard ADDED 2019-05-03 19:27:22 +02:00
Manzovince
1cf791746c Bonus: Best Error Handler (more details about the error) 2019-05-03 19:13:48 +02:00
Manzovince
8d9b314781 README edit 2019-05-03 18:45:14 +02:00
Manzovince
7d0dab1e1e Auto stash before merge of "master" and "origin/master" 2019-05-03 18:44:51 +02:00
Hugo LAMY
60b970e901 affiche correctement la map avec les lettres mais la map est fausse donc erreur dans backtracking 2019-05-03 16:11:15 +02:00
Hugo LAMY
671585098f fonction print_final_map fonctionne mais backtracking bug.. 2019-05-03 16:06:11 +02:00
Hugo LAMY
bd38cd52ed letter ajoute a la struct 2019-05-03 14:25:05 +02:00
Hugo LAMY
192c2ba0ae ca semble fonctionner et c tres rapide 2019-05-02 16:45:28 +02:00
Hugo LAMY
8a49caad94 find place ne depasse plus les bords de droite et du bas 2019-05-02 00:13:11 +02:00
Hugo LAMY
05e265b3b1 la position des tetri dans la recursive est mtn garde en memoire 2019-05-01 23:46:43 +02:00
Hugo LAMY
929e070fb0 nettoyage et mise a la norme de add_remove 2019-05-01 23:22:14 +02:00
Hugo LAMY
f035f37607 this time add_remove really fucking works 2019-05-01 23:13:24 +02:00
Hugo LAMY
c8570a26f1 add_remove fonctionne vraiment cette fois 2019-05-01 22:50:46 +02:00
Manzovince
37b565f3da Ajout d'une nouvelle méthode pour les tetris et la map 2019-05-01 20:08:13 +02:00
Manzovince
2291152158 new samples 2019-05-01 20:05:44 +02:00
Hugo LAMY
527b621526 merging the clean branch with recursive working badly 2019-05-01 14:25:01 +02:00
Hugo LAMY
0e6e4a3caa merge conflict ave fillit 2019-05-01 14:23:53 +02:00
Hugo LAMY
c118eac450 debug de la recursive et add_remove qui foire certains bits 2019-05-01 14:22:18 +02:00
Hugo LAMY
646d611381 add_remove fonctionne 2019-05-01 13:49:19 +02:00
Hugo LAMY
c40da94786 add_remove fonctionne pour adding 2019-05-01 12:34:58 +02:00
Hugo LAMY
c50f971f50 continue de tenter d'ecrire le add_remove mask 2019-04-30 20:59:01 +02:00
Manzovince
7b26fc7feb adding a print_tetri function in print.c for testing 2019-04-30 19:51:28 +02:00
Manzovince
5dd491ed52 few little edits + show wrong tetri feature 2019-04-30 15:32:47 +02:00
Hugo LAMY
9639bd80e3 correction lien libft et def BUFFSIZE dans fillit.h 2019-04-30 14:25:32 +02:00
Hugo LAMY
4d4ec6d8e0 merge avec nouveau file search_map qui est la recursive et reorganisation du makefile 2019-04-30 14:21:41 +02:00
Hugo LAMY
7e2ef9e878 creer symlink de libft 2019-04-30 14:11:56 +02:00
Hugo LAMY
ef78667474 renomme fichiers en prevision de merge 2019-04-30 14:10:37 +02:00
Hugo LAMY
2363e42167 test add_remove qui ne fonctionne pas encore 2019-04-30 14:08:30 +02:00
Hugo LAMY
ed1cde6e22 modified test_right in test_big_tetri 2019-04-30 13:32:27 +02:00
Hugo LAMY
c7f7ac205c ajout du fichier print qui contient les fonctinos de print de bits 2019-04-30 13:26:10 +02:00
Hugo LAMY
0eef1b4825 libft en symlink 2019-04-30 13:20:36 +02:00
Hugo LAMY
8967fcb464 some changes to search map 2019-04-30 12:50:20 +02:00
Hugo LAMY
817528c943 makefile delete tous les fichiers .o et .swp et du genre 2019-04-28 16:49:17 +02:00
Hugo LAMY
656973ae52 ebut implementation de la recursive 2019-04-28 16:24:09 +02:00
Hugo LAMY
1dd8a9e8c8 find_place renvois la position du tetri dans la map 2019-04-28 02:24:27 +02:00
Hugo LAMY
003d2b3cbb recherche de la position du tetri dans la map fonctionne 2019-04-28 01:09:43 +02:00
Manzovince
4f212d598a main.c print_error modified 2019-04-27 16:43:43 +02:00
Manzovince
12fff81bde README edit 2019-04-27 16:38:28 +02:00
Manzovince
faae791431 2 new samples for testing feature on check_tetri_errors 2019-04-27 16:33:46 +02:00
Manzovince
3e20319691 Few edits for readability, cleaning + README edit 2019-04-27 15:16:34 +02:00
Manzovince
fa281b58ea TEST OK - WORKING - Nice job Hugo ;) ! 2019-04-27 14:58:30 +02:00
Manzovince
16f98e1a1d .h, main, Makefile and add_to_list edit for Testing 2019-04-27 14:55:50 +02:00
Manzovince
fc0530a257 test 2019-04-27 14:41:12 +02:00
Hugo LAMY
48576180a2 structure modifiee avec tailles et parsing fonctionne 2019-04-27 02:05:22 +02:00
Hugo LAMY
b5ad1209f4 add_to_list fonctionne pleinement en binaire et creer un vrai tetri reduit et ses dimensions 2019-04-27 02:01:54 +02:00
Hugo LAMY
213cf40eb4 tous les champs de t_fillist remplis 2019-04-25 18:46:52 +02:00
Hugo LAMY
c83ac7599d tous les champs de list remplis 2019-04-25 18:45:21 +02:00
Hugo LAMY
e1f4ebee2a la recherche du tetri qui rentre dans la map fonctionne avec plusieurs tailles 2019-04-25 16:29:17 +02:00
Hugo LAMY
4007f0d707 la recherche du tetri qui rentre dans la map fonctionne avec toutes les tailles de tetri 2019-04-25 16:25:26 +02:00
Hugo LAMY
51205f5c56 test_big_tetri.c mis a jour ainsi que parse_input avec le add_to_list integre 2019-04-25 15:11:26 +02:00
Hugo LAMY
ac29587a10 nettoye parse_input avec add_to_list a l'interieur 2019-04-25 15:00:32 +02:00
Hugo LAMY
23ec23f8bc boucle cherche tetra dans map et trouve quand ca fit 2019-04-25 14:46:46 +02:00
Hugo LAMY
33f74f31fc ajout de test_big_tetri.c et merge conflict 2019-04-25 13:06:34 +02:00
Hugo LAMY
c70803b01b ajout de test_big_tetri.c 2019-04-25 13:01:47 +02:00
Hugo LAMY
2364b6322a fonction pour verifier si l'emplacement est libre en cours de construction 2019-04-25 07:06:37 +02:00
Hugo LAMY
dabdd7dbef print_map fonctionne avec deux versions 2019-04-25 05:32:29 +02:00
Manzovince
2bac429596 bug resolved + few edits 2019-04-24 21:50:51 +02:00
Hugo LAMY
8da1c5bec6 rangement des fichiers tests et makefile 2019-04-24 15:47:42 +02:00
Hugo LAMY
8d9afa579d reorganise parse_input 2019-04-24 13:53:33 +02:00
Hugo LAMY
ef84335727 corrige le fill_list pour virer les zeros de debut de tetraminos 2019-04-24 13:41:42 +02:00
Hugo LAMY
c2101d3af9 conflict solved 2019-04-24 12:16:01 +02:00
Hugo LAMY
7bf76e5d41 some changes 2019-04-24 12:15:06 +02:00
Manzovince
39a59058ba Few edit + BUG on bit convertion for tetri starting at top left corner 2019-04-23 21:44:11 +02:00
Manzovince
2c9340c645 Merge remote-tracking branch 'origin/master' 2019-04-23 21:20:19 +02:00
Manzovince
0aa3026f65 Few edits + BUG found on tmp (add_to_list) with some tetriminoes 2019-04-23 21:20:07 +02:00
Manzovince
f4492e2735 Few edits + BUG found on add_to_list with some tetriminoes 2019-04-23 21:15:12 +02:00
Manzovince
21c10a5787 editing few files for readability 2019-04-23 16:17:13 +02:00
Manzovince
acf5aed90e gitignore, makefile, .h edited 2019-04-23 15:34:21 +02:00
Manzovince
9a463f3358 Merge remote-tracking branch 'origin/master' 2019-04-23 15:25:52 +02:00
Manzovince
952cc5bf22 create_square comments modified 2019-04-23 15:25:40 +02:00
Manzovince
d0de4dcb47 comments modified 2019-04-23 15:25:23 +02:00
Manzovince
b2d291603c create_square comment modified 2019-04-23 15:21:21 +02:00
Manzovince
6d093e66cc handle_errors function name modified 2019-04-23 15:19:53 +02:00
Manzovince
02159dc587 get_smallest_square edited + initialize map added (WIP) 2019-04-23 15:19:30 +02:00
Manzovince
704a47684d files cleaned (WORKING) 2019-04-22 17:12:36 +02:00
Manzovince
3f6f6f249a little mod (makefile + read_file) 2019-04-22 16:27:46 +02:00
Manzovince
b5f8e37699 Auto stash before merge of "master" and "origin/master" 2019-04-22 15:14:20 +02:00
Hugo LAMY
88b126d3f1 super mask 2019-04-22 14:40:39 +02:00
Hugo LAMY
64464522f0 test_big_map sans utiliser un compteur j pour le tableau d'int 2019-04-22 13:08:58 +02:00
Hugo LAMY
fc69b0242c fonction test_big_map fonctionne correctement 2019-04-21 13:34:51 +02:00
Hugo LAMY
41f5d6b202 ajout de test_big_map pour faire tourner une grande map sur une petite 2019-04-20 21:01:49 +02:00
Hugo LAMY
bcfe54e614 ajout de test pour faire tourner une grande map sur une petite 2019-04-20 21:00:29 +02:00
Manzovince
1422c8e046 bug resolved 2019-04-19 21:26:02 +02:00
Manzovince
61cab1af7f Merge remote-tracking branch 'origin/master' 2019-04-19 21:20:29 +02:00
Hugo LAMY
730964a817 modifie add_to_list pour fonctionner avec du binaire 2019-04-19 15:34:05 +02:00
Manzovince
cfa772677c tetri_to_bit not working but better ! 2019-04-18 16:10:35 +02:00
Manzovince
729853cea0 New function convert tetri to bits ! BUT NOT WORKING :( 2019-04-18 13:09:11 +02:00
Manzovince
15bbf591e8 Makefile cleaned (ft instead of *.c) 2019-04-18 13:08:44 +02:00
Manzovince
851622dc93 print_test ft deleted (not used anymore) 2019-04-18 11:47:42 +02:00
Hugo LAMY
041aa6c9b5 merging solve conflict 2019-04-18 10:56:55 +02:00
Hugo LAMY
4462517caf merging to push test bits 2019-04-18 10:55:16 +02:00
Manzovince
de86161fcd Comments Updated (no change in the code) 2019-04-16 16:42:19 +02:00
Manzovince
7dfe29b224 Makefile cleaned (comments deleted + all aligned) 2019-04-16 16:39:37 +02:00
Manzovince
67ec57fd3d parse_input little edit (printf() deleted) 2019-04-16 16:26:17 +02:00
Hugo LAMY
f592c3cede met le dernier element du char** a null dans add_to_list et parse 2019-04-16 16:09:09 +02:00
Hugo LAMY
e9d29e6dc1 code qui parse bien les fichiers et gere les erreurs 2019-04-16 15:55:34 +02:00
Hugo LAMY
301d2ba5fb prepare pour merge 2019-04-16 15:35:16 +02:00
217 changed files with 11646 additions and 544 deletions

Binary file not shown.

8
.gitignore vendored
View File

@@ -5,3 +5,11 @@ objs/
a\.out\.dSYM/
a\.out
*.swo
*.swp
fillit
\.DS_Store

Binary file not shown.

Binary file not shown.

View File

@@ -6,43 +6,47 @@
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
# Updated: 2019/04/16 14:05:39 by hulamy ### ########.fr #
# Updated: 2019/06/03 21:55:31 by hulamy ### ########.fr #
# #
# **************************************************************************** #
NAME = fillit
NAME = fillit
CC = gcc
OBJ_DIR = ./
HEADER = ./
CFLAGS = -I.
CFLAGS += -Wall -Wextra -Werror
SRCS = *.c
OBJS = $(SRCS:.c=.o)
LIB = fillit.h
LDFLAGS = -L./libft/
LDLIBS = -lft
CC = gcc
CFLAGS = -Wall -Werror -Wextra
SRCS = main.c \
f_bonus_opti.c \
f_bonus_print.c \
f_handle_errors.c \
f_parse_input.c \
f_print.c \
f_print_map_with_colors.c \
f_read_file.c \
f_search_map.c
RM = rm -rf
OBJS = $(SRCS:.c=.o)
all: $(NAME)
# - - - - - - - - - - - - - - - #
# RULES #
# - - - - - - - - - - - - - - - #
$(NAME):
make -C libft/
$(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS)
$(CC) -o $(NAME) $(OBJS) -L libft/ -lft
#$(CC) $(CFLAGS) -I$(HEADER) -c $(addprefix $(SRC_DIR), $(SRCS))
#$(CC) $(OBJS) -o $(NAME)
mkdir $(OBJ_DIR)
mv $(OBJS) $(OBJ_DIR)
all: $(NAME)
$(NAME): $(OBJS)
make -C ./libft/
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $(SRCS) -o $(NAME)
clean:
make -C libft/ clean
$(RM) $(OBJ_DIR)
make clean -C libft/
/bin/rm -rf $(OBJS)
fclean: clean
make -C libft/ fclean
$(RM) $(NAME)
fclean: clean
make fclean -C libft/
/bin/rm -rf $(NAME)
re: fclean all
.PHONY: all clean fclean re
re: fclean all

View File

@@ -1,20 +1,24 @@
# Fillit
**hulamy** and **vmanzoni**
Team: **hulamy** and **vmanzoni**
Le but de ce projet est dagencer les Tetriminos entre eux pour former le plus petit carré possible, sachant que ce carré peut présenter des trous quand les pièces données ne semboîtent pas parfaitement.
## To do
- [x] Check if we have a file
- [x] Read file
- [x] Check if there are errors in file
- At least 1 tetrimino or less than 26
- [x] Check if every tetrimino is valid
- 4 char * 4 lines
- 4 blocks in 1 tetrimino
- No solo block
- [x] Transform file into tetriminos
- [ ] Backtracking for smallest square
- [ ] Transform tetriminos to letters
- [ ] Print result
- [x] Backtracking for smallest square
- [x] Transform tetriminos to letters
- [x] Print result (Can be done with above step)
- [ ] Free everything (NO LEAKS)
- [ ] Optimisation
## BONUS
- [x] Best error handler (more details on why there is an error.)
- [x] Optimisation (skip when tetri with same shape was already tested on map)
- [x] Add colors to tetri when printing result map
- [x] Flag for debbuging (print every step in backtracking)
- [x] Adding flags (and password for blocking more args on moulinette)

View File

@@ -1,152 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_to_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
/* Updated: 2019/04/18 01:33:00 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
/*
** Function that fills the char **tetraminos section of the structure
** with the most little rectangle that fit the tetraminos
*/
char **fill_tetraminos(char **square, int *tab)
{
char **result;
int height;
int length;
int i;
int j;
i = 0;
height = tab[2] - tab[0] + 1;
length = tab[3] - tab[1] + 1;
if (!(result = (char**)malloc(sizeof(*result) * (height + 1))))
return (NULL);
while (i < height)
{
if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1))))
return (NULL);
result[i][length] = '\0';
i++;
}
i = -1;
while (++i < height && (j = -1))
while (++j < length)
result[i][j] = square[tab[0] + i][tab[1] + j];
return (result);
}
/*
** This function calculate the line and columns where the tetraminos
** start and end, by skipping the empty lines
**
** ! it has a little bug so far, i need to fix it
*/
void find_start_and_end(char **square, int **x)
{
int i;
x[0][0] = -1;
x[0][1] = -1;
x[0][2] = 4;
x[0][3] = 4;
i = 4;
while (x[0][0] < 4 && i == 4 && !(i = 0) && square[++(x[0][0])][0] != '#')
while (i < 4 && square[*(x[0])][i] != '#')
i++;
i = 4;
while (x[0][1] < 4 && i == 4 && !(i = 0) && square[0][++(x[0][1])] != '#')
while (i < 4 && square[i][x[0][1]] != '#')
i++;
i = -1;
while (x[0][2] >= 0 && i == -1 && (i = 3) && square[--(x[0][2])][3] != '#')
while (i >= 0 && square[x[0][2]][i] != '#')
i--;
i = -1;
while (x[0][3] >= 0 && i == -1 && (i = 3) && square[3][--(x[0][3])] != '#')
while (i >= 0 && square[i][x[0][3]] != '#')
i--;
}
/*
** this function first call find_start_and_end to find the coordinates
** of start en end of the most little rectangle that fit the tetraminos
**
** it allows it to fill the structure with the size information
** (for instance :
** "##" ".#" ".#"
** is a tatraminos of 2 by 3)
** then it fills also the area information (2 * 3 = 6)
**
** and finally it calls fill_tetraminos to fill the char **tetraminos
*/
int fill_list(char **square, t_fillist *list)
{
int *tab;
tab = (int*)malloc(sizeof(int) * 4);
find_start_and_end(square, &tab);
list->size[0] = tab[3] - tab[1] + 1;
list->size[1] = tab[2] - tab[0] + 1;
list->area = list->size[0] * list->size[1];
list->tetraminos = fill_tetraminos(square, tab);
return (1);
}
/*
** this function first checks if the structure has been created
** if not, it creates the first element, else it adds an element
** and modifies the initial pointer to link to the new first element
**
** then it calls fill_list to fill the data of the structure
*/
int add_to_list(char **square, t_fillist **list)
{
t_fillist *tmp;
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
return (0);
if (!(*list))
tmp->next = NULL;
else
tmp->next = *list;
*list = tmp;
fill_list(square, *list);
return (1);
}
/*
**int main(int ac, char **av)
**{
** static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure
** int i;
**
** if (ac > 1)
** {
** add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste
** if (ac == 9)
** add_to_list(av += 4, &list);
** while (list && (i = -1))
** {
** while (++i < list->size[1])
** printf("%s\n", list->tetraminos[i]);
** printf("\n");
** list = list->next;
** }
** }
**
** return (0);
**}
*/

100
f_bonus_opti.c Normal file
View File

@@ -0,0 +1,100 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/24 14:42:46 by hulamy #+# #+# */
/* Updated: 2019/06/03 12:51:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int check_tetri_memory(t_fillist *list, int pos)
{
t_fillist *tetri;
unsigned int mask;
tetri = list;
mask = 1 << ((pos % 32) - 1);
if (tetri->same)
{
if (!(tetri->same->memory[pos / 32] & mask))
return (tetri->same->memory[pos / 32] |= mask);
}
else
{
if (!(tetri->memory[pos / 32] & mask))
return (tetri->memory[pos / 32] |= mask);
}
return (0);
}
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b)
{
if (tetri_a->tetribit != tetri_b->tetribit)
return (0);
if (tetri_a->width != tetri_b->width)
return (0);
if (tetri_a->height != tetri_b->height)
return (0);
return (1);
}
/*
** Function that free the list->memory each time it's malloc
*/
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp)
{
while (tmp)
{
if (tmp->memory)
free(tmp->memory);
tmp = tmp->next;
}
return (list);
}
/*
** Test optimisation for not testing wrong maps when tetri are identical
*/
int check_same_tetri(t_fillist *list, int num)
{
t_fillist *curr_tetri;
t_fillist *next_tetri;
int i;
curr_tetri = clean_list_memory(list, list);
while (curr_tetri != NULL)
{
i = 0;
if (!(curr_tetri->memory =
(unsigned int *)malloc(sizeof(*curr_tetri->memory) * num)))
return (0);
while (i < num)
curr_tetri->memory[i++] = 0;
next_tetri = curr_tetri->next;
while (next_tetri != NULL)
{
if (compare_tetri(curr_tetri, next_tetri))
if (next_tetri->same == NULL)
next_tetri->same = curr_tetri;
next_tetri = next_tetri->next;
}
curr_tetri->total_num = num;
curr_tetri = curr_tetri->next;
}
return (0);
}

78
f_bonus_print.c Normal file
View File

@@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_bonus_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/27 13:46:29 by hulamy #+# #+# */
/* Updated: 2019/06/01 16:26:09 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** function that print the given tetris if flag p is present
*/
t_fillist *print_tetri(t_fillist *list)
{
unsigned int print;
t_fillist *tmp;
tmp = list;
if (list->dope[2])
{
while (tmp)
{
check_same_tetri(list, 1);
print = tmp->tetribit;
print <<= 16;
print_sized_map(&print, tmp->width, tmp->height, tmp->letter);
if (tmp->same && list->dope[1])
{
print = tmp->same->tetribit;
print <<= 16;
ft_putstr("same --> ");
ft_put_tetri_color(tmp->same->letter);
ft_putchar('\n');
}
ft_putchar('\n');
tmp = tmp->next;
}
}
return (list);
}
/*
** function that print the map in binary if flag p is present
** it returns anyway the size of the map for main to print it
*/
int print_binary_map(unsigned int *map, int size, int *dope)
{
size--;
if (dope[2])
{
ft_putendl("result in binary :");
print_sized_map(map, size, size, '#');
ft_putchar('\n');
}
free(map);
return (size);
}
/*
** function that print the flags usage
*/
int print_flags_usage(void)
{
ft_putendl("flags usage :");
ft_putendl("d : debug print (print the map during the backtracking)");
ft_putendl("o : optimisation ultra fast but with some errors still");
ft_putendl("p : print the tetri and the map in different formats");
ft_putendl("e : error msgs more precise AND no error for too much tetri\n");
return (0);
}

138
f_handle_errors.c Normal file
View File

@@ -0,0 +1,138 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_handle_errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 19:44:08 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that display error message *s on fd and exit program
*/
void print_error(char *str)
{
write(1, str, ft_strlen(str));
exit(0);
}
/*
** Function that display error message *s on fd with more informations
*/
void print_error_extended(int error, int *dope)
{
if (!dope[3])
print_error("error\n");
if (error == 1)
print_error("error: File contains char other than '.','#' and '\\n'\n");
if (error == 2)
print_error("error: File contains two tetriminos not"
"separated by a '\\n'\n");
if (error == 3)
print_error("error: File contains more than 2 '\\n' in a row\n");
if (error == 4)
print_error("error: File contains less than 1 tetrimino\n");
if (error == 5)
print_error("error: File contains more than 26 tetriminos\n");
if (error == 6)
print_error("error: Tetrimino has more or less than 4 #\n");
if (error == 7)
print_error("error: Tetrimino # are not all connected\n");
print_error("error\n");
}
/*
** Function to see if there if an error if the file
** - less than 4 lines
** - more than 104 (26 tetri) + 25 (\n) = 129 lines
** - two \n in a row
*/
void check_file_errors(char *file, int *dope)
{
int i;
int line_nbr;
i = 0;
line_nbr = 0;
while (file[i])
{
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
print_error_extended(1, dope);
else if (file[i] == '\n')
line_nbr++;
if (file[i] == '\n' && line_nbr % 5 == 0 && file[i - 1] != '\n')
print_error_extended(2, dope);
if (file[i] == '\n' && file[i + 1] != '\0' && \
file[i + 2] != '.' && file[i + 2] != '#')
print_error_extended(3, dope);
i++;
}
if (file[i - 1] == '\n')
print_error_extended(3, dope);
if (line_nbr < 3)
print_error_extended(4, dope);
if (!dope[3] && line_nbr > 129)
print_error_extended(5, dope);
}
/*
** Function that check if tetrimino square contains:
** - 4 x #
** - 12 x .
*/
int check_tetri_errors(char *tetri)
{
int i;
int htg;
int dot;
i = 0;
htg = 0;
dot = 0;
while (tetri[i])
{
if (tetri[i] == '#')
htg++;
else if (tetri[i] == '.')
dot++;
i++;
}
if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri))
return (6 + check_tetri_errors_proxy(tetri));
return (0);
}
/*
** Function that check if 4 # (tetrimino parts) are linked
*/
int check_tetri_errors_proxy(char *tetri)
{
int i;
int j;
i = 0;
j = 0;
while (tetri[i])
{
if (i < 19 && tetri[i] == '#' && tetri[i + 1] == '#')
j++;
if (i > 0 && tetri[i] == '#' && tetri[i - 1] == '#')
j++;
if (i < 15 && tetri[i] == '#' && tetri[i + 5] == '#')
j++;
if (i > 4 && tetri[i] == '#' && tetri[i - 5] == '#')
j++;
i++;
}
return ((j < 6) ? 1 : 0);
}

155
f_parse_input.c Normal file
View File

@@ -0,0 +1,155 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 13:32:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** function that transform a tab of . and # into a binary tab of int
*/
unsigned short tab_to_bin(char line[])
{
unsigned short tmp;
int i;
i = 0;
tmp = 0;
while (line[i])
{
tmp <<= 1;
if (line[i] == '\n')
i++;
if (line[i++] == '#')
tmp |= 1;
}
return (tmp);
}
/*
** Function that take a tetrimino of 4*4
** and reduce it to its right size, in binary
*/
unsigned short reduce_tetri(unsigned short tetri, int width)
{
unsigned int mask;
unsigned int tmp;
mask = ~0u << (32 - width) >> 16;
tmp = (mask & tetri);
tmp |= ((mask & tetri << 4) >> width);
tmp |= ((mask & tetri << 8) >> (2 * width));
tmp |= ((mask & tetri << 12) >> (3 * width));
return (tmp);
}
/*
** Function that transforme a tetriminos char* into a short of 16 bites
** and then fills it and its reversed into the list
**
** 1) transforme la ligne de . et # en un short de 0 et 1
** 2) cree un mask avec des 1 sur la colonne de droite (#...#...#...#...)
** 3) utilise le mask pour trouver la largeur que prend le tetriminos
** 4) deplace le tetriminos tout en haut a gauche
** (i - list->width = le nombre de colonne vide a gauche)
** 5) trouve la hauteur du tetri
** 6) fabrique la ligne pour le tetriminos de la bonne largeur
**
** list->test is used to debug the backtracking, allowing to print the
** map each time without the previous tries
*/
void fill_list(char line[], t_fillist *list)
{
unsigned int mask;
int i;
list->tetribit = tab_to_bin(line);
list->memory = 0;
mask = (1 << 15) | (1 << 11) | (1 << 7) | (1 << 3);
i = 0;
while (!(mask & list->tetribit) && i++ < 4)
mask >>= 1;
list->width = i;
while (mask & list->tetribit && ++i < 4)
mask >>= 1;
list->width = i - list->width;
list->tetribit <<= (i - list->width);
while (!(list->tetribit & (~0u << 12)))
list->tetribit <<= 4;
i = 0;
while (i < 4 && list->tetribit & (~0u << 28 >> (i * 4 + 16)))
i++;
list->height = i;
list->tetribit = reduce_tetri(list->tetribit, list->width);
list->same = NULL;
list->test = 0;
}
/*
** Function that creates the linked list and add a new structure
** linked each time needed
*/
int add_to_list(char *line, t_fillist **lst, char letter, int *dope)
{
t_fillist *tmp;
t_fillist *test;
if (!(tmp = (t_fillist*)malloc(sizeof(*tmp))))
return (0);
tmp->next = NULL;
test = *lst;
if (!test)
*lst = tmp;
else
{
while (test->next)
test = test->next;
test->next = tmp;
}
fill_list(line, tmp);
tmp->letter = letter;
tmp->dope = dope;
tmp->start = *lst;
return (1);
}
/*
** Function that parse a file and put each tetrimino in a linked list
*/
int parse_input(char *input, t_fillist **list, int *dope)
{
char tetri[20];
int i;
int j;
int letter;
int size;
i = 0;
letter = 'A';
while (input[i])
{
j = 0;
while (j < 19)
tetri[j++] = input[i++];
tetri[19] = '\0';
if (check_tetri_errors(tetri))
print_error_extended(check_tetri_errors(tetri), dope);
add_to_list(tetri, list, letter++, dope);
while (input[i] && input[i] != '.' && input[i] != '#')
i++;
}
size = search_map(*list);
return (size);
}

122
f_print.c Normal file
View File

@@ -0,0 +1,122 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 13:24:28 by hulamy #+# #+# */
/* Updated: 2019/06/01 13:56:50 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that print a map of height and width
** useful to print tetris
*/
void print_sized_map(unsigned int *tab, int width, int height, char letter)
{
int i;
unsigned int mask;
i = 0;
mask = 0;
while (i++ < width)
mask = (mask >> 1) | ((mask | 1) << 31);
i = 0;
while (i < width * height)
{
if (i && !(i % width))
ft_putchar('\n');
if (tab[i / 32] & (1 << (31 - i % 32)))
ft_put_tetri_color(letter);
else
ft_putchar('.');
ft_putchar(' ');
i++;
}
write(1, "\n", 1);
}
/*
** Print the final map with the letters
** if flag value is 0 -> print moulinette version
** if flag value is p -> print in color
*/
char *init_print_map(t_fillist *list, int size)
{
char *map;
int i;
int j;
if (!(map = (char *)malloc(sizeof(*map) * (size * size + 1))))
return (NULL);
map[size * size] = '\0';
i = -1;
while (++i < size * size)
map[i] = '.';
while (list)
{
j = 0;
i = -1;
while (++i < list->width * list->height)
{
if (i && i % list->width == 0)
j += size - list->width;
if (1 << (15 - i) & list->tetribit && list->test == 1)
map[list->position + i + j - 1] = list->letter;
}
list = list->next;
}
return (map);
}
/*
** Function that print the map with color if flag = 1
** or for moulinette if flag = 0;
*/
void print_letter_map(t_fillist *list, int size, int flag)
{
int i;
char *map;
map = init_print_map(list, size);
i = -1;
while (++i < size * size)
{
if (i && i % size == 0)
ft_putchar('\n');
if (flag == 0)
ft_putchar(map[i]);
else
{
ft_put_tetri_color(map[i]);
ft_putchar(' ');
}
}
ft_putchar('\n');
free(map);
}
/*
** Function that print the map
*/
void print_final_map(t_fillist *list, int size)
{
if (list->dope[2])
{
ft_putendl("result for humans :");
print_letter_map(list, size, 1);
ft_putchar('\n');
ft_putendl("result for moulinette :");
}
print_letter_map(list, size, 0);
if (list->dope[2])
ft_putchar('\n');
}

51
f_print_map_with_colors.c Normal file
View File

@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_map_with_colors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/03 20:27:22 by vmanzoni #+# #+# */
/* Updated: 2019/06/01 14:27:30 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void ft_putchar_color(char c, char color)
{
if (color == 'R')
write(1, RED, 5);
else if (color == 'B')
write(1, BLU, 5);
else if (color == 'G')
write(1, GRN, 5);
else if (color == 'Y')
write(1, YEL, 5);
else if (color == 'M')
write(1, MAG, 5);
else if (color == 'C')
write(1, CYN, 5);
else if (color == 'W' || !c)
write(1, RESET, 5);
ft_putchar(c);
write(1, RESET, 5);
}
void ft_put_tetri_color(char c)
{
if (c == 'A' || c == 'G' || c == 'M' || c == 'S' || c == 'Y')
ft_putchar_color(c, 'R');
else if (c == 'B' || c == 'H' || c == 'N' || c == 'T' || c == 'Z')
ft_putchar_color(c, 'B');
else if (c == 'C' || c == 'I' || c == 'O' || c == 'U')
ft_putchar_color(c, 'G');
else if (c == 'D' || c == 'J' || c == 'P' || c == 'V')
ft_putchar_color(c, 'Y');
else if (c == 'E' || c == 'K' || c == 'Q' || c == 'W')
ft_putchar_color(c, 'M');
else if (c == 'F' || c == 'L' || c == 'R' || c == 'X')
ft_putchar_color(c, 'C');
else
ft_putchar(c);
}

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 14:48:36 by vmanzoni ### ########.fr */
/* Updated: 2019/06/01 15:12:03 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,24 +18,33 @@
char *read_file(char *file)
{
char buf[BUFF_SIZE];
int fd;
int rv;
int i;
char *result;
char buf[BUFF_SIZE];
int fd;
int rv;
int i;
char *result;
if (((fd = open(file, O_RDONLY)) < 0) \
|| ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \
|| !(result = malloc(sizeof(char) * rv)))
|| !(result = malloc(sizeof(char) * rv)))
return (NULL);
buf[rv] = '\0';
i = 0;
while (buf[i])
{
buf[rv - 1] = '\0';
i = -1;
while (buf[++i])
result[i] = buf[i];
i++;
}
result[i] = '\0';
close(fd);
return (result);
}
/*
** Function that init num and size for search_map
*/
void init_num_and_size(int num, int *size, t_fillist *tmp)
{
while ((tmp = tmp->next))
num++;
while (*size * *size < num * 4)
(*size)++;
}

169
f_search_map.c Normal file
View File

@@ -0,0 +1,169 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_search_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/27 20:47:22 by hulamy #+# #+# */
/* Updated: 2019/06/03 13:00:28 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** function that look if a tretri fit in a place
*/
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int sze, int i)
{
unsigned int tmp;
unsigned int mask;
unsigned int tetri;
int n;
int r;
n = lst->num;
r = lst->rank;
i = lst->height;
tetri = lst->tetribit << 16 >> lst->width;
tmp = 0;
mask = ~0u << (32 - lst->width);
while (i--)
{
if (tmp & tetri)
return (0);
if (r >= 32 && ++n)
r -= 32;
tmp = (mask & (map[n] << r));
if (n + 1 < lst->total_num)
tmp |= (mask & (map[n + 1] >> (32 - r)));
tetri <<= lst->width;
r += sze;
}
return (!(tmp & tetri));
}
/*
** function that look for the first place in the map for a tetri
*/
int find_place(unsigned int *map, t_fillist *list, int size)
{
int limit;
int pos;
pos = list->position;
list->place = pos % size;
list->rank = pos % 32;
list->num = pos / 32;
limit = (size - list->height + 1) * size;
while (pos < limit)
{
if (list->rank >= 32 && ++list->num)
list->rank -= 32;
if (list->place > size - list->width)
{
list->place = -1;
pos += list->width - 2;
list->rank += list->width - 2;
}
else if (fit_in_place(map, list, size, 0))
return ((list->position = pos + 1));
pos++;
list->place++;
list->rank++;
}
return (0);
}
/*
** function that add or remove a tetri on the map
*/
void add_remove(unsigned int *map, t_fillist *list, int size)
{
unsigned int msk;
unsigned short tetri;
int i;
int j;
tetri = list->tetribit;
msk = ~0u << (32 - list->width);
i = (list->height - 1) * list->width;
j = (list->height - 1) * size + list->position;
while (j >= list->position)
{
map[(j - 1) / 32] ^= (msk & tetri << (16 + i)) >> (j - 1);
if ((j - 1) / 32 + 1 < list->total_num)
map[(j - 1) / 32 + 1] ^= (msk & tetri << (16 + i)) << (32 - j) << 1;
j -= size;
i -= list->width;
}
}
/*
** Function that recursively try to fill the map with the tetris
*/
int fill_map(unsigned int *map, t_fillist *list, int size)
{
if (!list)
return (1);
list->position = 0;
while (find_place(map, list, size))
{
add_remove(map, list, size);
list->test = 1;
if (list->dope[0])
{
print_letter_map(list->start, size, 1);
ft_putchar('\n');
}
if (list->dope[1])
if (check_tetri_memory(list, list->position))
if (fill_map(map, list->next, size))
return (1);
if (!list->dope[1])
if (fill_map(map, list->next, size))
return (1);
add_remove(map, list, size);
list->test = 0;
}
return (0);
}
/*
** Function that send to "fill_map" a map of a certain size
** and increment its size untill it's solved
*/
int search_map(t_fillist *list)
{
t_fillist *tmp;
unsigned int *map;
int size;
int num;
int i;
size = 2;
tmp = print_tetri(list);
init_num_and_size(1, &size, tmp);
i = 0;
while (!i)
{
num = (size * size) / 32 + 1;
if (!(map = (unsigned int *)malloc(sizeof(*map) * num)))
return (0);
check_same_tetri(list, num);
if (list->dope[2])
ft_putnbrendl(size);
while (num--)
map[num] = 0;
i = fill_map(map, list, size++);
if (!i)
free(map);
}
return (print_binary_map(map, size, list->dope));
}

BIN
fillit

Binary file not shown.

139
fillit.h
View File

@@ -6,47 +6,138 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 20:53:57 by vmanzoni ### ########.fr */
/* Updated: 2019/06/03 21:53:09 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
#include <stdlib.h>
#include <unistd.h> // for system call write
#include <fcntl.h> // for system call open
#include <string.h> // for memmove and strlen
#include <stdio.h> // for debug printf
#include <stdbool.h> // to use bool type
# include <stdlib.h>
# include <unistd.h>
# include <fcntl.h>
# include <stdbool.h>
# include "libft/libft.h"
/*
** DEFINE
*/
# define BUFF_SIZE 1024
# define RED "\x1B[31m"
# define GRN "\x1B[32m"
# define YEL "\x1B[33m"
# define BLU "\x1B[34m"
# define MAG "\x1B[35m"
# define CYN "\x1B[36m"
# define RESET "\x1B[0m"
/*
** STRUCTURE
** tetribit : tetri ecrit en binaire dans un short de 16 bits
** width : largeur du tetri
** height : hauteur du tetri
** position : memorise la position d tetri bit a bit
** place : position sur l'axe des abscisses de la map (position % size)
** rank : position de 1 a 32 dans l'int du tableau d'int (position % 32)
** num : memorise dans quel int du tableau on se trouve (position / 32)
** test :
** letter : letter of the tetrimino for printing final map
** dope : flags for details, optimisation, printing and error
** memory : positions already tested by a tetrimino in bitwise
** same : pointer to previous identical tetrimino
** next : pointer to next tetrimino
** start : pointer to first tetrimino of input file
*/
typedef struct s_fillist
typedef struct s_fillist
{
int id;
char **tetraminos;
int position[2];
int size[2];
int area;
unsigned short tetribit;
int width;
int height;
int position;
int place;
int rank;
int num;
int total_num;
int test;
char letter;
int *dope;
unsigned int *memory;
struct s_fillist *same;
struct s_fillist *next;
} t_fillist;
struct s_fillist *start;
} t_fillist;
/*
** FUNCTIONS
** bonus_opti.c
*/
int check_tetri_memory(t_fillist *list, int pos);
int compare_tetri(t_fillist *tetri_a, t_fillist *tetri_b);
t_fillist *clean_list_memory(t_fillist *list, t_fillist *tmp);
int check_same_tetri(t_fillist *list, int num);
void print_test(char *test); //DELETE BEFORE EVALUATION
char *read_file(char *file);
void print_error(char *s);
void parse_input(char *input);
int check_file_errors(char *file);
int check_tetri_errors(char *tetri);
int check_tetri_errors2(char *tetri);
int add_to_list(char **square, t_fillist **list);
/*
** bonus_print.c
*/
t_fillist *print_tetri(t_fillist *list);
int print_binary_map(unsigned int *map, int size, int *dope);
int print_flags_usage(void);
/*
** main.c
*/
int *create_dope(char *av, int mdp);
int is_mdp(int ac, char **av);
void clean_list(t_fillist *list, t_fillist *tmp);
int main(int argc, char **argv);
/*
** read_file.c
*/
char *read_file(char *file);
void init_num_and_size(int num, int *size, t_fillist *tmp);
/*
** handle_errors.c
*/
void print_error(char *s);
void print_error_extended(int error, int *dope);
void check_file_errors(char *file, int *dope);
int check_tetri_errors(char *tetri);
int check_tetri_errors_proxy(char *tetri);
/*
** parse_input.c
*/
unsigned short tab_to_bin(char line[]);
unsigned short reduce_tetri(unsigned short tetri, int width);
void fill_list(char line[], t_fillist *list);
int add_to_list(char *sqr, t_fillist **lst, char lett, int *dope);
int parse_input(char *input, t_fillist **list, int *dope);
/*
** search_map.c
*/
unsigned int fit_in_place(unsigned int *map, t_fillist *lst, int siz, int i);
int find_place(unsigned int *map, t_fillist *list, int size);
void add_remove(unsigned int *map, t_fillist *list, int size);
int fill_map(unsigned int *map, t_fillist *list, int size);
int search_map(t_fillist *list);
/*
** print.c
*/
void print_sized_map(unsigned int *tab, int wdth, int hgt, char ltr);
char *init_print_map(t_fillist *list, int size);
void print_letter_map(t_fillist *list, int size, int flag);
void print_final_map(t_fillist *list, int size);
/*
** print_map_with_colors.c
*/
void ft_putchar_color(char c, char color);
void ft_put_tetri_color(char c);
#endif

34
fillit_roduquen/Makefile Executable file
View File

@@ -0,0 +1,34 @@
CC = gcc
CFLAGS = -Wall -Wextra -Werror
NAME = fillit
SRCDIR = ./
INCLDIR = ./
SRCS = $(SRCDIR)main.c $(SRCDIR)check_square.c $(SRCDIR)check_square2.c \
$(SRCDIR)fillit.c $(SRCDIR)full_square.c $(SRCDIR)check_hole.c\
$(SRCDIR)full_square2.c $(SRCDIR)remove_square.c $(SRCDIR)utilitys.c \
$(SRCDIR)do_i_fillit.c $(SRCDIR)count_island.c \
$(SRCDIR)check_count_island.c $(SRCDIR)init.c \
$(SRCDIR)check_count_island2.c
OBJS_ = $(SRCS:.c=.o)
OBJS = $(notdir $(OBJS_))
all : $(NAME)
$(NAME) : $(SRCS)
@make $(OBJS)
@$(CC) $(CFLAGS) -I $(INCLDIR) $^ -o $@
@echo "\n\033[36mCreation :\033[0m \033[35;4m$(NAME)\033[0m\n"
%.o : %.c
@$(CC) $(CFLAGS) -c -I $(INCLDIR) $^
@echo "\033[36mCompilation :\033[0m \033[32m$*\033[0m"
clean :
@rm -rf $(OBJS)
@echo "\n\033[36mDeletion :\033[0m \033[32mObjects\033[0m\n"
fclean : clean
@rm -rf $(NAME)
@echo "\033[36mDeletion :\033[0m \033[35;4m$(NAME)\033[0m\n"
re : fclean all

View File

@@ -0,0 +1,54 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,64 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....
.###
..#.
....
....
.#..
###.
....
....
....
.#..
###.
....
..##
.##.
....
....

View File

@@ -0,0 +1,34 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....

View File

@@ -0,0 +1,44 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....
....
....
....
####
....
.##.
.##.
....
.#..
.##.
.#..
....
.#..
.#..
.##.
....

39
fillit_roduquen/TEST/test_I.txt Executable file
View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

119
fillit_roduquen/TEST/test_J.txt Executable file
View File

@@ -0,0 +1,119 @@
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_J2.txt Executable file
View File

@@ -0,0 +1,119 @@
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###

119
fillit_roduquen/TEST/test_L.txt Executable file
View File

@@ -0,0 +1,119 @@
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###

44
fillit_roduquen/TEST/test_O.txt Executable file
View File

@@ -0,0 +1,44 @@
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##

59
fillit_roduquen/TEST/test_S.txt Executable file
View File

@@ -0,0 +1,59 @@
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#

119
fillit_roduquen/TEST/test_T.txt Executable file
View File

@@ -0,0 +1,119 @@
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#

59
fillit_roduquen/TEST/test_Z.txt Executable file
View File

@@ -0,0 +1,59 @@
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

View File

@@ -0,0 +1,24 @@
..#.
###.
....
....
..##
.##.
....
....
.#..
###.
....
....
.#..
##..
.#..
....
.###
...#
....
....

View File

@@ -0,0 +1,129 @@
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....
.#..
###.
....
....

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,38 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
..##
...#
...#

View File

@@ -0,0 +1,40 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
....
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,39 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#.

View File

@@ -0,0 +1,64 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....

View File

@@ -0,0 +1,79 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....
.#..
##..
.#..
....
.#..
.#..
##..
....
...#
.###
....
....
.#..
.###
....
....
##..
.#..
.#..
....
##..
#...
#...
....
.##.
##..
....
....

View File

@@ -0,0 +1,44 @@
....
####
....
....
#...
#...
#...
#...
.#..
###.
....
....
.#..
.##.
.#..
....
.###
..#.
....
....
###.
..#.
....
....
.###
.#..
....
....
##..
##..
....
....
.#..
.#..
.##.
....

1
fillit_roduquen/auteur Executable file
View File

@@ -0,0 +1 @@
roduquen;scarpent

View File

@@ -0,0 +1,121 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:16:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square(int i, t_type *square, char nbr)
{
if (i < square->size)
{
if (i == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square2(i, square, nbr));
}
return (ft_check_square3(i, square, nbr));
}
int ft_check_square2(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - 1] == nbr
|| square->isl[i + square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square3(int i, t_type *square, char nbr)
{
if (i < square->size * (square->size - 1))
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.')
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
else
return (ft_check_square4(i, square, nbr));
}
return (ft_check_square5(i, square, nbr));
}
int ft_check_square4(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i + square->size] == nbr
|| square->isl[i - 1] == nbr || square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i + square->size] == '.')
square->isl[i + square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
int ft_check_square5(int i, t_type *square, char nbr)
{
if (i % square->size == 0)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
return (SUCCESS);
}
return (ERROR);
}
return (ft_check_square6(i, square, nbr));
}

View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:04 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:15:21 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_square6(int i, t_type *square, char nbr)
{
if ((square->isl[i + 1] == nbr && (i + 1) % square->size != 0)
|| square->isl[i - square->size] == nbr
|| square->isl[i - 1] == nbr)
{
square->isl[i] = nbr;
if (square->str[i + 1] == '.' && (i + 1) % square->size != 0)
square->isl[i + 1] = nbr;
if (square->str[i - square->size] == '.')
square->isl[i - square->size] = nbr;
if (square->str[i - 1] == '.')
square->isl[i - 1] = nbr;
return (SUCCESS);
}
return (ERROR);
}

41
fillit_roduquen/check_hole.c Executable file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_hole.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:10 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:11 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_hole(t_type *square, char tetri[], int to_test)
{
if (count_island(square, 0, tetri, to_test) > square->hole)
return (ERROR);
return (SUCCESS);
}
int i_fillit_the_power(t_type *square, char tetri[], int pos)
{
int i;
int j;
i = 0;
j = -1;
while (i < pos)
{
if (tetri[i] == tetri[pos])
j = i;
i++;
}
if (j == -1)
return (0);
i = 0;
while (square->str[i] != j + 'A')
i++;
return (i);
}

158
fillit_roduquen/check_square.c Executable file
View File

@@ -0,0 +1,158 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:12 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:14:13 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int check_square(t_type *square, char tetri, int pos)
{
if (tetri == -9
&& square->str[pos] == '.' && (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -8
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2 * square->size] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -7
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
return (check_square2(square, tetri, pos));
}
int check_square2(t_type *square, char tetri, int pos)
{
if (tetri == -6
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 2 * square->size + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -5
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == -4
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square3(square, tetri, pos));
}
int check_square3(t_type *square, char tetri, int pos)
{
if (tetri == -3
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == -2
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
if (tetri == -1
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& (pos + 3) % square->size != 0
&& pos + 3 < square->size * square->size
&& square->str[pos] == '.' && square->str[pos + 1] == '.'
&& square->str[pos + 3] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
return (check_square4(square, tetri, pos));
}
int check_square4(t_type *square, char tetri, int pos)
{
if (tetri == 0
&& (pos + 1) % square->size != 0
&& pos + square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 1 + square->size] == '.')
return (SUCCESS);
if (tetri == 1
&& pos + 3 * square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 3 * square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 2
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square5(square, tetri, pos));
}
int check_square5(t_type *square, char tetri, int pos)
{
if (tetri == 3
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 1 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size + 1] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 4
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size < square->size * square->size
&& square->str[pos + 1] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size] == '.')
return (SUCCESS);
if (tetri == 5
&& (pos + 1) % square->size != 0
&& pos + 2 * square->size + 1 < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 * square->size + 1] == '.')
return (SUCCESS);
return (check_square6(square, tetri, pos));
}

55
fillit_roduquen/check_square2.c Executable file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:15 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:26:45 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int check_square6(t_type *square, char tetri, int pos)
{
if (tetri == 6
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2] == '.')
return (SUCCESS);
if (tetri == 7
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1] == '.'
&& square->str[pos + 2] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
if (tetri == 8
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (check_square7(square, tetri, pos));
}
int check_square7(t_type *square, char tetri, int pos)
{
if (tetri == 9
&& (pos + 1) % square->size != 0 && (pos + 2) % square->size != 0
&& pos + 2 + square->size < square->size * square->size
&& square->str[pos + 2] == '.'
&& square->str[pos + 1 + square->size] == '.'
&& square->str[pos + square->size] == '.'
&& square->str[pos + 2 + square->size] == '.')
return (SUCCESS);
return (ERROR);
}

126
fillit_roduquen/count_island.c Executable file
View File

@@ -0,0 +1,126 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* count_island.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:17 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:13:25 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
#include <unistd.h>
int count_island(t_type *square, int i, char tetri[], int to_test)
{
char nbr;
ft_memset(square->isl, '.', 170);
nbr = 'a';
while (1)
{
i = 0;
while (square->str[i])
{
if (square->isl[i] == '.' && square->str[i] == '.')
break ;
i++;
}
if (square->str[i])
square->isl[i] = nbr;
else
return (count_hole(square, nbr, tetri, to_test));
full_count_island_square(square, nbr);
nbr++;
}
return (ERROR);
}
void full_count_island_square(t_type *square, char nbr)
{
int i;
int j;
i = 0;
while (i < square->size * 2)
{
j = 0;
while (square->str[j])
{
if (square->str[j] == '.' && square->isl[j] == '.')
ft_check_square(j, square, nbr);
j++;
}
i++;
}
}
int count_hole(t_type *square, char nbr, char tetri[], int to_test)
{
int i;
int nbr_hole;
int total;
total = 0;
while (nbr >= 'a')
{
i = 0;
nbr_hole = 0;
while (i < square->size * square->size)
{
if (square->isl[i] == nbr)
nbr_hole++;
i++;
}
if (nbr_hole == 4)
total += check_new_possibility(square, nbr, tetri, to_test);
else
total += nbr_hole % 4;
nbr--;
}
return (total);
}
int check_if_placing_tetri_is_possible(t_type *square, char tetri[],
int to_test, int i)
{
while (tetri[to_test] != 42)
{
if (tetri[to_test] == -9 || tetri[to_test] == -7
|| tetri[to_test] == -6 || tetri[to_test] == -4
|| tetri[to_test] == -3 || tetri[to_test] == -1
|| tetri[to_test] == 0 || tetri[to_test] == 1
|| tetri[to_test] == 3 || tetri[to_test] == 5
|| tetri[to_test] == 6 || tetri[to_test] == 7
|| tetri[to_test] == 8)
{
if (check_square(square, tetri[to_test], i) == SUCCESS)
return (0);
}
else if (tetri[to_test] == -8 || tetri[to_test] == -5
|| tetri[to_test] == -2 || tetri[to_test] == 2
|| tetri[to_test] == 4)
{
if (check_square(square, tetri[to_test], i - 1) == SUCCESS)
return (0);
}
else if (check_square(square, tetri[to_test], i - 2) == SUCCESS)
return (0);
to_test++;
}
return (4);
}
int check_new_possibility(t_type *square, char nbr, char tetri[],
int to_test)
{
int i;
i = 0;
while (square->isl[i] != nbr)
i++;
return (check_if_placing_tetri_is_possible(square, tetri, to_test, i));
}

103
fillit_roduquen/do_i_fillit.c Executable file
View File

@@ -0,0 +1,103 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_i_fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:19 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:27:29 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "fillit.h"
#include <unistd.h>
int do_i_fillit(char tetri[], int nbr)
{
int i;
t_type *square;
i = 0;
if (!(square = (t_type*)malloc(sizeof(t_type))))
return (ERROR);
while (i * i < nbr * 4)
i++;
if (!(square->str = (char*)malloc(sizeof(char) * (i * i + 1))))
return (free_error(square));
square->size = i;
full_square_hole(square, nbr);
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
return (do_i_fillit2(tetri, square));
}
int do_i_fillit2(char tetri[], t_type *square)
{
int i;
while (fillit(tetri, square) == ERROR)
{
free(square->str);
square->size++;
square->hole += square->size * 2 - 1;
if (!(square->str = (char*)malloc(sizeof(char) * (square->size
* square->size + 1))))
return (free_error(square));
i = 0;
while (i < square->size * square->size)
square->str[i++] = '.';
square->str[i] = 0;
}
free(square->str);
free(square);
return (SUCCESS);
}
int free_error(void *ptr)
{
free(ptr);
return (ERROR);
}
void print_tab(t_type *square)
{
int i;
i = 0;
while (i < square->size * square->size)
{
if (i != 0 && i % square->size == 0)
write(1, "\n", 1);
write(1, &square->str[i], 1);
i++;
}
write(1, "\n", 1);
}
void full_square_hole(t_type *square, int nbr)
{
if (nbr == 1 || nbr == 4 || nbr == 9 || nbr == 16 || nbr == 25)
square->hole = 0;
else if (nbr == 2 || nbr == 6 || nbr == 12 || nbr == 20)
square->hole = 1;
else if (nbr == 3 || nbr == 8 || nbr == 15 || nbr == 24)
square->hole = 4;
else if (nbr == 5 || nbr == 11 || nbr == 19)
square->hole = 5;
else if (nbr == 7 || nbr == 14 || nbr == 23)
square->hole = 8;
else if (nbr == 10 || nbr == 18)
square->hole = 9;
else if (nbr == 13 || nbr == 22)
square->hole = 12;
else if (nbr == 17)
square->hole = 13;
else if (nbr == 21)
square->hole = 16;
else
square->hole = 17;
}

564
fillit_roduquen/external_file.txt Executable file
View File

@@ -0,0 +1,564 @@
####
....
....
....
....
####
....
....
....
....
####
....
....
....
....
####
#...
#...
#...
#...
.#..
.#..
.#..
.#..
..#.
..#.
..#.
..#.
...#
...#
...#
...#
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
....
....
.#..
.#..
##..
....
..#.
..#.
.##.
....
...#
...#
..##
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
....
....
....
###.
..#.
....
....
.###
...#
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
....
....
##..
#...
#...
....
.##.
.#..
.#..
....
..##
..#.
..#.
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
....
....
....
#...
###.
....
....
.#..
.###
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
....
....
#...
#...
##..
....
.#..
.#..
.##.
....
..#.
..#.
..##
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
....
....
....
###.
#...
....
....
.###
.#..
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
....
....
##..
.#..
.#..
....
.##.
..#.
..#.
....
..##
...#
...#
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
....
....
....
..#.
###.
....
....
...#
.###
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
....
....
....
##..
##..
....
....
.##.
.##.
....
....
..##
..##
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
....
....
....
.##.
##..
....
....
..##
.##.
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
....
....
#...
##..
.#..
....
.#..
.##.
..#.
....
..#.
..##
...#
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
....
....
....
###.
.#..
....
....
.###
..#.
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
....
....
#...
##..
#...
....
.#..
.##.
.#..
....
..#.
..##
..#.
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
....
....
....
.#..
###.
....
....
..#.
.###
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
....
....
.#..
##..
.#..
....
..#.
.##.
..#.
....
...#
..##
...#
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
....
....
....
##..
.##.
....
....
.##.
..##
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.
....
....
.#..
##..
#...
....
..#.
.##.
.#..
....
...#
..##
..#.

127
fillit_roduquen/fillit.c Executable file
View File

@@ -0,0 +1,127 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:23 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:28:16 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int full_tetri(char tetri[], char buffer[], char bufftest[], int fd)
{
int i;
if (fd == 26)
return (FILE_ERROR);
i = ft_strstr(buffer, bufftest);
if (i == 0 || i == 21 || i == 42 || i == 63)
tetri[fd] = -1;
if (i == 84 || i == 105 || i == 126 || i == 147)
tetri[fd] = 1;
if (i == 168 || i == 189 || i == 210 || i == 231 || i == 252 || i == 273)
tetri[fd] = -8;
if (i == 294 || i == 315 || i == 336 || i == 357 || i == 378 || i == 399)
tetri[fd] = 7;
if (i == 420 || i == 441 || i == 462 || i == 483 || i == 504 || i == 525)
tetri[fd] = -7;
if (i == 546 || i == 567 || i == 588 || i == 609 || i == 630 || i == 651)
tetri[fd] = 8;
if (i == 672 || i == 693 || i == 714 || i == 735 || i == 756 || i == 777)
tetri[fd] = -6;
if (i == 798 || i == 819 || i == 840 || i == 861 || i == 882 || i == 903)
tetri[fd] = 6;
if (i == 924 || i == 945 || i == 966 || i == 987 || i == 1008 || i == 1029)
tetri[fd] = -9;
return (full_tetri2(i, tetri, fd));
}
int full_tetri2(int i, char tetri[], int fd)
{
if (i == 1050 || i == 1071 || i == 1092 || i == 1113 || i == 1134
|| i == 1155)
tetri[fd] = 9;
if (i == 1176 || i == 1197 || i == 1218 || i == 1239 || i == 1260
|| i == 1281 || i == 1302 || i == 1323 || i == 1344)
tetri[fd] = 0;
if (i == 1365 || i == 1386 || i == 1407 || i == 1428 || i == 1449
|| i == 1470)
tetri[fd] = -5;
if (i == 1491 || i == 1512 || i == 1533 || i == 1554 || i == 1575
|| i == 1596)
tetri[fd] = 5;
if (i == 1617 || i == 1638 || i == 1659 || i == 1680 || i == 1701
|| i == 1722)
tetri[fd] = 3;
if (i == 1743 || i == 1764 || i == 1785 || i == 1806 || i == 1827
|| i == 1848)
tetri[fd] = -3;
if (i == 1869 || i == 1890 || i == 1911 || i == 1932 || i == 1953
|| i == 1974)
tetri[fd] = 2;
if (i == 1995 || i == 2016 || i == 2037 || i == 2058 || i == 2079
|| i == 2100)
tetri[fd] = -2;
return (full_tetri3(i, tetri, fd));
}
int full_tetri3(int i, char tetri[], int fd)
{
if (i == 2121 || i == 2142 || i == 2163 || i == 2184 || i == 2205
|| i == 2226)
tetri[fd] = -4;
if (i == 2247 || i == 2268 || i == 2289 || i == 2310 || i == 2331
|| i == 2352)
tetri[fd] = 4;
if (tetri[fd] == 42)
return (FILE_ERROR);
return (SUCCESS);
}
int fillit(char tetri[], t_type *square)
{
int i;
int j;
i = 0;
j = 0;
while (j >= 0)
{
if (check_square(square, tetri[j], i) == SUCCESS)
{
if (fillit2(square, tetri, &j, &i) == SUCCESS)
return (SUCCESS);
}
else if (square->str[i])
i++;
else
{
j--;
if (j >= 0)
i = remove_square(square, j + 'A', tetri[j]);
}
}
return (ERROR);
}
int fillit2(t_type *square, char tetri[], int *j, int *i)
{
full_square(square, tetri[*j], *j + 'A', *i);
if (tetri[*j + 1] != 42 && check_hole(square, tetri, *j + 1) != SUCCESS)
*i = remove_square(square, *j + 'A', tetri[*j]);
else
{
*i = i_fillit_the_power(square, tetri, *j + 1);
*j += 1;
}
if (tetri[*j] == 42)
{
print_tab(square);
return (SUCCESS);
}
return (CONTINUE);
}

91
fillit_roduquen/fillit.h Executable file
View File

@@ -0,0 +1,91 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fillit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:28:32 by roduquen #+# #+# */
/* Updated: 2019/04/01 19:01:09 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FILLIT_H
# define FILLIT_H
/*
** MACROS
*/
# define SUCCESS 0
# define ERROR -1
# define READ_ERROR -2
# define OPEN_ERROR -3
# define FILE_ERROR -4
# define CONTINUE 1
# define BUFF_SIZE 2372
/*
** TYPEDEF && STRUCTURES
*/
typedef struct s_type
{
int size;
int hole;
char *str;
char isl[170];
} t_type;
/*
** PROTOTYPES
*/
int fillit(char tetri[], t_type *square);
int fillit2(t_type *square, char tetri[], int *j, int *i);
void full_square(t_type *square, char tetri, char nbr, int pos);
void full_square2(t_type *square, char tetri, char nbr, int pos);
void full_square3(t_type *square, char tetri, char nbr, int pos);
void full_square4(t_type *square, char tetri, char nbr, int pos);
void full_square5(t_type *square, char tetri, char nbr, int pos);
void full_square6(t_type *square, char tetri, char nbr, int pos);
int check_square(t_type *square, char tetri, int pos);
int check_square2(t_type *square, char tetri, int pos);
int check_square3(t_type *square, char tetri, int pos);
int check_square4(t_type *square, char tetri, int pos);
int check_square5(t_type *square, char tetri, int pos);
int check_square6(t_type *square, char tetri, int pos);
int check_square7(t_type *square, char tetri, int pos);
int remove_square(t_type *square, char nbr, char type);
int i_fillit_the_power(t_type *square, char tetri[], int pos);
int i_got_a_fillit(int check_fd);
int check_file(char bufftest[], char tetri[], char buffer[],
int fd);
int free_error(void *ptr);
int do_i_fillit(char tetri[], int nbr);
int do_i_fillit2(char tetri[], t_type *square);
void print_tab(t_type *square);
int full_tetri(char tetri[], char buffer[], char bufftest[],
int fd);
int full_tetri2(int i, char tetri[], int fd);
int full_tetri3(int i, char tetri[], int fd);
int ft_strstr(char haystack[], char needle[]);
int chose_type(char type, int ret);
int check_hole(t_type *square, char tetri[], int to_test);
void full_square_hole(t_type *square, int nbr);
int ft_check_square(int i, t_type *square, char nbr);
int ft_check_square2(int i, t_type *square, char nbr);
int ft_check_square3(int i, t_type *square, char nbr);
int ft_check_square4(int i, t_type *square, char nbr);
int ft_check_square5(int i, t_type *square, char nbr);
int ft_check_square6(int i, t_type *square, char nbr);
int count_island(t_type *square, int i, char tetri[],
int to_test);
void full_count_island_square(t_type *square, char nbr);
int count_hole(t_type *square, char nbr, char tetri[],
int to_test);
void ft_memset(void *ptr, char c, int len);
int check_new_possibility(t_type *square, char nbr,
char tetri[], int to_test);
#endif

148
fillit_roduquen/full_square.c Executable file
View File

@@ -0,0 +1,148 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:25 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:29:03 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -9)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -8)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else
full_square2(square, tetri, nbr, pos);
}
void full_square2(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -6)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -5)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == -4)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square3(square, tetri, nbr, pos);
}
void full_square3(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == -3)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == -2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else if (tetri == -1)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + 3] = nbr;
}
else
full_square4(square, tetri, nbr, pos);
}
void full_square4(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 0)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 1)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size * 2] = nbr;
square->str[pos + 3 * square->size] = nbr;
}
else if (tetri == 2)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else
full_square5(square, tetri, nbr, pos);
}
void full_square5(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 3)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 1] = nbr;
}
else if (tetri == 4)
{
square->str[pos + 1] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 2 * square->size] = nbr;
}
else if (tetri == 5)
{
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + square->size + 1] = nbr;
square->str[pos + 2 * square->size + 1] = nbr;
}
else
full_square6(square, tetri, nbr, pos);
}

38
fillit_roduquen/full_square2.c Executable file
View File

@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* full_square2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:29 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:30 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void full_square6(t_type *square, char tetri, char nbr, int pos)
{
if (tetri == 6)
{
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos] = nbr;
square->str[pos + square->size] = nbr;
}
else if (tetri == 7)
{
square->str[pos] = nbr;
square->str[pos + 1] = nbr;
square->str[pos + 2] = nbr;
square->str[pos + square->size + 2] = nbr;
}
else if (tetri == 8 || tetri == 9)
{
square->str[(tetri == 8 ? pos : pos + 2)] = nbr;
square->str[pos + square->size] = nbr;
square->str[pos + 1 + square->size] = nbr;
square->str[pos + square->size + 2] = nbr;
}
}

53
fillit_roduquen/init.c Executable file
View File

@@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:31 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:32 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <fcntl.h>
#include <unistd.h>
int i_got_a_fillit(int check_fd)
{
int fd;
char buffer[BUFF_SIZE];
char bufftest[21];
char tetri[27];
int ret;
ft_memset(bufftest, 42, 21);
ft_memset(tetri, 42, 27);
bufftest[20] = 0;
if ((fd = open("external_file.txt", O_RDONLY)) < 0)
return (OPEN_ERROR);
if (read(fd, buffer, BUFF_SIZE) <= 0)
return (READ_ERROR);
fd = 0;
while ((ret = read(check_fd, bufftest, 20)) > 0)
{
if (ret != 20 || check_file(bufftest, tetri, buffer, fd) != SUCCESS)
return (FILE_ERROR);
if (read(check_fd, bufftest, 1) > 0 && bufftest[0] != '\n')
return (FILE_ERROR);
tetri[++fd] = 42;
}
if (ret < 0 || fd == 0 || bufftest[0] == '\n')
return (FILE_ERROR);
return (do_i_fillit(tetri, fd));
}
int check_file(char bufftest[], char tetri[], char buffer[], int fd)
{
if (bufftest[0] != '.' && bufftest[0] != '#')
return (FILE_ERROR);
if (full_tetri(tetri, buffer, bufftest, fd) != SUCCESS)
return (FILE_ERROR);
return (SUCCESS);
}

42
fillit_roduquen/main.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:34 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:35 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <unistd.h>
#include <fcntl.h>
int main(int ac, char **av)
{
int fd;
if (ac != 2 || (fd = open(av[1], O_DIRECTORY | O_RDONLY)) >= 0)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
if ((fd = open(av[1], O_RDONLY)) == -1)
{
write(2, "fillit: usage : fillit [PATH/FILE]\n", 35);
return (-1);
}
else
{
if ((fd = i_got_a_fillit(fd)) < 0)
{
if (fd == FILE_ERROR || fd == ERROR)
write(1, "error\n", 6);
if (fd == OPEN_ERROR || fd == READ_ERROR)
write(2, "Something went wrong, please try again\n", 39);
}
}
return (fd);
}

46
fillit_roduquen/remove_square.c Executable file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* remove_square.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:36 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:38 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int remove_square(t_type *square, char nbr, char type)
{
int i;
int ret;
i = 0;
ret = -1;
while (square->str[i])
{
if (square->str[i] == nbr)
{
if (ret == -1)
ret = i;
square->str[i] = '.';
}
i++;
}
return (chose_type(type, ret));
}
int chose_type(char type, int ret)
{
if (type == -9 || type == -7 || type == -6 || type == -4
|| type == -3 || type == -1 || type == 0 || type == 1
|| type == 3 || type == 5 || type == 6 || type == 7
|| type == 8)
return (ret + 1);
else if (type == 9)
return (ret - 1);
else
return (ret);
}

42
fillit_roduquen/utilitys.c Executable file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilitys.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/01 17:12:39 by roduquen #+# #+# */
/* Updated: 2019/04/01 17:12:50 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_strstr(char haystack[], char needle[])
{
int i;
int j;
i = 0;
while (i < BUFF_SIZE)
{
j = 0;
while (i + j < BUFF_SIZE && needle[j] && needle[j] == haystack[i + j])
j++;
if (!needle[j])
return (i);
i++;
}
return (ERROR);
}
void ft_memset(void *ptr, char c, int len)
{
int i;
unsigned char *str;
i = 0;
str = (unsigned char*)ptr;
while (i < len)
str[i++] = c;
}

View File

@@ -1,103 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_errors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 14:41:19 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that display error message *s on fd and exit program
*/
void print_error(char *s)
{
write(2, s, strlen(s));
exit(1);
}
/*
** Function to see if there if an error if the file
** - less than 4 lines
** - more than 104 (26 tetri) + 25 (\n) = 129 lines
** - two \n in a row
*/
int check_file_errors(char *file)
{
int i;
int line_nbr;
i = 0;
line_nbr = 0;
while (file[i])
{
if (file[i] != '.' && file[i] != '#' && file[i] != '\n')
return (1);
if (file[i] == '\n')
line_nbr++;
if (file[i] == '\n' && file[i+1] != '\0' && \
file[i+2] != '.' && file[i+2] != '#')
return (1);
i++;
}
if (line_nbr < 4 || line_nbr > 129)
return (1);
return (0);
}
/*
** Function that check if tetrimino square contains:
** - 4 '#'
** - 12 '.'
*/
int check_tetri_errors(char *tetri)
{
int i;
int htg;
int dot;
i = 0;
htg = 0;
dot = 0;
while (tetri[i])
{
if (tetri[i] == '#')
htg++;
else if (tetri[i] == '.')
dot++;
i++;
}
if (htg != 4 || dot != 12 || check_tetri_errors2(tetri))
return (1);
return (0);
}
/*
** Function that check if tetrimino parts are linked
*/
int check_tetri_errors2(char *tetri)
{
int i;
i = 0;
while (tetri[i])
{
if (tetri[i] == '.' || tetri[i] == '\n')
i++;
else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#'
|| tetri[i + 5] == '#' || tetri[i - 5] == '#'))
i++;
else
return (1);
}
return (0);
}

1
libft

Submodule libft deleted from dad20d5d96

46
libft/Makefile Normal file
View File

@@ -0,0 +1,46 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: hulamy <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/06/03 21:52:28 by hulamy #+# #+# #
# Updated: 2019/06/03 21:52:33 by hulamy ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
CFLAGS = -Wall -Wextra -Werror -I.
SRCS = ft_isdigit.c ft_memccpy.c ft_putnbr.c ft_strcpy.c ft_strmapi.c ft_strsub.c \
ft_any.c ft_isprint.c ft_memchr.c ft_putnbr_fd.c ft_strdel.c ft_strmultisplit.c ft_strtrim.c \
ft_arraymap.c ft_issort.c ft_memcmp.c ft_putnbrbase.c ft_strdup.c ft_strncat.c ft_tolower.c \
ft_atoi.c ft_itoa.c ft_memcpy.c ft_putnbrendl.c ft_strequ.c ft_strncmp.c ft_toupper.c \
ft_atoibase.c ft_lstadd.c ft_memdel.c ft_putnbrendl_fd.c ft_striter.c ft_strncpy.c \
ft_bzero.c ft_lstdel.c ft_memmove.c ft_putstr.c ft_striteri.c ft_strnequ.c \
ft_convertbase.c ft_lstdelone.c ft_memset.c ft_putstr_fd.c ft_strjoin.c ft_strnew.c \
ft_foreach.c ft_lstiter.c ft_putchar.c ft_strcat.c ft_strjoinfree.c ft_strnstr.c \
ft_isalnum.c ft_lstmap.c ft_putchar_fd.c ft_strchr.c ft_strlcat.c ft_strrchr.c \
ft_isalpha.c ft_lstnew.c ft_putendl.c ft_strclr.c ft_strlen.c ft_strsplit.c \
ft_isascii.c ft_memalloc.c ft_putendl_fd.c ft_strcmp.c ft_strmap.c ft_strstr.c
OBJS = $(SRCS:.c=.o)
all: $(NAME)
$(NAME): $(SRCS)
@gcc $(CFLAGS) -c $(SRCS)
@ar -rc $(NAME) $(OBJS)
@ranlib $(NAME)
clean:
@/bin/rm -f $(OBJS)
fclean: clean
@/bin/rm -f $(NAME)
re: fclean all

26
libft/ft_any.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_any.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_any(char **tab, int (*f)(char*))
{
int i;
i = -1;
if (!tab)
return (0);
while (tab[++i])
if (f(tab[i]) == 1)
return (1);
return (0);
}

28
libft/ft_arraymap.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arraymap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int *ft_arraymap(int *tab, int length, int (*f)(int))
{
int i;
int *newtab;
i = -1;
if (!tab)
return (NULL);
if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1))))
return (NULL);
while (++i < length)
newtab[i] = (*f)(tab[i]);
return (newtab);
}

39
libft/ft_atoi.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:04 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:38:12 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long long nbr;
int i;
int n;
i = 0;
n = 1;
nbr = 0;
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '-')
n = -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
if ((nbr >= 922337203685477580
&& ((str[i] > 8 && n < 0) || (str[i] > 7 && n > 0))))
return ((n > 0) ? -1 : 0);
else
nbr = nbr * 10 + (str[i++] - '0');
}
return (nbr * n);
}

75
libft/ft_atoibase.c Normal file
View File

@@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoibase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_valid_base(char *base, int i, int j)
{
while (base[i])
{
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (0);
j++;
}
if (base[i] == '-' || base[i] == '+')
return (0);
i++;
}
if (i >= 2)
return (1);
return (0);
}
static int skip(int i, char *str, int *n)
{
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
i++;
if (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
*n = -1;
i++;
}
return (i);
}
int ft_atoibase(char *str, char *base)
{
int i;
int j;
int length;
int res;
int n;
length = 0;
res = 0;
n = 1;
if (!is_valid_base(base, 0, 0))
return (0);
while (base[length])
length++;
i = skip(0, str, &n);
while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+')
{
j = 0;
while (str[i] != base[j] && base[j])
j++;
if (base[j] == '\0')
return (0);
res = (res * length) + j;
i++;
}
return (res * n);
}

27
libft/ft_bzero.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:19 by hulamy #+# #+# */
/* Updated: 2018/11/15 21:43:05 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
size_t i;
unsigned char *ptr;
if (n)
{
ptr = (unsigned char *)s;
i = 0;
while (i < n)
ptr[i++] = '\0';
}
}

86
libft/ft_convertbase.c Normal file
View File

@@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_convertbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:15:55 by hulamy #+# #+# */
/* Updated: 2019/04/17 17:09:35 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_malloc_size(int decimal, int length, int i)
{
if (decimal <= 0)
i++;
while (decimal)
{
decimal /= length;
i++;
}
return (i);
}
static char *ft_decimal_to_base(int decimal, char *base, char *res, int size)
{
long nb;
int i;
nb = decimal;
i = 0;
while (base[i])
i++;
if (nb < 0)
nb = -nb;
while (--size >= 0)
{
res[size] = base[nb % i];
nb /= i;
}
return (res);
}
static int ft_base_to_decimal(char *nbr, char *base, int length, int i)
{
long decimal;
int j;
decimal = 0;
if (nbr[i] == '-')
i++;
while (nbr[i])
{
j = 0;
while (nbr[i] != base[j] && base[j])
j++;
decimal = (decimal * length) + j;
i++;
}
if (nbr[0] == '-')
decimal = -decimal;
return (decimal);
}
char *ft_convertbase(char *nbr, char *base_from, char *base_to)
{
int length;
int size;
int decimal;
char *res;
res = 0;
length = 0;
while (base_from[length])
length++;
decimal = ft_base_to_decimal(nbr, base_from, length, 0);
length = 0;
while (base_to[length])
length++;
size = ft_malloc_size(decimal, length, 0);
res = (char *)malloc(sizeof(char) * (size + 1));
res[size] = '\0';
return (ft_decimal_to_base(decimal, base_to, res, size));
}

22
libft/ft_foreach.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_foreach.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_foreach(int *tab, int length, void (*f)(int))
{
int i;
i = 0;
while (i < length && tab && tab[i])
(*f)(tab[i++]);
}

18
libft/ft_isalnum.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:33 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:37 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isalpha(c) || ft_isdigit(c));
}

18
libft/ft_isalpha.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:44 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}

18
libft/ft_isascii.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:09:53 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:09:55 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
return (c >= 0 && c <= 127);
}

18
libft/ft_isdigit.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:01 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:10:05 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
return (c >= '0' && c <= '9');
}

18
libft/ft_isprint.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:19 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:10:20 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
return (c >= 32 && c < 127);
}

26
libft/ft_issort.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_issort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_issort(int *tab, int length, int (*f)(int, int))
{
int i;
i = -1;
if (!tab)
return (0);
while (++i < length - 1)
if (f(tab[i], tab[i + 1]) > 0)
return (0);
return (1);
}

35
libft/ft_itoa.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:25 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:36:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *str;
int len;
long int nbis;
len = (n < 0) ? 2 : 1;
nbis = n;
while (nbis /= 10)
len++;
nbis = n;
nbis *= (nbis < 0) ? -1 : 1;
if (!(str = ft_strnew(len)))
return (NULL);
str[--len] = nbis % 10 + '0';
while (nbis /= 10)
str[--len] = nbis % 10 + '0';
if (n < 0)
str[0] = '-';
return (str);
}

19
libft/ft_lstadd.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:33 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:58:54 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd(t_list **alst, t_list *new)
{
new->next = *alst;
*alst = new;
}

20
libft/ft_lstdel.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:49 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:59:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
if ((*alst)->next)
ft_lstdel(&(*alst)->next, del);
ft_lstdelone(alst, del);
}

20
libft/ft_lstdelone.c Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:59 by hulamy #+# #+# */
/* Updated: 2018/11/16 13:59:22 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
{
del((*alst)->content, (*alst)->content_size);
free(*alst);
*alst = NULL;
}

22
libft/ft_lstiter.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:14 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
{
if (!lst)
return ;
if (lst->next)
ft_lstiter(lst->next, f);
f(lst);
}

35
libft/ft_lstmap.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:20 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:23 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *new;
t_list *tmp;
if (!lst)
return (NULL);
tmp = f(lst);
new = tmp;
while (lst->next)
{
lst = lst->next;
if (!(tmp->next = f(lst)))
{
free(tmp->next);
return (NULL);
}
tmp = tmp->next;
}
return (new);
}

35
libft/ft_lstnew.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:42 by hulamy #+# #+# */
/* Updated: 2018/11/16 14:01:36 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void const *content, size_t content_size)
{
t_list *lst;
if (!(lst = (t_list *)malloc(sizeof(*lst))))
return (NULL);
if (!content)
{
lst->content = NULL;
lst->content_size = 0;
}
else
{
if (!(lst->content = malloc(content_size)))
return (NULL);
ft_memcpy(lst->content, content, content_size);
lst->content_size = content_size;
}
lst->next = NULL;
return (lst);
}

27
libft/ft_memalloc.c Normal file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memalloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:11:58 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:42:06 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** allocate size byte of memory and return a pointer to the allocated memory
*/
#include "libft.h"
void *ft_memalloc(size_t size)
{
void *tmp;
if (!(tmp = malloc(size)))
return (NULL);
ft_bzero(tmp, size);
return (tmp);
}

36
libft/ft_memccpy.c Normal file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:12:10 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:42:41 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy string until character is found and place cursor in dst
** after last byte copied
*/
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
unsigned char *dest;
unsigned char *sourc;
size_t i;
i = -1;
dest = (unsigned char *)dst;
sourc = (unsigned char *)src;
while (++i < n)
{
dest[i] = sourc[i];
if (sourc[i] == (unsigned char)c)
return (dst + i + 1);
}
return (NULL);
}

30
libft/ft_memchr.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:12:32 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:14 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** locate character in string and return its position
*/
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *sbis;
size_t i;
sbis = (unsigned char *)s;
i = -1;
while (++i < n)
if (sbis[i] == (unsigned char)c)
return ((void *)sbis + i);
return (NULL);
}

32
libft/ft_memcmp.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:04 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:41 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** compare two bytes strings (doesnt recognize a null terminated string)
** and return value of difference between first two different character
*/
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *frst;
unsigned char *scnd;
size_t i;
i = 0;
frst = (unsigned char *)s1;
scnd = (unsigned char *)s2;
while (i < n && frst[i] == scnd[i])
i++;
return ((i == n) ? 0 : frst[i] - scnd[i]);
}

31
libft/ft_memcpy.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:17 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:43:56 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n characters from src to dst and return dst
*/
#include "libft.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
char *ptr;
char *ptr2;
ptr = (char *)dst;
ptr2 = (char *)src;
i = -1;
while (++i < n)
ptr[i] = ptr2[i];
return (dst);
}

View File

@@ -1,25 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_fillit.c :+: :+: :+: */
/* ft_memdel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:35:48 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 00:11:22 by hulamy ### ########.fr */
/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
void ft_print_fillit()
{
}
** free memory
*/
void print_test(char *test)
#include "libft.h"
void ft_memdel(void **ap)
{
write(1, test, strlen(test));
if (ap && *ap)
{
free(*ap);
*ap = 0;
}
}

35
libft/ft_memmove.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:34 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:28 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n characters from src to dst in a non destructive way and return dst
*/
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
int i;
char *source;
char *dest;
i = -1;
source = (char *)src;
dest = (char *)dst;
if (source < dest)
while ((int)(--len) >= 0)
dest[len] = source[len];
else
while (++i < (int)len)
dest[i] = source[i];
return (dst);
}

29
libft/ft_memset.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:13:41 by hulamy #+# #+# */
/* Updated: 2019/04/03 15:44:44 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** copy n time a character in a string and return the string
*/
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
char *ptr;
size_t i;
ptr = (char *)b;
i = 0;
while (i < len)
ptr[i++] = c;
return (b);
}

View File

@@ -1,20 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_smallest_square.c :+: :+: :+: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */
/* Updated: 2019/04/14 21:37:19 by vmanzoni ### ########.fr */
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include "libft.h"
/*
char *get_smallest_square()
void ft_putchar(char c)
{
write(1, &c, 1);
}
*/

18
libft/ft_putchar_fd.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:14 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

19
libft/ft_putendl.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl(char const *s)
{
ft_putstr(s);
ft_putchar('\n');
}

19
libft/ft_putendl_fd.c Normal file
View File

@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:47 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:48 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char const *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

18
libft/ft_putnbr.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr(int n)
{
ft_putnbr_fd(n, 1);
}

28
libft/ft_putnbr_fd.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:09 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
long l;
l = n;
if (l < 0)
{
ft_putchar_fd('-', fd);
l *= -1;
}
if (l >= 10)
ft_putnbr_fd(l / 10, fd);
ft_putchar_fd((l % 10) + '0', fd);
}

59
libft/ft_putnbrbase.c Normal file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrbase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int check(char *base)
{
int i;
int j;
i = 0;
while (base[i])
{
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (0);
j++;
}
if (base[i] == '-' || base[i] == '+')
return (0);
i++;
}
if (i >= 2)
return (1);
return (0);
}
void ft_putnbrbase(int nbr, char *base)
{
int i;
long n;
i = 0;
n = nbr;
if (check(base))
{
if (n < 0)
{
ft_putchar('-');
n = -n;
}
while (base[i])
i++;
if (n >= i)
ft_putnbrbase(n / i, base);
ft_putchar(base[n % i]);
}
}

18
libft/ft_putnbrendl.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrendl.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */
/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbrendl(int n)
{
ft_putnbrendl_fd(n, 1);
}

29
libft/ft_putnbrendl_fd.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */
/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbrendl_fd(int n, int fd)
{
long l;
l = n;
if (l < 0)
{
ft_putchar_fd('-', fd);
l *= -1;
}
if (l >= 10)
ft_putnbr_fd(l / 10, fd);
ft_putchar_fd((l % 10) + '0', fd);
ft_putchar_fd('\n', fd);
}

22
libft/ft_putstr.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr(char const *s)
{
int i;
i = 0;
while (s && s[i])
ft_putchar(s[i++]);
}

Some files were not shown because too many files have changed in this diff Show More