1
0

first commit

This commit is contained in:
Adam Joly
2023-08-03 23:16:27 +02:00
parent 7f3254f1c5
commit a80c4d61d7
133 changed files with 4293 additions and 0 deletions

49
BSQ/Makefile Normal file
View File

@ -0,0 +1,49 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/08/02 19:37:01 by axdubois #+# #+# #
# Updated: 2023/08/02 19:37:06 by axdubois ### ########.fr #
# #
# **************************************************************************** #
NAME = bsq
CC = clang
SRCS = srcs/Display-c/write.c \
srcs/parsing-c/parsing.c \
srcs/utils-c/free.c \
srcs/utils-c/utils.c \
srcs/parsing-c/charobj.c \
srcs/main.c \
srcs/parsing-c/fst_line.c \
srcs/algo/algo.c \
srcs/algo/controller.c \
srcs/parsing-c/map_error.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wall -Wextra -Werror
$(NAME): $(OBJS)
$(CC) $(FLAGS) -o $(NAME) $(OBJS)
.c.o:
$(CC) $(FLAGS) -c $< -o $@
all: $(NAME)
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: clean all re fclean

20
BSQ/assets/gen.pl Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/perl
use warnings;
use strict;
die "program x y density" unless (scalar(@ARGV) == 3);
my ($x, $y, $density) = @ARGV;
print "$y.ox\n";
for (my $i = 0; $i < $y; $i++) {
for (my $j = 0; $j < $x; $j++) {
if (int(rand($y) * 2) < $density) {
print "o";
}
else {
print ".";
}
}
print "\n";
}

BIN
BSQ/bsq Executable file

