init
This commit is contained in:
59
Rush/Rush01/check.c
Normal file
59
Rush/Rush01/check.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/24 08:21:31 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/24 20:18:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_verif_line(int nb_tower_viewable_in, int *line, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int nb_tower_viewable_out;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
nb_tower_viewable_out = 1;
|
||||
while (i < size)
|
||||
{
|
||||
j = 0;
|
||||
while (line[j] < line[i])
|
||||
{
|
||||
if (i == j + 1)
|
||||
break ;
|
||||
j++;
|
||||
}
|
||||
if (line[j] < line[i])
|
||||
nb_tower_viewable_out++;
|
||||
i++;
|
||||
}
|
||||
return (nb_tower_viewable_out);// == nb_tower_viewable_in);
|
||||
}
|
||||
|
||||
|
||||
int *ft_verif(int *tab_user, int *tab_gen, int size)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int *line;
|
||||
|
||||
i = 0;
|
||||
line = malloc(sizeof(*line) * size);
|
||||
while (i < size * 4)
|
||||
{
|
||||
j = 0;
|
||||
while (j < size * size)
|
||||
{
|
||||
ft_verif_line(tab_user[i], line, size);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
28
Rush/Rush01/ft_print.c
Normal file
28
Rush/Rush01/ft_print.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_print.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jvasseur <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/24 17:09:36 by jvasseur #+# #+# */
|
||||
/* Updated: 2022/07/25 15:52:24 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_putchar(char c);
|
||||
|
||||
void ft_print(int *tab)
|
||||
{
|
||||
int a;
|
||||
a = 0;
|
||||
while(a < 16)
|
||||
{
|
||||
ft_putchar(tab[a] + '0');
|
||||
if ((a + 1) % 4 == 0)
|
||||
ft_putchar('\n');
|
||||
else
|
||||
ft_putchar(' ');
|
||||
a++;
|
||||
}
|
||||
}
|
19
Rush/Rush01/ft_printf.c
Normal file
19
Rush/Rush01/ft_printf.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/24 20:04:30 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/24 20:15:03 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_putchar(char c);
|
||||
|
||||
void ft_printf(char *str)
|
||||
{
|
||||
while (str != 0)
|
||||
ft_putchar(*str++);
|
||||
}
|
6
Rush/Rush01/ft_putchar.c
Normal file
6
Rush/Rush01/ft_putchar.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
50
Rush/Rush01/gen.c
Normal file
50
Rush/Rush01/gen.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* gen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/23 09:11:05 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/24 20:00:05 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_gen_row(int *tab, int size, int seed, int row_number)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
tab[0] = seed;
|
||||
while (i < size)
|
||||
{
|
||||
tab[i] = size % (tab[i - 1] + seed + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int *ft_gen(int size)
|
||||
{
|
||||
int *tab;
|
||||
int i;
|
||||
int seed;
|
||||
|
||||
tab = malloc(sizeof(*tab) * size * size);
|
||||
seed = 0;
|
||||
while (seed < size * size)
|
||||
{
|
||||
ft_gen_row(tab, 4, seed, 1);
|
||||
seed++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
39
Rush/Rush01/input.c
Normal file
39
Rush/Rush01/input.c
Normal file
@ -0,0 +1,39 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
int ft_input(char *str)
|
||||
{
|
||||
int i;
|
||||
int counter;
|
||||
int *tab;
|
||||
|
||||
i = 0;
|
||||
counter = 1;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if ('0' < str[i] && str[i] < '5')
|
||||
counter++;
|
||||
else
|
||||
if (str[i] != ' ')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
tab = malloc(sizeof(tab) * counter);
|
||||
counter = 0;
|
||||
while (str[i] != 0)
|
||||
{
|
||||
if ('0' < str[i] && str[i] < '5')
|
||||
{
|
||||
tab[counter] = str[i] - '0';
|
||||
counter++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
39
Rush/Rush01/main.c
Normal file
39
Rush/Rush01/main.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/24 19:36:07 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/24 20:19:00 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_print(int *tab, int size);
|
||||
int *ft_gen(int size);
|
||||
int *ft_input(char *str);
|
||||
void *ft_printf(char *str);
|
||||
int *ft_verif(int *tab_user, int *tab_gen, int size)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int *gen_tab;
|
||||
int *user_tab;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
ft_printf("error");
|
||||
return (0);
|
||||
}
|
||||
user_tab = ft_input(argv[1]);
|
||||
if (user_tab[0] == 0)
|
||||
{
|
||||
ft_printf("error");
|
||||
return (0);
|
||||
}
|
||||
gen_tab = ft_gen(4);
|
||||
ft_verif(gen_tab, user_tab, 4);
|
||||
ft_print(gen_tab, 4);
|
||||
return (1);
|
||||
}
|
Reference in New Issue
Block a user