Binary file not shown.

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* write.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:17:55 by axdubois #+# #+# */
/* Updated: 2023/08/02 19:21:49 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WRITE_H
# define WRITE_H
#include "../../includes/utils-h/utils.h"
#include "../../includes/utils-h/charobj.h"
#include "../../includes/algo-h/algo.h"
void ft_putchar(char c);
void ft_print(char *str);
void ft_print_result(t_square sq,t_charobj c,t_coords *listobj,int file);
#endif

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 22:11:53 by adjoly #+# #+# */
/* Updated: 2023/08/02 19:31:12 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ALGO_H
# define ALGO_H
#include "../../includes/utils-h/utils.h"
#include "../../includes/utils-h/charobj.h"
#include "../../includes/algo-h/algo.h"
typedef struct s_square
{
int x;
int y;
int side;
} t_square;
t_square ft_comb(t_coords *listobjsx, t_coords *listobjsy);
#endif

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* charobj.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/02 11:01:47 by axdubois #+# #+# */
/* Updated: 2023/08/02 19:10:38 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CHAROBJ_H
# define CHAROBJ_H
typedef struct s_charobj
{
char o;
char x;
char n;
} t_charobj;
t_charobj ft_get_charobj(char *ftline,int sizeline);
#endif

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fst_line.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 18:25:47 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:30:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FST_LINE_H
# define FST_LINE_H
int ft_len_line(int file, int n);
int ft_len_colum(int file);
char *ft_get_first_line(int file);
#endif

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:33:05 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:37:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_H
# define UTILS_H
# include <unistd.h>
# include <stdlib.h>
# include <fcntl.h>
typedef struct s_coords
{
int x;
int y;
} t_coords;
int ft_strlen(char *str);
void ft_swap(int *a, int *b);
void ft_sort_int_tab(int *tab, int size);
void ft_free_coords(t_coords *coords);
void ft_free_arr(char *arr);
void ft_free_d_arr(char **arr);
int ft_check_map(int file);
int ft_write_error(int file);
int ft_controller(int file);
t_coords *ft_sort_x(t_coords *coords, int size);
t_coords *ft_sort_y(t_coords *coords, int size);
t_coords *ft_get_list_obj(int file, char o);
int ft_get_nobj(int file, char o);
#endif

View File

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* write.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:11:14 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:34:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/Display-h/write.h"
#include "../../includes/utils-h/utils.h"
#include "../../includes/algo-h/algo.h"
#include "../../includes/utils-h/charobj.h"
#include "../../includes/utils-h/fst_line.h"
#include "../../includes/utils-h/utils.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_print(char *str)
{
int i;
i = 0;
while (str[i])
{
ft_putchar(str[i]);
i++;
}
}
void ft_print_linesq(int side,char x)
{
int i;
i = 0;
while(i < side)
{
ft_putchar(x);
i++;
}
}
void ft_print_result(t_square sq,t_charobj c,t_coords *listobj,int file)
{
int x;
int y;
int ysq;
y = 1;
ysq = 0;
while (y < ft_len_colum(file))
{
x = 0;
while (x < ft_len_line(file, y))
{
if ((listobj[x].x == x) && (listobj[y].y == y))
ft_putchar(c.o);
else if ((sq.x == x) && (ysq < sq.side))
{
ft_print_linesq(sq.side,c.x);
x += sq.side -1;
ysq++;
}
else
ft_putchar(c.n);
x++;
}
ft_putchar('\n');
y++;
}
}

BIN
BSQ/srcs/Display-c/write.o Normal file

Binary file not shown.

55
BSQ/srcs/algo/algo.c Normal file
View File

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 22:03:23 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:32:48 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/algo-h/algo.h"
#include "../../includes/utils-h/utils.h"
int ft_is_side_max(int x, int y, int mx, int my)
{
int l;
l = (mx - x) - (my - y);
if (l > 0)
return (mx - x);
else if (l < 0)
return (my - y);
else
return (0);
}
t_square ft_comb(t_coords *listobjsx, t_coords *listobjsy)
{
int i;
int j;
t_square square_max;
square_max.x = 0;
square_max.y = 0;
square_max.side = 0;
i = -1;
j = -1;
while (listobjsx[++i].x > -1)
{
while (listobjsy[++j].y > -1)
{
if ((square_max.x - listobjsx[i].x) < 0
&& (square_max.y - listobjsy[j].y) < 0)
{
square_max.x = listobjsx[i].x;
square_max.y = listobjsy[i].y;
square_max.side = ft_is_side_max(listobjsx[i].x,
listobjsy[j].y, square_max.x, square_max.y);
}
}
}
return (square_max);
}

BIN
BSQ/srcs/algo/algo.o Normal file

Binary file not shown.

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* controller.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/02 14:57:07 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:39:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/Display-h/write.h"
#include "../../includes/utils-h/utils.h"
#include "../../includes/algo-h/algo.h"
#include "../../includes/utils-h/charobj.h"
#include "../../includes/utils-h/fst_line.h"
int ft_controller(int file)
{
t_charobj charobj;
charobj = ft_get_charobj(ft_get_first_line(file), ft_len_line(file, 0));
ft_print_result(ft_comb(ft_sort_x(ft_get_list_obj(file, charobj.o),
ft_get_nobj(file, charobj.o)),
ft_sort_y(ft_get_list_obj(file, charobj.o),
ft_get_nobj(file, charobj.o))), charobj,
ft_get_list_obj(file, charobj.o),
file);
return (0);
}

BIN
BSQ/srcs/algo/controller.o Normal file

Binary file not shown.

47
BSQ/srcs/main.c Normal file
View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:14:41 by axdubois #+# #+# */
/* Updated: 2023/08/02 20:37:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/utils-h/utils.h"
int ft_while_file(int file, char **argv)
{
int i;
i = 0;
while (argv[i])
{
if (ft_check_map(file) == 1)
return (1);
ft_controller(file);
i++;
}
return (0);
}
int main(int argc, char **argv)
{
int file;
int i;
i = 1;
if (argc == 1)
{
file = 0;
ft_controller(file);
}
else
{
file = open(argv[i], O_RDONLY);
ft_while_file(file, argv);
}
}

BIN
BSQ/srcs/main.o Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* charobj.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/02 15:09:36 by axdubois #+# #+# */
/* Updated: 2023/08/02 19:39:22 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/utils-h/charobj.h"
t_charobj ft_get_charobj(char *ftline,int sizeline)
{
t_charobj charobj;
charobj.n = ftline[sizeline -3];
charobj.o = ftline[sizeline -2];
charobj.x = ftline[sizeline -1];
return (charobj);
}

Binary file not shown.

View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fst_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 18:23:55 by axdubois #+# #+# */
/* Updated: 2023/08/02 11:28:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/utils-h/utils.h"
int ft_len_line(int file, int n)
{
int count;
char *buf;
int i;
i = 0;
while (i < n)
{
read(file, &buf, 1);
i++;
}
count = 0;
buf = malloc(1);
while (*buf != '\n' && read(file, &buf, 1) > 0)
count++;
free(buf);
close(file);
return (count);
}
int ft_len_colum(int file)
{
int count;
char *buf;
int i;
i = 0;
count = 0;
buf = malloc(1);
while (read(file, &buf, 1) > 0)
{
if (*buf == '\n')
count++;
}
free(buf);
close(file);
return (count);
}
char *ft_get_first_line(int file)
{
char *buf;
int i;
char *fst_line;
int len_line;
//if (file == -1) main
//return (-1);
len_line = ft_len_line(file, 0);
fst_line = malloc(len_line + 1);
if (fst_line == NULL)
return (NULL);
i = 0;
while (i < len_line)
{
read(file, &buf, 1);
fst_line[i] = *buf;
i++;
}
fst_line[i] = 0;
return (fst_line);
}

Binary file not shown.

View File

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/02 10:06:20 by adjoly #+# #+# */
/* Updated: 2023/08/02 19:46:23 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/Display-h/write.h"
#include "../../includes/utils-h/utils.h"
#include "../../includes/algo-h/algo.h"
#include "../../includes/utils-h/charobj.h"
#include "../../includes/utils-h/fst_line.h"
int ft_write_error(int file)
{
write(2, "Map Error", 1);
close(file);
return (1);
}
int ft_atoi(char *str)
{
int i;
int result;
i = 0;
result = 0;
while (str[i] >= '0' && str[i] <= '9')
{
result = (result * 10) + str[i] - 48;
i++;
}
return (result);
}
int ft_check_map(int file)
{
char *first_line;
int line_nb;
int i_line_nb;
int i;
i = 1;
line_nb = ft_len_colum(file);
first_line = ft_get_first_line(file);
i_line_nb = ft_atoi(first_line);
if (i_line_nb != line_nb)
return (ft_write_error(file));
while (i < line_nb)
{
if (ft_len_line(file, i) != i_line_nb)
return (ft_write_error(file));
i++;
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,116 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:10:14 by axdubois #+# #+# */
/* Updated: 2023/08/02 19:39:26 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/utils-h/utils.h"
#include "../../includes/utils-h/fst_line.h"
int ft_get_nobj(int file, char o)
{
int count;
char *buf;
count = 0;
buf = malloc(1);
while (read(file, &buf, 1) > 0)
{
read(file, &buf, 1);
if (*buf == o)
count++;
}
free(buf);
close(file);
return (count);
}
int ft_get_y(int file, int obj_c, char o)
{
int count_obj;
int y_obj;
char *buf;
y_obj = 0;
count_obj = 0;
buf = malloc(1);
while (*buf)
{
read(file, &buf, 1);
if (*buf == '\n')
y_obj++;
if (*buf == o)
{
count_obj++;
if (obj_c == count_obj)
return (y_obj);
}
}
free(buf);
return(0);
}
int ft_get_x(int file, int obj_c, char o)
{
int count_obj;
int x_obj;
char *buf;
x_obj = 0;
count_obj = 0;
buf = malloc(1);
while (*buf)
{
read(file, &buf, 1);
if (*buf == '\n')
x_obj = 0;
if (*buf == o)
{
count_obj++;
if (obj_c == count_obj)
return (x_obj);
}
x_obj++;
}
free(buf);
return (0);
}
t_coords *ft_get_list_obj(int file, char o)
{
t_coords *list_obj;
int i;
int *buf;
int obj_c;
list_obj = malloc(sizeof(t_coords) * ft_get_nobj(file, o));
if (list_obj == NULL)
return (NULL);
i = 0;
obj_c = 0;
buf = malloc(1);
while (i < ft_get_nobj(file, o))
{
read(file, &buf, 1);
if (*buf == o)
{
obj_c++;
list_obj[i].x = ft_get_x(file, obj_c, o);
list_obj[i].y = ft_get_y(file, obj_c, o);
}
i++;
}
list_obj[i].x = ft_len_line(file, 1);
list_obj[i].y = ft_len_colum(file);
i++;
list_obj[i].x = -1;
list_obj[i].y = -1;
free(buf);
return (list_obj);
}

Binary file not shown.

37
BSQ/srcs/utils-c/free.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/01 17:51:39 by adjoly #+# #+# */
/* Updated: 2023/08/01 18:16:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/Display-h/write.h"
#include "../../includes/utils-h/utils.h"
void ft_free_coords(t_coords *coords)
{
free(coords);
}
void ft_free_arr(char *arr)
{
free(arr);
}
void ft_free_d_arr(char **arr)
{
int i;
i = -1;
while (arr[i])
{
free(arr[i]);
i++;
}
free(*arr);
}

BIN
BSQ/srcs/utils-c/free.o Normal file

Binary file not shown.

80
BSQ/srcs/utils-c/utils.c Normal file
View File

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: axdubois <axdubois@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 23:27:23 by axdubois #+# #+# */
/* Updated: 2023/08/02 19:28:42 by axdubois ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/Display-h/write.h"
#include "../../includes/utils-h/utils.h"
int ft_strlen(char *str)
{
int i;
i = 0;
while (*str != 0)
{
i++;
str++;
}
return (i);
}
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *b;
*b = *a;
*a = tmp;
}
t_coords *ft_sort_x(t_coords *coords, int size)
{
t_coords *arr;
int i;
i = 0;
arr = coords;
while (i != size - 1)
{
if (arr[i].x > arr[i + 1].x)
{
ft_swap(&arr[i].x, &arr[i + 1].x);
i = 0;
}
else
{
i++;
}
}
return (arr);
}
t_coords *ft_sort_y(t_coords *coords, int size)
{
t_coords *arr;
int i;
i = 0;
arr = coords;
while (i != size - 1)
{
if (arr[i].y > arr[i + 1].y)
{
ft_swap(&arr[i].y, &arr[i + 1].y);
i = 0;
}
else
{
i++;
}
}
return (arr);
}

BIN
BSQ/srcs/utils-c/utils.o Normal file

Binary file not shown.

11
BSQ/test Normal file
View File

@ -0,0 +1,11 @@
10.ox
...o.....o
......o..o
.oo...oo..
....o..ooo
o.....o..o
...o.....o
oo......o.
o..oo.....
..oo..o.o.
o..o......

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 20:19:51 by adjoly #+# #+# */
/* Updated: 2023/07/31 14:43:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int i;
int result;
i = 1;
result = 1;
if (nb < 0)
return (0);
if (nb == 0 || nb == 1)
return (1);
while (i <= nb)
{
result *= i;
i++;
}
return (result);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 20:36:35 by adjoly #+# #+# */
/* Updated: 2023/07/23 23:07:46 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
if (nb == 1 || nb == 0)
return (1);
return (ft_recursive_factorial(nb - 1) * nb);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 22:29:27 by adjoly #+# #+# */
/* Updated: 2023/07/25 19:40:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int result;
if (power < 0)
return (0);
if (power == 0)
return (1);
if (power == 1)
return (nb);
result = nb;
while (power > 1)
{
result *= nb;
power--;
}
return (result);
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 22:18:51 by adjoly #+# #+# */
/* Updated: 2023/07/25 19:41:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
if (power < 0)
return (0);
if (power == 0)
return (1);
if (power == 1)
return (nb);
return (ft_recursive_power(nb, power - 1) * nb);
}

24
C05/ex04/ft_fibonacci.c Normal file
View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 22:53:47 by adjoly #+# #+# */
/* Updated: 2023/07/31 16:58:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (index < 0)
return (-1);
if (index == 0)
return (0);
if (index == 1)
return (1);
if (index == 2)
return (1);
return (ft_fibonacci(index - 2) + ft_fibonacci(index - 1));
}

25
C05/ex05/ft_sqrt.c Normal file
View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 22:18:51 by adjoly #+# #+# */
/* Updated: 2023/07/25 19:41:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int i;
i = 0;
while (i <= 46340)
{
if (i * i == nb)
return (i);
i++;
}
return (0);
}

BIN
C05/ex06/.ft_is_prime.c.swp Normal file

Binary file not shown.

29
C05/ex06/ft_is_prime.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 23:24:05 by adjoly #+# #+# */
/* Updated: 2023/08/02 10:20:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
if (nb <= 0 || nb == 1)
return (0);
i = 2;
if (nb == 2)
return (1);
while (i < nb / 2)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 23:24:05 by adjoly #+# #+# */
/* Updated: 2023/07/31 09:59:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb == 2147483647)
return (1);
if (nb <= 0 || nb == 1)
return (0);
if (nb % 2 == 0)
return (0);
while (i < nb / 2)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
int i;
i = nb;
if (nb <= 2)
return (2);
while (ft_is_prime(i) != 1)
i++;
return (i);
}

46
C07/ex00/ft_strdup.c Normal file
View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/25 21:06:54 by adjoly #+# #+# */
/* Updated: 2023/08/03 16:38:19 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}
char *ft_strdup(char *src)
{
int i;
char *dest;
int len;
i = 0;
len = ft_strlen(src);
dest = malloc(sizeof(char) * len);
if (dest == NULL)
return (NULL);
while (src[i])
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

33
C07/ex01/ft_range.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/27 19:51:50 by adjoly #+# #+# */
/* Updated: 2023/07/31 09:40:55 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int i;
int *arr;
i = 0;
if (min >= max)
return (NULL);
arr = malloc((max - min) * sizeof(int));
if (arr == NULL)
return (NULL);
while (min < max)
{
arr[i] = min;
min++;
i++;
}
return (arr);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/27 19:51:50 by adjoly #+# #+# */
/* Updated: 2023/08/03 20:25:00 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_ultimate_range(int **range, int min, int max)
{
int i;
int *arr;
i = 0;
if (min >= max)
{
*range = 0;
return (0);
}
arr = malloc((max - min) * sizeof(int));
if (arr == NULL)
{
*range = 0;
return (-1);
}
while (min < max)
{
arr[i] = min + i;
i++;
}
*range = arr;
return (max - min);
}

85
C07/ex03/ft_strjoin.c Normal file
View File

@ -0,0 +1,85 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/31 12:52:50 by adjoly #+# #+# */
/* Updated: 2023/08/03 16:37:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int ft_strlenn(int size, char **strs, char *sep)
{
int len;
int i;
i = 0;
len = 0;
while (i < size)
{
len += ft_strlen(strs[i]);
i++;
}
len += (ft_strlen(sep) * (size - 1));
return (len);
}
char *ft_strcat(char *dest, char *src)
{
int size_dest;
unsigned int i;
i = 0;
size_dest = ft_strlen(dest);
while (src[i])
{
dest[size_dest + i] = src[i];
i++;
}
dest[size_dest + i] = '\0';
return (dest);
}
char *ft_strjoin(int size, char **strs, char *sep)
{
int len_strs;
char *result;
int i;
i = 0;
if (size == 0 || !strs || !sep)
{
result = malloc(1);
*result = 0;
return (result);
}
len_strs = ft_strlenn(size, strs, sep);
result = malloc((len_strs + 1) * sizeof(char));
if (result == NULL)
return (NULL);
result[0] = 0;
while (i < size)
{
ft_strcat(result, strs[i]);
if (i < size - 1)
ft_strcat(result, sep);
i++;
}
return (result);
}

22
C08/ex00/ft.h Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/26 23:13:31 by adjoly #+# #+# */
/* Updated: 2023/07/26 23:35:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_H
# define FT_H
void ft_putchar(char c);
void ft_swap(int *a, int *b);
void ft_putstr(char *str);
int ft_strlen(char *str);
int ft_strcmp(char *s1, char *s2);
#endif

18
C08/ex01/ft_boolean.h Normal file
View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_boolean.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/26 23:45:33 by adjoly #+# #+# */
/* Updated: 2023/07/26 23:50:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_BOOLEAN_H
# define FT_BOOLEAN_H
#endif

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 10:32:16 by adjoly #+# #+# */
/* Updated: 2023/07/12 10:50:35 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 11:08:23 by adjoly #+# #+# */
/* Updated: 2023/07/12 20:50:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_alphabet(void)
{
char i;
i = 'a';
while (i <= 'z')
{
write(1, &i, 1);
i++;
}
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 11:08:23 by adjoly #+# #+# */
/* Updated: 2023/07/15 15:45:54 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_reverse_alphabet(void)
{
char i;
i = 'z';
while (i >= 'a')
{
write(1, &i, 1);
i--;
}
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 20:36:08 by adjoly #+# #+# */
/* Updated: 2023/07/15 15:33:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_numbers(void)
{
char nbr;
nbr = '0';
while (nbr <= '9')
{
write(1, &nbr, 1);
nbr++;
}
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_negative.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 20:51:36 by adjoly #+# #+# */
/* Updated: 2023/07/13 11:47:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_is_negative(int n)
{
if (n < 0)
write(1, "N", 1);
else
write(1, "P", 1);
}

View File

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 23:26:35 by adjoly #+# #+# */
/* Updated: 2023/07/13 11:45:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_virgule(char a, char b, char c)
{
if (!(a == '7' && b == '8' && c == '9'))
{
write(1, ",", 1);
write(1, " ", 1);
}
}
void ft_print_comb(void)
{
char a;
char b;
char c;
a = '0';
while (a <= '7')
{
b = a + 1;
while (b <= '8')
{
c = b + 1;
while (c <= '9')
{
write(1, &a, 1);
write(1, &b, 1);
write(1, &c, 1);
ft_print_virgule(a, b, c);
c++;
}
b++;
}
a++;
}
}

View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 11:13:23 by adjoly #+# #+# */
/* Updated: 2023/07/16 13:29:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_nbr(int a, int b)
{
char c;
char d;
char e;
char f;
c = a / 10 + 48;
d = a % 10 + 48;
e = b / 10 + 48;
f = b % 10 + 48;
write(1, &c, 1);
write(1, &d, 1);
write(1, " ", 1);
write(1, &e, 1);
write(1, &f, 1);
if (!(c == '9' && d == '8' && e == '9' && f == '9'))
write(1, ", ", 2);
}
void ft_print_comb2(void)
{
int a;
int b;
a = 0;
while (a <= 98)
{
b = a + 1;
while (b <= 99)
{
ft_print_nbr(a, b);
b++;
}
a++;
}
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 13:51:06 by adjoly #+# #+# */
/* Updated: 2023/07/16 13:26:07 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int nb)
{
if (nb == -214783648)
{
write(1, "-214783648", 10);
return ;
}
if (nb < 0)
{
write(1, "-", 1);
ft_putnbr(nb * -1);
}
else if (nb < 10)
write(1, &(char){nb + 48}, 1);
else
{
ft_putnbr(nb / 10);
write(1, &(char){nb % 10 + 48}, 1);
}
}

16
finish/C01/ex00/ft_ft.c Normal file
View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 18:51:05 by adjoly #+# #+# */
/* Updated: 2023/07/16 21:06:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ft(int *nbr)
{
*nbr = 42;
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 19:08:30 by adjoly #+# #+# */
/* Updated: 2023/07/13 19:09:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
}

20
finish/C01/ex02/ft_swap.c Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 19:20:17 by adjoly #+# #+# */
/* Updated: 2023/07/16 19:00:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 19:36:32 by adjoly #+# #+# */
/* Updated: 2023/07/13 19:40:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 10:03:47 by adjoly #+# #+# */
/* Updated: 2023/07/14 10:32:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int div;
int mod;
div = *a / *b;
mod = *a % *b;
*a = div;
*b = mod;
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 10:36:38 by adjoly #+# #+# */
/* Updated: 2023/07/14 18:35:37 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 18:37:42 by adjoly #+# #+# */
/* Updated: 2023/07/14 18:40:41 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 18:49:16 by adjoly #+# #+# */
/* Updated: 2023/07/16 21:06:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void ft_rev_int_tab(int *tab, int size)
{
int i;
i = 0;
while (i < size)
{
ft_swap(&tab[i], &tab[--size]);
i++;
}
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/15 16:49:13 by adjoly #+# #+# */
/* Updated: 2023/07/17 11:15:40 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i])
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/15 16:49:13 by adjoly #+# #+# */
/* Updated: 2023/07/17 22:41:12 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (i < n && src[i])
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_alpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 14:06:22 by adjoly #+# #+# */
/* Updated: 2023/07/17 17:16:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_alpha(char *str)
{
int i;
i = 0;
while (str[i])
{
if ((str[i] < 65 || str[i] > 90) && (str[i] < 97 || str[i] > 122))
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_numeric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 14:06:22 by adjoly #+# #+# */
/* Updated: 2023/07/17 17:53:00 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_numeric(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < '0' || str[i] > '9')
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_lowercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 14:06:22 by adjoly #+# #+# */
/* Updated: 2023/07/17 17:19:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_lowercase(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < 97 || str[i] > 122)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_uppercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 14:06:22 by adjoly #+# #+# */
/* Updated: 2023/07/17 17:58:53 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_uppercase(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < 65 || str[i] > 90)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_printable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 14:06:22 by adjoly #+# #+# */
/* Updated: 2023/07/17 17:51:25 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_printable(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < 32 || str[i] == 127)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 17:50:51 by adjoly #+# #+# */
/* Updated: 2023/07/19 22:09:15 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strupcase(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] >= 97 && str[i] <= 122)
str[i] -= 32;
i++;
}
return (str);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlowcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 17:50:51 by adjoly #+# #+# */
/* Updated: 2023/07/20 09:37:24 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] >= 65 && str[i] <= 90)
str[i] = str[i] + 32;
i++;
}
return (str);
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 18:12:38 by adjoly #+# #+# */
/* Updated: 2023/07/18 21:24:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcapitalize(char *str)
{
int i;
i = 0;
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 32;
i++;
while (str[i])
{
if ((str[i] >= 'a' && str[i] <= 'z')
&& !((str[i - 1] >= '0' && str[i - 1] <= '9')
|| (str[i - 1] >= 'a' && str[i - 1] <= 'z')
|| (str[i - 1] >= 'A' && str[i - 1] <= 'Z')))
str[i] -= 32;
else if (str[i] >= 'A' && str[i] <= 'Z'
&& ((str[i - 1] >= '0' && str[i - 1] <= '9')
|| (str[i - 1] >= 'a' && str[i - 1] <= 'z')
|| (str[i - 1] >= 'A' && str[i - 1] <= 'Z')))
str[i] += 32;
i++;
}
return (str);
}

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 13:39:08 by adjoly #+# #+# */
/* Updated: 2023/07/18 19:49:31 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
i = 0;
if (size == 0)
{
while (src[i])
i++;
return (i);
}
while (src[i] && i + 1 < size)
{
dest[i] = src[i];
i++;
}
while (i < size)
{
dest[i] = '\0';
i++;
}
i = 0;
while (src[i])
i++;
return (i);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 16:20:57 by adjoly #+# #+# */
/* Updated: 2023/07/25 13:06:36 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] || s2[i])
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
i++;
}
return (s1[i] - s2[i]);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 16:20:57 by adjoly #+# #+# */
/* Updated: 2023/07/25 13:07:01 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
unsigned int i;
i = 0;
while ((s1[i] || s2[i]) && i < n)
{
if (s1[i] != s2[i])
return (s1[i] - s2[i]);
i++;
}
return (0);
}

View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 17:17:04 by adjoly #+# #+# */
/* Updated: 2023/07/18 17:33:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int size_dest;
unsigned int i;
i = 0;
size_dest = ft_strlen(dest);
while (src[i])
{
dest[size_dest + i] = src[i];
i++;
}
dest[size_dest + i] = '\0';
return (dest);
}

View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 17:17:04 by adjoly #+# #+# */
/* Updated: 2023/07/18 17:32:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strncat(char *dest, char *src, unsigned int nb)
{
int size_dest;
unsigned int i;
i = 0;
size_dest = ft_strlen(dest);
while (src[i] && i < nb)
{
dest[size_dest + i] = src[i];
i++;
}
dest[size_dest + i] = '\0';
return (dest);
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/18 21:31:36 by adjoly #+# #+# */
/* Updated: 2023/07/20 22:14:23 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strstr(char *str, char *to_find)
{
int i;
int j;
i = 0;
j = 0;
if (to_find[0] == '\0')
{
return (str);
}
while (str[i])
{
while (str[i + j] == to_find[j])
{
if (to_find[j + 1] == '\0')
return (&str[i]);
j++;
}
j = 0;
i++;
}
return (0);
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 08:44:17 by adjoly #+# #+# */
/* Updated: 2023/07/19 08:57:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 08:58:22 by adjoly #+# #+# */
/* Updated: 2023/07/19 09:02:13 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 13:51:06 by adjoly #+# #+# */
/* Updated: 2023/07/25 12:57:21 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putnbr(int nb)
{
unsigned int nbr;
if (nb < 0)
{
write(1, "-", 1);
nbr = -nb;
}
else
nbr = nb;
if (nbr < 10)
write(1, &(char){nbr + 48}, 1);
else
{
ft_putnbr(nbr / 10);
write(1, &(char){nbr % 10 + 48}, 1);
}
}

37
finish/C04/ex03/ft_atoi.c Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 09:27:06 by adjoly #+# #+# */
/* Updated: 2023/07/26 09:56:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int neg;
int result;
i = 0;
neg = 1;
result = 0;
while (str[i] == ' ' || (str[i] >= 9 && str[i] <= 13))
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
neg *= -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
result = (result * 10) + str[i] - 48;
i++;
}
result *= neg;
return (result);
}

View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 14:25:29 by adjoly #+# #+# */
/* Updated: 2023/07/25 09:20:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int ft_checkbase(char *base)
{
int i;
int j;
i = 0;
if (ft_strlen(base) <= 1)
return (1);
while (base[i])
{
if (base[i] == '-' || base[i] == '+')
return (1);
j = i + 1;
while (base[j])
{
if (base[i] == base[j])
return (1);
j++;
}
i++;
}
return (0);
}
void ft_putnbr_base(int nbr, char *base)
{
unsigned int len;
unsigned int y;
if (ft_checkbase(base) == 1)
return ;
len = ft_strlen(base);
if (nbr < 0)
{
write(1, "-", 1);
y = -nbr;
}
else
y = nbr;
if (y < len)
write(1, &(char){base[y]}, 1);
else
{
ft_putnbr_base(y / len, base);
write(1, &(char){base[y % len]}, 1);
}
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 09:18:20 by adjoly #+# #+# */
/* Updated: 2023/07/24 09:22:02 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int ac, char **av)
{
int i;
i = 0;
(void)ac;
while (av[0][i])
{
write(1, &av[0][i], 1);
i++;
}
}

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 09:26:14 by adjoly #+# #+# */
/* Updated: 2023/07/24 09:40:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int ac, char **av)
{
int i;
int j;
(void)ac;
i = 1;
j = 0;
while (av[i])
{
j = 0;
while (av[i][j])
{
write(1, &av[i][j], 1);
j++;
}
write(1, "\n", 1);
i++;
}
}

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 09:38:41 by adjoly #+# #+# */
/* Updated: 2023/07/27 09:49:32 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int ac, char **av)
{
int i;
int j;
i = 0;
(void)ac;
while (av[i])
i++;
while (i > 1)
{
j = 0;
i--;
while (av[i][j])
{
write(1, &av[i][j], 1);
j++;
}
write(1, "\n", 1);
}
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/12 11:59:45 by ttrave #+# #+# */
/* Updated: 2023/07/15 09:59:04 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}

19
finish/rush00/ex00/main.c Normal file
View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/15 10:00:20 by ttrave #+# #+# */
/* Updated: 2023/07/15 10:39:38 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void rush(int x, int y);
int main(void)
{
rush(25, 17);
return (0);
}

View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush00.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 21:13:37 by ttrave #+# #+# */
/* Updated: 2023/07/16 11:30:51 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void rush(int x, int y)
{
int w;
int h;
w = 1;
h = 1;
while (y > 0 && h <= y)
{
while (x > 0 && w <= x)
{
if (((h == 1 || h == y) && w == 1)
|| ((h == 1 || h == y) && w == x))
ft_putchar('o');
else if (w == x || w == 1)
ft_putchar('|');
else if (h == 1 || h == y)
ft_putchar('-');
else
ft_putchar(' ');
w++;
}
ft_putchar('\n');
w = 1;
h++;
}
}

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush01.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 21:13:37 by ttrave #+# #+# */
/* Updated: 2023/07/16 11:31:22 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void rush(int x, int y)
{
int w;
int h;
w = 1;
h = 1;
while (y > 0 && h <= y)
{
while (x > 0 && w <= x)
{
if ((w == 1 && h == 1) || (w == x && h == y))
ft_putchar('/');
else if ((w == x && h == 1) || (w == 1 && h == y))
ft_putchar('\\');
else if (w == x || w == 1 || h == 1 || h == y)
ft_putchar('*');
else
ft_putchar(' ');
w++;
}
ft_putchar('\n');
w = 1;
h++;
}
}

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush02.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 21:13:37 by ttrave #+# #+# */
/* Updated: 2023/07/16 11:32:34 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void rush(int x, int y)
{
int w;
int h;
w = 1;
h = 1;
while (y > 0 && h <= y)
{
while (x > 0 && w <= x)
{
if (h == 1 && (w == 1 || w == x))
ft_putchar('A');
else if (h == y && (w == 1 || w == x))
ft_putchar('C');
else if (w == x || w == 1 || h == 1 || h == y)
ft_putchar('B');
else
ft_putchar(' ');
w++;
}
ft_putchar('\n');
w = 1;
h++;
}
}

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush03.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 21:13:37 by ttrave #+# #+# */
/* Updated: 2023/07/16 11:33:12 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void rush(int x, int y)
{
int w;
int h;
w = 1;
h = 1;
while (y > 0 && h <= y)
{
while (x > 0 && w <= x)
{
if (w == 1 && (h == 1 || h == y))
ft_putchar('A');
else if (w == x && (h == 1 || h == y))
ft_putchar('C');
else if (w == x || w == 1 || h == 1 || h == y)
ft_putchar('B');
else
ft_putchar(' ');
w++;
}
ft_putchar('\n');
w = 1;
h++;
}
}

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rush04.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ttrave <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 21:13:37 by ttrave #+# #+# */
/* Updated: 2023/07/16 11:33:48 by ttrave ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void rush(int x, int y)
{
int w;
int h;
w = 1;
h = 1;
while (y > 0 && h <= y)
{
while (x > 0 && w <= x)
{
if ((w == 1 && h == 1) || (w == x && h == y))
ft_putchar('A');
else if ((w == x && h == 1) || (w == 1 && h == y))
ft_putchar('C');
else if (w == x || w == 1 || h == 1 || h == y)
ft_putchar('B');
else
ft_putchar(' ');
w++;
}
ft_putchar('\n');
w = 1;
h++;
}
}

View File

@ -0,0 +1,108 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bruteforce.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmikola <jmikola@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 12:00:11 by psalame #+# #+# */
/* Updated: 2023/07/23 12:43:04 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
int get_area_size(void);
int ft_test_possibility(int **tab, int i);
int verif_non_double(int i, int **tab);
int verif_col_down(int i, int **tab);
int verif_col_up(int i, int **tab);
int verif_row_right(int i, int **tab);
int verif_row_left(int i, int **tab);
int **get_row(void);
int **get_col(void);
int verif_all_row(int i, int **tab)
{
int row_left;
int row_right;
int area_size;
area_size = get_area_size();
row_left = verif_row_left(i, tab);
row_right = verif_row_right(i, tab);
if (((i % area_size) == area_size - 1))
{
if (row_left != get_row()[i / area_size][0]
|| row_right != get_row()[i / area_size][1])
return (0);
}
else if (row_left > get_row()[i / area_size][0])
return (0);
return (1);
}
int verif_all_col(int i, int **tab)
{
int col_up;
int col_down;
int area_size;
area_size = get_area_size();
col_up = verif_col_up(i, tab);
col_down = verif_col_down(i, tab);
if (((i / area_size) == area_size - 1))
{
if (col_up != get_col()[i % area_size][0]
|| col_down != get_col()[i % area_size][1])
return (0);
}
else if (col_up > get_col()[i % area_size][0])
return (0);
return (1);
}
int verif(int i, int **tab)
{
if (!verif_non_double(i, tab))
return (0);
return (verif_all_row(i, tab) && verif_all_col(i, tab));
}
int is_possibility_valid(int **tab, int i)
{
int area_size;
area_size = get_area_size();
if (i == area_size * area_size - 1)
return (1);
else
return (ft_test_possibility(tab, i + 1));
}
int ft_test_possibility(int **tab, int i)
{
int area_size;
int height;
area_size = get_area_size();
if (tab[i / area_size][i % area_size] == 0)
{
height = 0;
while (++height <= area_size)
{
tab[i / area_size][i % area_size] = height;
if (verif(i, tab))
{
if (is_possibility_valid(tab, i))
return (1);
}
}
tab[i / area_size][i % area_size] = 0;
return (0);
}
else
{
if (!verif(i, tab))
return (0);
return (is_possibility_valid(tab, i));
}
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free_tabtab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: psalame <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 14:18:27 by psalame #+# #+# */
/* Updated: 2023/07/22 16:25:32 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void ft_free_tabtab(int **tab, int size)
{
int i;
i = 0;
while (i < size)
{
free(tab[i]);
i++;
}
free(tab);
}

View File

@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_tables.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: psalame <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 19:12:44 by psalame #+# #+# */
/* Updated: 2023/07/23 17:44:52 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int get_area_size(void);
int **get_row_args(char **argv)
{
int i_row;
int tab_index;
int **row;
int s;
s = get_area_size();
row = malloc(s * sizeof(int *));
if (row == NULL)
return (NULL);
i_row = s * 4;
tab_index = 0;
while (i_row < (s * 6 - 1))
{
if (argv[1][i_row] != ' ')
{
row[tab_index] = malloc(2 * sizeof(int));
row[tab_index][0] = argv[1][i_row] - '0';
row[tab_index][1] = argv[1][i_row + s * 2] - '0';
tab_index ++;
}
i_row ++;
}
return (row);
}
int **get_col_args(char **argv)
{
int i_col;
int tab_index;
int **col;
int s;
s = get_area_size();
col = (int **) malloc(s * sizeof(int *));
if (col == NULL)
return (NULL);
i_col = 0;
tab_index = 0;
while (i_col < (s * 2 - 1))
{
if (argv[1][i_col] != ' ')
{
col[tab_index] = malloc(2 * sizeof(int));
col[tab_index][0] = argv[1][i_col] - '0';
col[tab_index][1] = argv[1][i_col + s * 2] - '0';
tab_index++;
}
i_col ++;
}
return (col);
}
int **init_res(void)
{
int i;
int j;
int **res;
res = malloc(get_area_size() * sizeof(int *));
if (res == NULL)
return (NULL);
i = 0;
j = 0;
while (i < get_area_size())
{
res[i] = malloc(get_area_size() * sizeof(int));
j = 0;
while (j < get_area_size())
{
res[i][j] = 0;
j++;
}
i++;
}
return (res);
}

View File

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_args_valid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: psalame <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 13:31:00 by psalame #+# #+# */
/* Updated: 2023/07/23 11:19:18 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
int is_args_valid(int argc, char **argv)
{
int i;
int area_size;
if (argc != 2)
return (0);
area_size = (ft_strlen(argv[1]) + 1) / 2 / 2 / 2;
if (area_size < 2 || (ft_strlen(argv[1]) + 1) % area_size != 0)
return (0);
i = 0;
while (argv[1][i] && area_size != 0)
{
if (i % 2 == 0)
{
if (argv[1][i] < '1' || argv[1][i] > '0' + area_size)
area_size = 0;
}
else
if (argv[1][i] != ' ')
area_size = 0;
i++;
}
return (area_size);
}

70
finish/rush01/ex00/main.c Normal file
View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ale-gal <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 12:32:28 by ale-gal #+# #+# */
/* Updated: 2023/07/23 17:45:59 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int get_area_size(void);
int **get_col_args(char **argv);
int **get_row_args(char **argv);
void ft_free_tabtab(int **tab, int size);
void ft_print_double_tab(int **tab, int size);
int **ft_place_sure(int **row, int **col, int **result);
int is_args_valid(int argc, char **argv);
int ft_test_possibility(int **tab, int i);
int **init_res(void);
int **g_col;
int **g_row;
int g_area_size;
int **get_col(void)
{
return (g_col);
}
int **get_row(void)
{
return (g_row);
}
int main(int argc, char **argv)
{
int **res;
g_area_size = is_args_valid(argc, argv);
if (g_area_size == 0)
{
write(1, "Error\n", 6);
return (0);
}
g_col = get_col_args(argv);
g_row = get_row_args(argv);
res = init_res();
if (g_col == NULL || g_row == NULL || res == NULL)
{
write(1, "Error\n", 6);
return (0);
}
ft_place_sure(g_row, g_col, res);
if (ft_test_possibility(res, 0))
ft_print_double_tab(res, get_area_size());
else
write(1, "Error\n", 6);
ft_free_tabtab(res, get_area_size());
ft_free_tabtab(g_col, get_area_size());
ft_free_tabtab(g_row, get_area_size());
return (0);
}
int get_area_size(void)
{
return (g_area_size);
}

View File

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* place_sure.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 11:37:10 by adjoly #+# #+# */
/* Updated: 2023/07/23 11:11:18 by psalame ### ########.fr */
/* */
/* ************************************************************************** */
int get_area_size(void);
void con_col(int **result, int i, int j, int **col)
{
int k;
k = 0;
if (col[i][j] == 1)
{
if (j == 1)
result[get_area_size() - 1][i] = get_area_size();
else
result[0][i] = get_area_size();
}
else if (col[i][j] == get_area_size())
{
if (j == 1)
{
k = get_area_size() + 1;
while (--k > 0)
result[k - 1][i] = (get_area_size() - k + 1);
}
else
{
while (++k <= get_area_size())
result[k - 1][i] = k;
}
}
}
void con_row(int **result, int i, int j, int **row)
{
int k;
k = 0;
if (row[i][j] == 1)
{
if (j == 1)
result[i][get_area_size() - 1] = get_area_size();
else
result[i][0] = get_area_size();
}
else if (row[i][j] == get_area_size())
{
if (j == 1)
{
k = get_area_size();
while (--k > 0)
result[i][k - 1] = (get_area_size() - k + 1);
}
else
{
while (++k <= get_area_size())
result[i][k - 1] = k;
}
}
}
void place_col(int size, int **col, int **result)
{
int i;
int j;
i = 0;
while (i < size)
{
j = 0;
while (j < 2)
{
con_col(result, i, j, col);
j++;
}
i++;
}
}
void place_row(int size, int **row, int **result)
{
int i;
int j;
i = 0;
while (i < size)
{
j = 0;
while (j < 2)
{
con_row(result, i, j, row);
j++;
}
i++;
}
}
int **ft_place_sure(int **row, int **col, int **result)
{
int size;
size = get_area_size();
place_row(size, row, result);
place_col(size, col, result);
return (result);
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_double_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ale-gal <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 11:42:20 by ale-gal #+# #+# */
/* Updated: 2023/07/22 16:51:52 by ale-gal ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_double_tab(int **tab, int size)
{
int i_x;
int i_y;
char chr;
i_y = 0;
while (i_y < size)
{
i_x = 0;
while (i_x < size)
{
chr = '0' + tab[i_y][i_x];
write(1, &chr, 1);
if (i_x != size - 1)
write(1, " ", 1);
i_x++;
}
write(1, "\n", 1);
i_y++;
}
}

128
finish/rush01/ex00/verif.c Normal file
View File

@ -0,0 +1,128 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* verif.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmikola <jmikola@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/22 13:01:37 by jmikola #+# #+# */
/* Updated: 2023/07/23 10:53:36 by jmikola ### ########.fr */
/* */
/* ************************************************************************** */
int get_area_size(void);
int verif_row_left(int i, int **tab)
{
int val_row_left;
int v_max;
int j;
int area_size;
j = 0;
val_row_left = 0;
v_max = 0;
area_size = get_area_size();
while (j < area_size)
{
if (tab[i / area_size][j] > v_max)
{
val_row_left++;
v_max = tab[i / area_size][j];
}
j++;
}
return (val_row_left);
}
int verif_row_right(int i, int **tab)
{
int val_row_right;
int v_max;
int j;
int area_size;
area_size = get_area_size();
j = area_size - 1;
v_max = 0;
val_row_right = 0;
while (j >= 0)
{
if (tab[i / area_size][j] > v_max)
{
val_row_right++;
v_max = tab[i / area_size][j];
}
j--;
}
return (val_row_right);
}
int verif_col_up(int i, int **tab)
{
int val_col_up;
int v_max;
int j;
int area_size;
j = 0;
v_max = 0;
val_col_up = 0;
area_size = get_area_size();
while (j < area_size)
{
if (tab[j][i % area_size] > v_max)
{
val_col_up++;
v_max = tab[j][i % area_size];
}
j++;
}
return (val_col_up);
}
int verif_col_down(int i, int **tab)
{
int val_col_down;
int v_max;
int j;
int area_size;
area_size = get_area_size();
j = area_size - 1;
v_max = 0;
val_col_down = 0;
while (j >= 0)
{
if (tab[j][i % area_size] > v_max)
{
val_col_down++;
v_max = tab[j][i % area_size];
}
j--;
}
return (val_col_down);
}
int verif_non_double(int i, int **tab)
{
int j;
int area_size;
j = 0;
area_size = get_area_size();
while (j < i % area_size)
{
if (tab[i / area_size][j] == tab[i / area_size][i % area_size])
return (0);
j++;
}
j = 0;
while (j < i / area_size)
{
if (tab[j][i % area_size] == tab[i / area_size][i % area_size])
return (0);
j++;
}
return (1);
}

View File

@ -0,0 +1,46 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2023/07/30 22:41:49 by tomoron ### ########.fr #
# #
# **************************************************************************** #
NAME = rush-02
CC = gcc
SRCS = algo.c \
algo2.c \
lib2.c \
lib.c \
main.c \
parse2.c \
parse.c \
special_tens.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wall -Wextra -Werror
$(NAME): $(OBJS)
$(CC) $(FLAGS) -o $(NAME) $(OBJS)
.c.o:
$(CC) $(FLAGS) -c $< -o $@
all: $(NAME)
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: clean all re fclean

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