Merge 42-piscine-c with full history

This commit is contained in:
Jack 2026-01-29 18:04:57 -03:00
commit 50e14c8b79
No known key found for this signature in database
414 changed files with 37723 additions and 0 deletions

1
42-piscine-c/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*a.out

5
42-piscine-c/README.md Normal file
View file

@ -0,0 +1,5 @@
# 42 piscine C, août 2016.
<img src="https://raw.githubusercontent.com/jzck/42-piscine-c/master/img/25-08-16.png">
Correction automatique des jours avec : https://github.com/jzck/42-correction-jhalford

35
42-piscine-c/bsq/Makefile Normal file
View file

@ -0,0 +1,35 @@
NAME = bsq
CC = gcc
D_SRC = src
D_INC = includes
D_OBJ = obj
O_FLAGS = -O3
W_FLAGS = -Wall -Wextra -Werror
DEBUG =
MKDIR = mkdir -p
RM = /bin/rm -rf
F_SRC := $(shell ls -1 $(D_SRC) | grep .c$$)
F_OBJ := $(F_SRC:.c=.o)
F_OBJ := $(addprefix $(D_OBJ)/, $(F_OBJ))
.PHONY: all clean fclean re
all: $(NAME)
$(D_OBJ)/%.o: $(D_SRC)/%.c $(D_INC)
@$(MKDIR) $(D_OBJ)
$(CC) -I$(D_INC) $(O_FLAGS) $(W_FLAGS) -c $< -o $@ $(DEBUG)
$(NAME): $(F_OBJ)
$(CC) -I$(D_INC) $(O_FLAGS) $(W_FLAGS) $(F_OBJ) -o $@ $(DEBUG)
clean:
$(RM) $(D_OBJ)
fclean: clean
$(RM) $(NAME)
re: fclean all

1
42-piscine-c/bsq/auteur Normal file
View file

@ -0,0 +1 @@
elacaill:jhalford

BIN
42-piscine-c/bsq/bsq Executable file

Binary file not shown.

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.bsq</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

Binary file not shown.

View file

@ -0,0 +1,10 @@
9.ox
...........................
....o......................
............o..............
...........................
....o......................
...............o...........
...........................
......o..............o.....
..o.......o................

View file

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

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,401 @@
400 .x
. . .
.
. .
. . .
. .
.
.
.
. .
. .
.
.
. .
.
. .
.
.
.
.
.
. .
.
. .
. . . .
.
.
. . .
. .
.
.
.
.
.
.
.
. .
.
. .
. .
. . .
. .
.
.
.
. .
.
.
.
. .
.
. .
.
.
.
.
.
.
. .
.
.
. .
.
. .
.. .
.
.
.
. .
.
.
.
. .
. .
.
.
.
. .
.
.
.
. . .
.
. . . .
. .
.
. . .
. .
. . . .
. .
. .
. . .
.
.
. . .
.
.
. .
. .
.
. .
.
. .
. . .
. .
.
. .
.
. .
. .
. . . . .
.
.
.
. .
.
.
. .
.
.
. .
. .
. . .
. . .
.
.
.
. .
.
. .
. .
. .
.
.
.
. .
. .
.
.
. .
.
. .
.
. .
.
.
. .
.
.
. .
.
.
.
. .
.
.
.
. . .
. .
.
.
. .
.
.
.
.
.
.
.
.
.
.
.
.
. . . .
. .
. .
. .
. .
. .
. .
.
.
.
. .
.
.
.
. .
.
. . .
. .
.
. .
.
. .
.
.
.
.
.
.
.
. . .
. .
. .
.
.
. . . .
. .
.
.
.
.
.
.
.
. .
.
.
.
.
. . .
.
.
. .
. .
.
. .
. . .
. .
.
.
.
. .
.
.
. .
. . .
.
. .
.
.
. .
.

20
42-piscine-c/bsq/gen 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";
}

View file

@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* header.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/20 20:55:19 by jhalford #+# #+# */
/* Updated: 2016/08/24 17:28:49 by elacaill ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HEADER_H
# define HEADER_H
# define BUF_SIZE 4096
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <fcntl.h>
typedef struct s_data
{
unsigned char vide;
unsigned char obstacle;
unsigned char plein;
int size;
} t_data;
typedef struct s_square
{
int x;
int y;
int size;
} t_square;
int ft_bsq(char **grid);
char **ft_split_nl(char *str);
void ft_putchar(char c);
void ft_putstr(char *str);
void ft_print_grid(char **grid);
void ft_print_sol(char **grid, t_square sol, char x);
int min(int a, int b, int c);
int ft_strlen(char *str);
char *ft_strdup(char *src);
char *ft_strcat(char *dest, char *src);
char *ft_strcpy(char *dest, char *src);
int ft_strcmp(char *s1, char *s2);
int ft_atoi(char *str);
#endif

View file

@ -0,0 +1,115 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bsq_lib.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/22 10:50:03 by jhalford #+# #+# */
/* Updated: 2016/08/25 00:06:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
int *ft_dimension(char **grid, char a1, char a2)
{
int *dim;
int i;
dim = (int *)malloc(sizeof(int) * 2);
dim[0] = 0;
dim[1] = 0;
while (grid[dim[1]])
{
i = 0;
while (grid[dim[1]][i])
{
if (grid[dim[1]][i] != a1 && grid[dim[1]][i] != a2)
return (NULL);
i++;
}
if (dim[1] == 0)
dim[0] = i;
if (i != dim[0])
return (NULL);
dim[1]++;
}
return (dim);
}
int ft_update(int is_vide, int *i, int *a[2], t_square *sol)
{
int out;
if (i[0] == 0 || i[1] == 0)
out = (is_vide) ? 1 : 0;
else
out = (is_vide) ?
(1 + min(a[1][i[1] - 1], a[0][i[1] - 1], a[0][i[1]])) : 0;
if (out > sol->size)
{
sol->x = i[1];
sol->y = i[0];
sol->size = out;
}
return (out);
}
t_square ft_solve(char **grid, char vide, int x, int y)
{
int *a[2];
int i[2];
t_square sol;
sol.size = 0;
a[0] = (int *)(malloc(sizeof(int) * (x + 1)));
a[1] = (int *)(malloc(sizeof(int) * (x + 1)));
i[0] = -1;
while (++i[0] < y)
{
i[1] = -1;
while (++i[1] < x)
{
a[1][i[1]] = ft_update((grid[i[0]][i[1]] == vide), i, a, &sol);
if (i[1] > 0)
a[0][i[1] - 1] = a[1][i[1] - 1];
}
a[0][i[1] - 1] = a[1][i[1] - 1];
}
free(a[0]);
free(a[1]);
return (sol);
}
t_data ft_parse_data(char *str)
{
t_data out;
int len;
len = ft_strlen(str);
out.plein = str[len - 1];
out.obstacle = str[len - 2];
out.vide = str[len - 3];
str[len - 3] = '\0';
out.size = ft_atoi(str);
return (out);
}
int ft_bsq(char **grid)
{
t_square sol;
t_data data;
int *dim;
data = ft_parse_data(grid[0]);
grid++;
if (!(dim = ft_dimension(grid, data.vide, data.obstacle)))
return (1);
if (data.size != dim[1])
return (1);
sol = ft_solve(grid, data.vide, dim[0], dim[1]);
ft_print_sol(grid, sol, data.plein);
free(dim);
return (0);
}

View file

@ -0,0 +1,106 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_whitespaces.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/11 18:03:51 by jhalford #+# #+# */
/* Updated: 2016/08/23 12:53:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#define SEP(x) (x=='\n')
char **alloc_table(char **table, char *str)
{
int i;
int n_words;
i = 0;
n_words = 0;
while (SEP(str[i]))
i++;
while (str[i] != '\0')
{
i++;
if (SEP(str[i]))
{
n_words++;
while (SEP(str[i]))
i++;
}
}
if (!SEP(str[i - 1]))
n_words++;
table = (char**)malloc(sizeof(*table) * (n_words + 10));
table[n_words] = 0;
return (table);
}
char **alloc_words(char **table, char *str)
{
int i;
int j;
int k;
i = 0;
j = 0;
k = 0;
while (SEP(str[i]))
i++;
while (str[i] != '\0')
{
i++;
if (SEP(str[i]) || !str[i])
{
table[j] = (char*)malloc(sizeof(**table) * (k + 10));
j++;
k = 0;
while (SEP(str[i]))
i++;
}
k++;
}
return (table);
}
char **fill_table(char **table, char *str)
{
int i;
int j;
int k;
i = 0;
j = 0;
k = 0;
while (SEP(str[i]))
i++;
while (str[i] != '\0')
{
table[j][k] = str[i];
i++;
k++;
if (SEP(str[i]) || !str[i])
{
table[j][k] = '\0';
j++;
k = 0;
while (SEP(str[i]))
i++;
}
}
return (table);
}
char **ft_split_nl(char *str)
{
char **table;
table = 0;
table = alloc_table(table, str);
table = alloc_words(table, str);
table = fill_table(table, str);
return (table);
}

View file

@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elacaill <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/24 14:20:18 by elacaill #+# #+# */
/* Updated: 2016/08/25 11:21:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
char *ft_read_std(int fd)
{
char buf[BUF_SIZE + 1];
int ret;
long size_str;
char *temp;
char *res;
size_str = 0;
if (fd == -1)
return ("0\n0");
res = (char *)malloc(42);
*res = '\0';
while ((ret = read(fd, buf, BUF_SIZE)))
{
temp = ft_strdup(res);
free(res);
size_str += ret;
res = (char*)malloc(sizeof(char) * (size_str + 1));
*res = '\0';
buf[ret] = '\0';
ft_strcat(res, temp);
ft_strcat(res, buf);
free(temp);
}
close(fd);
return (res);
}
char ***ft_fill_grid(int ac, char **av)
{
int i;
int fd;
char *str;
char ***grid_ptr;
grid_ptr = (char***)malloc(sizeof(char**) * (ac + 1));
i = 1;
if (ac == 1)
{
str = ft_read_std(0);
*grid_ptr = ft_split_nl(str);
if (str)
free(str);
grid_ptr[1] = NULL;
}
while (i < ac)
{
fd = open(av[i], O_RDONLY);
str = ft_read_std(fd);
grid_ptr[i - 1] = ft_split_nl(str);
grid_ptr[i] = NULL;
i++;
}
return (grid_ptr);
}
int main(int ac, char **av)
{
int i;
int j;
char ***grid_ptr;
grid_ptr = ft_fill_grid(ac, av);
i = 0;
while (grid_ptr[i])
{
if (ft_bsq(grid_ptr[i]))
ft_putstr("map error\n");
j = 0;
while (grid_ptr[i][j])
free(grid_ptr[i][j++]);
free(grid_ptr[i]);
i++;
if (ac > 2 && grid_ptr[i])
ft_putchar('\n');
}
free(grid_ptr);
return (0);
}

View file

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/24 17:15:57 by jhalford #+# #+# */
/* Updated: 2016/08/24 17:37:47 by elacaill ### ########.fr */
/* */
/* ************************************************************************** */
int min(int a, int b, int c)
{
int m;
m = a;
if (m > b)
m = b;
if (m > c)
m = c;
return (m);
}
int ft_atoi(char *str)
{
int if_negativ;
int count;
int num;
if_negativ = 0;
count = 0;
num = 0;
while (str[0] == ' ')
str++;
if (str[0] == '-')
if_negativ = 1;
if (str[0] == '+' || str[0] == '-')
str++;
while ((str[count] >= '0' && str[count] <= '9'))
{
num += str[count] - 48;
if (str[count + 1] >= '0' && str[count + 1] <= '9')
num *= 10;
count++;
}
if (if_negativ == 1)
return (-num);
return (num);
}

View file

@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/21 15:31:30 by jhalford #+# #+# */
/* Updated: 2016/08/24 17:25:52 by elacaill ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
write(1, str, ft_strlen(str));
}
void ft_print_grid(char **grid)
{
int i;
i = 0;
while (grid[i])
{
ft_putstr(grid[i]);
ft_putchar('\n');
i++;
}
}
void ft_print_sol(char **grid, t_square sol, char x)
{
int i;
int j;
i = sol.y;
while (i >= 0 && i > sol.y - sol.size)
{
j = sol.x;
while (j >= 0 && j > sol.x - sol.size)
{
grid[i][j] = x;
j--;
}
i--;
}
ft_print_grid(grid);
}

View file

@ -0,0 +1,96 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utilities.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/20 23:16:36 by jhalford #+# #+# */
/* Updated: 2016/08/24 17:29:15 by elacaill ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <unistd.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
i = 0;
while (dest[i] != '\0')
i++;
j = 0;
while (src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
int ft_strcmp(char *s1, char *s2)
{
int cmp;
int i;
i = 0;
cmp = 0;
while (1)
{
cmp += (s1[i] - s2[i]);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++;
else
return (cmp);
}
}
char *ft_strdup(char *src)
{
char *dup;
int size;
int i;
i = 0;
size = 0;
while (src[size] != '\0')
size++;
dup = (char*)malloc(sizeof(*dup) * (size + 1));
while (src[i] != '\0')
{
dup[i] = src[i];
i++;
}
dup[i] = '\0';
return (dup);
}

View file

@ -0,0 +1,42 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2015/07/29 11:06:57 by jcamhi #+# #+# #
# Updated: 2015/07/30 20:23:56 by jcamhi ### ########.fr #
# #
# **************************************************************************** #
NAME = bsq
SRC = ft_atoi.c \
ft_io.c \
ft_string.c \
handle_input.c \
main.c \
solver.c \
input2.c
TMP = ft_atoi.o \
ft_io.o \
ft_string.o \
handle_input.o \
main.o \
solver.o \
input2.o
all: $(NAME)
$(NAME):
gcc -Wall -Werror -Wextra -c $(SRC)
gcc -Wall -Werror -Wextra -o $(NAME) $(TMP)
clean:
rm -f $(TMP)
fclean: clean
rm -f $(NAME)
re: fclean all

View file

@ -0,0 +1 @@
magouin:jcamhi

View file

@ -0,0 +1,97 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: exam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/17 18:14:25 by exam #+# #+# */
/* Updated: 2015/07/30 17:44:56 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
#include <stdlib.h>
char *ft_astrcpy(char *src)
{
char *rez;
int i;
rez = malloc(sizeof(char *) * (ft_strlen(src) + 1));
i = 0;
while (src[i] != '\0')
{
rez[i] = src[i];
i++;
}
return (rez);
}
int boucle(char **t, char *c, int *is_sign, int *i)
{
*i = 0;
*is_sign = 0;
*c = *t[*i];
while ((*c < '0' || *c > '9') && *is_sign == 0)
{
if (*c != 9 && *c != 10 && *c != 11 && *c != 12 && *c != 13 && *c != 32
&& *c != '-' && *c != '+')
return (0);
if (*c == '-' || *c == '+')
*is_sign = 1;
*i = *i + 1;
*c = t[0][*i];
}
return (1);
}
char *ft_isolate_number(char *t)
{
int i;
char c;
int j;
int is_sign;
is_sign = 0;
if (boucle(&t, &c, &is_sign, &i) == 0)
return (0);
if (is_sign == 1 && (t[i] < '0' || t[i] > '9'))
return (0);
if (is_sign == 1)
i--;
j = 0;
while ((t[i + j] >= '0'
&& t[i + j] <= '9') || (t[i + j] == '-' || t[i + j] == '+'))
j++;
t[i + j] = '\0';
return (t + i);
}
int ft_atoi(char *s)
{
int mult;
int i;
int hund;
int rez;
char *s2;
s2 = ft_astrcpy(s);
hund = 1;
rez = 0;
mult = 1;
s2 = ft_isolate_number(s2);
if (s == 0)
return (0);
i = ft_strlen(s2) - 1;
if (s[0] == '-')
mult = -1;
while (i >= 0 && s2[i] != '-' && s2[i] != '+')
{
rez += (s2[i] - '0') * hund;
i--;
hund *= 10;
}
free (s2);
return (rez * mult);
}

View file

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_io.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: magouin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 20:03:37 by magouin #+# #+# */
/* Updated: 2015/07/30 21:15:55 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_io.h"
void recursifg(int **tab, int x, int y, int value)
{
if (tab[y][x] > value)
{
tab[y][x] = value;
if (x != 0 && y != g_dimension[0] - 1)
recursifg(tab, x - 1, y + 1, value + 1);
if (x != 0)
recursifg(tab, x - 1, y, value + 1);
if (x != 0 && y != 0)
recursifg(tab, x - 1, y - 1, value + 1);
}
}
void recursifd(int **tab, int x, int y, int value)
{
if (tab[y][x] > value)
{
tab[y][x] = value;
if (x != g_dimension[1] - 1 && y != g_dimension[0] - 1)
recursifd(tab, x + 1, y + 1, value + 1);
if (x != g_dimension[1] - 1)
recursifd(tab, x + 1, y, value + 1);
if (x != g_dimension[1] - 1 && y != 0)
recursifd(tab, x + 1, y - 1, value + 1);
}
}
void recursifh(int **tab, int x, int y, int value)
{
if (tab[y][x] > value)
{
tab[y][x] = value;
if (x != g_dimension[1] - 1 && y != 0)
recursifh(tab, x + 1, y - 1, value + 1);
if (y != 0)
recursifh(tab, x, y - 1, value + 1);
if (x != 0 && y != 0)
recursifh(tab, x - 1, y - 1, value + 1);
}
}
void recursifb(int **tab, int x, int y, int value)
{
if (tab[y][x] > value)
{
tab[y][x] = value;
if (x != g_dimension[1] - 1 && y != g_dimension[0] - 1)
recursifb(tab, x + 1, y + 1, value + 1);
if (y != g_dimension[0] - 1)
recursifb(tab, x, y + 1, value + 1);
if (x != 0 && y != g_dimension[0] - 1)
recursifb(tab, x - 1, y + 1, value + 1);
}
}

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_io.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 09:36:44 by jcamhi #+# #+# */
/* Updated: 2015/07/30 21:23:33 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_IO_H
# define FT_IO_H
# include <stdlib.h>
# include <unistd.h>
# define BUFF_SIZE 2
int g_dimension[2];
int first_line(char *vide, char *plein, char *obstacle, int fd);
int handle_first_buff(char *s, char *block, int **tab, int i);
int ft_atoi(char *s);
void make_cadre(int **tab, int target, int longueur, int hauteur);
void percolation(int **tab, int x, int y);
void print_tab(int **tab, int longueur, int hauteur);
void recursifg(int **tab, int x, int y, int value);
void recursifd(int **tab, int x, int y, int value);
void recursifh(int **tab, int x, int y, int value);
void recursifb(int **tab, int x, int y, int value);
char *get_dim(int fd);
int **make_tab(void);
int **handle_buffer(char *block, int fd);
void print_result(int **tab, int *max, char *block);
char *ft_update(char *buff, char *s, int *taille, int r);
char *ft_update2(char *buff, char *tmp);
#endif

View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 08:48:55 by jcamhi #+# #+# */
/* Updated: 2015/07/30 20:45:22 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *s)
{
int i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
char *ft_malloc_zero(int nb)
{
char *s;
int i;
s = malloc(nb * sizeof(char));
if (s == NULL)
return (0);
i = 0;
while (i < nb - 1)
{
s[i] = '0';
i++;
}
s[i] = '\0';
return (s);
}
char *ft_append(char *s1, char *s2)
{
int i;
int j;
char *rez;
rez = ft_malloc_zero(ft_strlen(s1) + ft_strlen(s2) + 1);
i = 0;
while (s1[i] != '\0')
{
rez[i] = s1[i];
i++;
}
j = 0;
while (s2[j] != '\0')
{
rez[i] = s2[j];
j++;
i++;
}
rez[i] = '\0';
return (rez);
}
void ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != '\0' && dest[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_string.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 08:50:34 by jcamhi #+# #+# */
/* Updated: 2015/07/30 21:10:04 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_STRING_H
# define FT_STRING_H
char *ft_append(char *s1, char *s2);
void ft_strcpy(char *dest, char *src);
char *ft_malloc_zero(int nb);
int ft_strlen(char *s);
int **trans_tab(char *tab, int heigth, int width, char vide, char obstacle);
#endif

17
42-piscine-c/bsq_magouin/gen Executable file
View file

@ -0,0 +1,17 @@
#!/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";
}

View file

@ -0,0 +1,134 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 08:42:27 by jcamhi #+# #+# */
/* Updated: 2015/07/30 23:27:09 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
#include "ft_io.h"
int **handle_buffer(char *block, int fd)
{
char *s;
int i;
int r;
char buff[BUFF_SIZE + 1];
int **tab;
s = get_dim(fd);
if (s == 0)
return (NULL);
tab = make_tab();
i = 0;
i = handle_first_buff(s, block, tab, i);
if (i == -1)
return (NULL);
while ((r = read(fd, buff, BUFF_SIZE)))
{
buff[r] = '\0';
i = handle_first_buff(buff, block, tab, i);
if (i == -1)
return (NULL);
}
return (tab);
}
int fif(char *s, int j, int *lastnl)
{
if (s[j] == '\n')
{
if (*lastnl != g_dimension[1])
{
*lastnl = 0;
return (-1);
}
*lastnl = 0;
}
return (0);
}
int handle_first_buff(char *s, char *block, int **tab, int i)
{
int j;
static int lastnl = 0;
j = 0;
while (s[j] != '\0')
{
if (s[j] != block[0] && s[j] != block[2] && s[j] != '\n')
{
lastnl = 0;
return (-1);
}
if (s[j] == block[2])
percolation(tab, (i + j) % (g_dimension[1] + 1),
(i + j) / (g_dimension[1] + 1));
if (fif(s, j, &lastnl) == -1)
return (-1);
if (s[j] != '\n')
lastnl++;
j++;
}
return (i + j);
}
char *get_dim(int fd)
{
int r[2];
char buff[BUFF_SIZE + 1];
char *s1;
int taille;
taille = 0;
s1 = ft_malloc_zero(taille + 1);
while ((r[0] = read(fd, buff, BUFF_SIZE)))
{
g_dimension[1] = 0;
s1 = ft_update(buff, s1, &taille, r[0]);
r[1] = 0;
while (s1[r[1]] != '\0')
{
if (s1[r[1]] == '\n')
{
return (s1);
}
g_dimension[1] = g_dimension[1] + 1;
r[1]++;
}
}
return (0);
}
int first_line(char *vide, char *pleine, char *obstacle, int fd)
{
char buff[2];
char *tmp;
int r;
tmp = ft_malloc_zero(1);
r = read(fd, buff, 1);
if (r == 0 || (buff[0] < '1' || buff[0] > '9'))
return (-1);
buff[r] = '\0';
while (buff[0] <= '9' && buff[0] >= '0')
{
tmp = ft_update2(buff, tmp);
r = read(fd, buff, 1);
buff[r] = '\0';
}
g_dimension[0] = atoi(tmp);
free(tmp);
vide[0] = buff[0];
read(fd, pleine, 1);
read(fd, obstacle, 1);
r = read(fd, buff, 1);
if (r == 0 || buff[0] != '\n')
return (-1);
return (0);
}

View file

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/30 20:09:11 by jcamhi #+# #+# */
/* Updated: 2015/07/30 21:09:03 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
#include "ft_io.h"
char *ft_update(char *buff, char *s, int *taille, int r)
{
char *tmp;
buff[r] = '\0';
*taille = *taille + r;
tmp = ft_malloc_zero(*taille + 1);
ft_strcpy(tmp, s);
free(s);
s = ft_malloc_zero(*taille + 1);
ft_strcpy(s, tmp);
s = ft_append(s, buff);
free(tmp);
return (s);
}
char *ft_update2(char *buff, char *tmp)
{
char *s2;
static int taille = 0;
taille = taille + 1;
s2 = ft_malloc_zero(taille + 1);
ft_strcpy(s2, tmp);
free(tmp);
tmp = ft_malloc_zero(taille + 1);
ft_strcpy(tmp, s2);
tmp = ft_append(tmp, buff);
free(s2);
return (tmp);
}

View file

@ -0,0 +1,142 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jcamhi <jcamhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 12:33:02 by jcamhi #+# #+# */
/* Updated: 2015/07/30 23:25:21 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_io.h"
#include "string.h"
#include <stdlib.h>
#include "ft_string.h"
#include <fcntl.h>
#define MIN(x,y) (x > y ? y : x)
int g_dimension[2];
void foret_de_if(int **tab, int *max, int x, int y)
{
if (max[2] < tab[y][x])
{
max[2] = tab[y][x];
max[0] = x;
max[1] = y;
max[3] = 0;
}
if (x + 1 != g_dimension[1] && y + 1 != g_dimension[0]
&& max[2] == tab[y][x]
&& max[2] == tab[y + 1][x + 1] && max[2] == tab[y][x + 1]
&& max[2] == tab[y + 1][x] && max[3] != 1)
{
max[0] = x;
max[1] = y;
max[3] = 1;
}
}
int *print_rez(int **tab)
{
int *max;
int x;
int y;
max = malloc(sizeof(int) * 4);
max[0] = 0;
max[1] = 0;
max[2] = 0;
max[3] = 0;
y = 0;
while (y < g_dimension[0])
{
x = 0;
while (x < g_dimension[1])
{
foret_de_if(tab, max, x, y);
x++;
}
y++;
}
return (max);
}
void sinon(int **tab, char block[], int fd[], char **argv)
{
fd[1] = 1;
while (fd[1] < fd[2])
{
fd[0] = open(argv[fd[1]], O_RDONLY);
if (fd[0] == -1)
write(2, "map error\n", 10);
if (first_line(block, block + 2, block + 1, fd[0]) == -1)
write(2, "map error\n", 10);
else
{
tab = NULL;
if (g_dimension[0])
tab = handle_buffer(block, fd[0]);
if (tab == NULL)
write(2, "map error", 9);
else
print_result(tab, print_rez(tab), block);
close(fd[0]);
write(1, "\n", 1);
}
fd[1]++;
}
}
int main(int argc, char **argv)
{
char block[3];
int **tab;
int fd[3];
fd[2] = argc;
tab = NULL;
if (argc == 1)
{
if (first_line(block, block + 2, block + 1, 0) == -1)
{
write(2, "map error\n", 10);
return (0);
}
tab = handle_buffer(block, 0);
if (tab == NULL)
write(2, "map error\n", 10);
else
print_result(tab, print_rez(tab), block);
}
else
sinon (tab, block, fd, argv);
return (0);
}
int **make_tab(void)
{
int a;
int **tab;
int x;
int y;
y = g_dimension[0];
x = g_dimension[1];
a = 0;
tab = malloc(sizeof(int*) * y);
while (a < y)
{
tab[a] = malloc(sizeof(int) * x);
a++;
}
a = 0;
while (a != MIN((x + 1) / 2, (y + 1) / 2))
{
make_cadre(tab, a, x, y);
a++;
}
return (tab);
}

View file

@ -0,0 +1,108 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solver.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: magouin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/07/28 19:16:21 by magouin #+# #+# */
/* Updated: 2015/07/30 21:17:03 by jcamhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_io.h"
void make_cadre(int **tab, int target, int longeur, int hauteur)
{
int a;
int b;
a = target;
b = target;
while (a < longeur - target)
{
tab[b][a] = target + 1;
a++;
}
a--;
while (b < hauteur - target)
{
tab[b][a] = target + 1;
b++;
}
b--;
while (--a >= target)
tab[b][a] = target + 1;
a++;
while (--b >= target)
tab[b][a] = target + 1;
}
void affiche(int **tab, char *block)
{
int x;
int y;
y = 0;
while (y < g_dimension[0])
{
x = 0;
while (x < g_dimension[1])
{
if (tab[y][x] == 0)
write(1, block + 2, 1);
else if (tab[y][x] == -1)
write(1, block + 1, 1);
else
write(1, block, 1);
x++;
}
write(1, "\n", 1);
y++;
}
}
void print_result(int **tab, int *max, char *block)
{
int x;
int y;
max[2]--;
y = max[1] - max[2];
while (y <= max[1] + max[2] + max[3])
{
x = max[0] - max[2];
while (x <= max[0] + max[2] + max[3])
{
tab[y][x] = -1;
x++;
}
y++;
}
affiche(tab, block);
}
void percolation(int **tab, int x, int y)
{
tab[y][x] = 0;
if (x != 0)
{
tab[y][x] = 1;
recursifg(tab, x, y, 0);
}
if (x != g_dimension[1] - 1)
{
tab[y][x] = 1;
recursifd(tab, x, y, 0);
}
if (y != 0)
{
tab[y][x] = 1;
recursifh(tab, x, y, 0);
}
if (y != g_dimension[0] - 1)
{
tab[y][x] = 1;
recursifb(tab, x, y, 0);
}
}

Binary file not shown.

Binary file not shown.

1
42-piscine-c/d00/ex02/test1 Executable file
View file

@ -0,0 +1 @@
000

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
0

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,5 @@
Credentials cache: API:19184
Principal: jhalford@42.FR
Issued Expires Principal
Aug 1 09:19:16 2016 Aug 1 19:19:16 2016 krbtgt/42.FR@42.FR

View file

@ -0,0 +1 @@
ldapwhoami -Q | sed 's/dn://'

View file

@ -0,0 +1 @@
ldapsearch -QLLL "(uid=z*)" cn | sed -n '/cn:/p' | sed 's/cn: //g' | sort -r -f

View file

@ -0,0 +1,4 @@
dn: uid=jhalford,ou=2016_paris,ou=2016,ou=paris,ou=people,dc=42,dc=fr
changetype: modify
add: mobile
mobile: 0603727540

1
42-piscine-c/d00/ex07/midLS Executable file
View file

@ -0,0 +1 @@
ls -mpt

1
42-piscine-c/d00/ex08/z Normal file
View file

@ -0,0 +1 @@
Z

11
42-piscine-c/d00/ex09/b Normal file
View file

@ -0,0 +1,11 @@
Episode V, A NEW H0PE It is a period of civil war
Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.
During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet.
Pursued by the Empire's sinister agents,
Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie..

1
42-piscine-c/d00/ex10/clean Executable file
View file

@ -0,0 +1 @@
find . \( -name '*~' -o -name '#*#' \) -print -delete

View file

@ -0,0 +1 @@
42 string 42 42 file

View file

@ -0,0 +1 @@
groups $FT_USER | sed 's/ /,/g' | tr -d '\n'

View file

@ -0,0 +1 @@
find . -name "*.sh" -exec basename {} \; | rev | cut -c 4- | rev

View file

@ -0,0 +1 @@
echo `find . -type f -or -type d | wc -l`

1
42-piscine-c/d01/ex04/MAC.sh Executable file
View file

@ -0,0 +1 @@
ifconfig | grep ether | sed "s/ether//g" | tr -d "\t" | sed "s/ //g"

View file

@ -0,0 +1 @@
42

1
42-piscine-c/d01/ex06/skip.sh Executable file
View file

@ -0,0 +1 @@
ls -l | sed 'n;d'

View file

@ -0,0 +1 @@
cat /etc/passwd | grep -v \# | sed -n "n;p;d" | sed -E 's/:.*//g' | rev | sort -r | head -${FT_LINE2} | tail -$(($FT_LINE2 - $FT_LINE1 + 1)) | tr "\n" "," | sed 's/,/, /g' | sed 's/\(.*\), /\1./' | tr -d "\n"

1
42-piscine-c/d01/ex08/bon.sh Executable file
View file

@ -0,0 +1 @@
ldapsearch -QLLL "cn=*bon*" cn | sed -n '/cn:/p' | grep 'BON' | wc -l | sed 's: *::g'

View file

@ -0,0 +1 @@
echo $FT_NBR1 + $FT_NBR2 | tr "mrdoc" "01234" | tr "'\"?\!\\" "02341" | xargs echo "obase=13; ibase=5;" | bc | tr "0123456789ABC" "gtaio luSnemf"

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 20:50:06 by jhalford #+# #+# */
/* Updated: 2016/08/07 17:10:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_print_alphabet(void)
{
char c;
c = 'a';
while (c <= 'z')
{
ft_putchar(c);
c++;
}
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 20:54:50 by jhalford #+# #+# */
/* Updated: 2016/08/03 19:38:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_print_reverse_alphabet(void)
{
char c;
c = 'z';
while (c >= 'a')
{
ft_putchar(c);
c--;
}
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 20:55:29 by jhalford #+# #+# */
/* Updated: 2016/08/03 19:39:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_print_numbers(void)
{
char c;
c = '0';
while (c <= '9')
{
ft_putchar(c);
c++;
}
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_negative.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 20:55:40 by jhalford #+# #+# */
/* Updated: 2016/08/03 19:39:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_is_negative(int n)
{
if (n < 0)
ft_putchar('N');
else
ft_putchar('P');
}

View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 20:56:47 by jhalford #+# #+# */
/* Updated: 2016/08/03 20:07:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_print_comb(void)
{
char ch1;
char ch2;
char ch3;
ch1 = '0' - 1;
while (++ch1 <= '9')
{
ch2 = ch1;
while (++ch2 <= '9')
{
ch3 = ch2;
while (++ch3 <= '9')
{
if (ch1 != '0' || ch2 != '1' || ch3 != '2')
ft_putchar(',');
if (ch1 != '0' || ch2 != '1' || ch3 != '2')
ft_putchar(' ');
ft_putchar(ch1);
ft_putchar(ch2);
ft_putchar(ch3);
}
}
}
}

View file

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_comb2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 21:12:55 by jhalford #+# #+# */
/* Updated: 2016/08/04 20:56:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_my_putnbr(int nb)
{
int tmp;
int size;
size = 1;
if (nb < 0)
{
ft_putchar('-');
nb = -nb;
}
tmp = nb;
while (tmp > 9)
{
tmp /= 10;
size *= 10;
}
tmp = nb;
while (size > 0)
{
ft_putchar((char)(tmp / size) + 48);
tmp %= size;
size /= 10;
}
}
void ft_put_comb(int a, int b)
{
if (a != 0 || b != 1)
ft_putchar(',');
if (a != 0 || b != 1)
ft_putchar(' ');
if (a < 10)
ft_putchar('0');
if (a < 10)
ft_putchar(a + '0');
else
ft_my_putnbr(a);
ft_putchar(' ');
if (b < 10)
ft_putchar('0');
if (b < 10)
ft_putchar(b + '0');
else
ft_my_putnbr(b);
}
void ft_print_comb2(void)
{
int a;
int b;
a = 0;
while (a < 99)
{
b = a + 1;
while (b <= 99)
{
ft_put_comb(a, b);
b++;
}
a++;
}
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:00:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_putnbr(int a)
{
if (a == -2147483648)
{
ft_putchar('-');
ft_putchar('2');
ft_putnbr(147483648);
return ;
}
else if (a < 0)
{
ft_putchar('-');
a = -a;
}
if (a >= 10)
{
ft_putnbr(a / 10);
ft_putnbr(a % 10);
}
else
ft_putchar(a + '0');
}

View file

@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_combn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 21:35:28 by jhalford #+# #+# */
/* Updated: 2016/08/06 21:58:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_print_tab(int *tab, int n)
{
int i;
i = 0;
while (i < n)
{
ft_putchar(tab[i] + '0');
i++;
}
}
void ft_pour_la_norme07(int *tab, int col, int n)
{
int i;
while (1)
{
while (tab[col] == (9 + col - (n - 1)) && col >= 0)
col--;
if (col < 0)
break ;
tab[col]++;
i = col + 1;
while (i <= n)
{
tab[i] = tab[i - 1] + 1;
i++;
}
col = n - 1;
ft_putchar(',');
ft_putchar(' ');
ft_print_tab(tab, n);
}
}
void ft_print_combn(int n)
{
int tab[n];
int i;
int col;
col = n - 1;
if (n > 10)
return ;
i = 0;
while (i <= n)
{
tab[i] = i;
i++;
}
ft_print_tab(tab, n);
ft_pour_la_norme07(tab, col, n);
}

View file

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:05:07 by jhalford #+# #+# */
/* Updated: 2016/08/03 16:06:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ft(int *nbr)
{
*nbr = 42;
return ;
}

View file

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:10:31 by jhalford #+# #+# */
/* Updated: 2016/08/03 17:59:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
return ;
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:14:44 by jhalford #+# #+# */
/* Updated: 2016/08/03 18:25:37 by jhalford ### ########.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: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:11:10 by jhalford #+# #+# */
/* Updated: 2016/08/03 18:21:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:11:51 by jhalford #+# #+# */
/* Updated: 2016/08/03 16:11:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int tmp;
tmp = *a;
*a /= *b;
*b = tmp % *b;
}

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:13:07 by jhalford #+# #+# */
/* Updated: 2016/08/03 18:29:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c);
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
ft_putchar(str[i++]);
}

View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:14:15 by jhalford #+# #+# */
/* Updated: 2016/08/03 16:14:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:15:09 by jhalford #+# #+# */
/* Updated: 2016/08/20 17:50:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strrev(char *str)
{
int len;
char tmp;
int i;
i = 0;
len = 0;
while (str[len] != '\0')
len++;
while (i < len / 2)
{
tmp = str[len - (i + 1)];
str[len - (i + 1)] = str[i];
str[i] = tmp;
i++;
}
return (str);
}

View file

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:00:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_whitespace(char c)
{
if (c == ' ' || c == '\t' || c == '\n')
return (1);
else if (c == '\v' || c == '\f' || c == '\r')
return (1);
else
return (0);
}
int ft_atoi(char *str)
{
int i;
int res;
int sign;
i = 0;
res = 0;
sign = 1;
while (ft_is_whitespace(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i + 1] >= '0' && str[i + 1] <= '9')
{
sign = (str[i] == '+') ? 1 : -1;
i++;
}
else
return (0);
}
while (str[i] >= '0' && str[i] <= '9')
res = res * 10 + str[i++] - '0';
res *= sign;
return (res);
}

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_integer_table.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:56 by jhalford #+# #+# */
/* Updated: 2016/08/03 16:18:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_sort_integer_table(int *tab, int size)
{
int i;
int j;
int tmp;
i = 1;
while (i < size)
{
j = i;
while (j > 0)
{
if (tab[j] < tab[j - 1])
{
tmp = tab[j];
tab[j] = tab[j - 1];
tab[j - 1] = tmp;
}
j--;
}
i++;
}
}

View file

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 14:55:19 by jhalford #+# #+# */
/* Updated: 2016/08/05 10:39:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int i;
int f;
int fn;
i = 1;
f = 1;
fn = 1;
if (nb < 0)
return (0);
while (i <= nb)
{
fn = f * i;
if (fn / i != f)
return (0);
i++;
f = fn;
}
return (f);
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 15:04:45 by jhalford #+# #+# */
/* Updated: 2016/08/05 10:02:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
int f;
if (nb < 0)
return (0);
if (nb == 0)
return (1);
else
{
f = ft_recursive_factorial(nb - 1);
if ((nb * f) / nb != f)
return (0);
return (nb * f);
}
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 15:15:41 by jhalford #+# #+# */
/* Updated: 2016/08/05 10:48:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int i;
int nb_orig;
int nb_prev;
nb_orig = nb;
i = 1;
if (power < 0)
{
return (0);
}
if (power == 0)
return (1);
while (i < power)
{
nb_prev = nb;
nb *= nb_orig;
if (nb / nb_orig != nb_prev)
return (0);
i++;
}
return (nb);
}

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 15:32:21 by jhalford #+# #+# */
/* Updated: 2016/08/05 13:55:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
int nb_prev;
nb_prev = nb;
if (power < 0)
return (0);
else if (power == 0)
return (1);
else if (power == 1)
return (nb);
nb = ft_recursive_power(nb, power - 1);
return (nb * nb_prev);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/04 15:34:18 by jhalford #+# #+# */
/* Updated: 2016/08/05 13:58:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
int fibm;
int fibmm;
if (index >= 47)
return (0);
if (index < 0)
return (-1);
if (index == 0 || index == 1)
return (index);
fibm = ft_fibonacci(index - 1);
fibmm = ft_fibonacci(index - 2);
return (fibm + fibmm);
}

View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 10:52:22 by jhalford #+# #+# */
/* Updated: 2016/08/07 17:46:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#define SQ(x) (x * x)
int ft_sqrt(int nb)
{
int guess;
int low;
int high;
low = 0;
high = 46342;
while (1)
{
guess = (high + low) / 2;
if (SQ(guess) > nb)
high = guess;
else if (SQ(guess) < nb)
low = guess;
if (SQ(guess) == nb)
return (guess);
if ((high - low) <= 1)
{
return (0);
}
}
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 10:54:36 by jhalford #+# #+# */
/* Updated: 2016/08/07 17:42:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
if ((nb % 2 == 0 && nb != 2) || nb <= 1)
return (0);
i = 3;
while (i * i <= nb)
{
if ((nb % i) == 0)
return (0);
i += 2;
}
return (1);
}

View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 10:56:15 by jhalford #+# #+# */
/* Updated: 2016/08/07 17:45:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime2(int nb)
{
int i;
if ((nb % 2 == 0 && nb != 2) || nb <= 1)
return (0);
i = 3;
while (i * i <= nb)
{
if ((nb % i) == 0)
return (0);
i += 2;
}
return (1);
}
int ft_find_next_prime(int nb)
{
if (nb <= 2)
return (2);
nb += (nb % 2) ? 0 : 1;
while (!ft_is_prime2(nb))
nb += 2;
return (nb);
}

View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_eight_queens_puzzle.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 11:06:57 by jhalford #+# #+# */
/* Updated: 2016/08/05 11:07:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#define DIFF(a,b) ((a<b) ? (b-a) : (a-b))
int solve(int n, int col, int *hist)
{
int i;
int j;
int count;
count = 0;
if (col == n)
count++;
i = 0;
while (i < n)
{
j = 0;
while (j < col && !(hist[j] == i) && !(DIFF(hist[j], i) == col - j))
j++;
if (j < col)
{
i++;
continue;
}
hist[col] = i;
count += solve(n, col + 1, hist);
i++;
}
return (count);
}
int ft_eight_queens_puzzle(void)
{
int hist[8];
return (solve(8, 0, hist));
}

View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_eight_queens_puzzle_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/05 11:08:03 by jhalford #+# #+# */
/* Updated: 2016/08/05 15:03:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#define DIFF(a,b) ((a<b) ? (b-a) : (a-b))
void ft_putchar(char c);
void print_layout(int *list)
{
int i;
i = 0;
while (i < 8)
ft_putchar((char)list[i++] + 48 + 1);
ft_putchar('\n');
}
int solve_2(int n, int col, int *hist)
{
int i;
int j;
int count;
count = 0;
if (col == n)
count++;
if (col == n)
print_layout(hist);
i = 0;
while (i < n)
{
j = 0;
while (j < col && !(hist[j] == i) && !(DIFF(hist[j], i) == col - j))
j++;
if (j < col)
i++;
if (j < col)
continue;
hist[col] = i;
count += solve_2(n, col + 1, hist);
i++;
}
return (count);
}
int ft_eight_queens_puzzle_2(void)
{
int hist[8];
return (solve_2(8, 0, hist));
}

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:13:07 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:03:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c);
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
ft_putchar(str[i++]);
}

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/02 21:25:03 by jhalford #+# #+# */
/* Updated: 2016/08/04 21:28:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
void ft_putchar(char c);
void ft_putnbr(int a)
{
if (a == -2147483648)
{
ft_putchar('-');
ft_putchar('2');
ft_putnbr(147483648);
return ;
}
else if (a < 0)
{
ft_putchar('-');
a = -a;
}
if (a >= 10)
{
ft_putnbr(a / 10);
ft_putnbr(a % 10);
}
else
ft_putchar(a + '0');
}

View file

@ -0,0 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/08/07 18:10:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_whitespace(char c)
{
if (c == ' ' || c == '\t' || c == '\n')
return (1);
else if (c == '\v' || c == '\f' || c == '\r')
return (1);
else
return (0);
}
int ft_atoi(char *str)
{
int i;
int res;
int sign;
i = 0;
res = 0;
sign = 1;
while (ft_is_whitespace(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i + 1] >= '0' && str[i + 1] <= '9')
{
sign = (str[i] == '+') ? 1 : -1;
i++;
}
else
return (0);
}
while (str[i] >= '0' && str[i] <= '9')
res = res * 10 + str[i++] - '0';
res *= sign;
return (res);
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:12 by jhalford #+# #+# */
/* Updated: 2016/08/20 23:37:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:21 by jhalford #+# #+# */
/* Updated: 2016/08/07 10:48:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
int i;
i = 0;
while (src[i] != '\0' && i < (int)n)
{
dest[i] = src[i];
i++;
}
while (i < (int)n)
{
dest[i] = '\0';
i++;
}
return (dest);
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:48:35 by jhalford #+# #+# */
/* Updated: 2016/08/09 13:53:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strstr(char *str, char *to_find)
{
int i;
int j;
i = 0;
while (str[i] != '\0')
{
j = 0;
while (str[i + j] == to_find[j])
{
j++;
if (to_find[j] == '\0')
return (str + i);
}
i++;
}
return (0);
}

View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:02 by jhalford #+# #+# */
/* Updated: 2016/08/25 17:06:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strcmp(char *s1, char *s2)
{
int cmp;
int i;
i = 0;
cmp = 0;
while (1)
{
cmp += (s1[i] - s2[i]);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++;
else
return (cmp);
}
}

View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:12 by jhalford #+# #+# */
/* Updated: 2016/08/15 22:25:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
int size;
int cmp;
int i;
size = 1;
i = 0;
cmp = 0;
while (1)
{
cmp += (s1[i] - s2[i]);
if (i >= (int)n - 1)
return (cmp);
if (s1[i] == '\0' && s2[i] == '\0')
return (cmp);
if (s1[i] == s2[i])
i++;
else
return (cmp);
}
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:49:50 by jhalford #+# #+# */
/* Updated: 2016/08/07 10:50:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strupcase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 32;
i++;
}
return (str);
}

View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlowcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:50:10 by jhalford #+# #+# */
/* Updated: 2016/08/07 21:38:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
i++;
}
return (str);
}

View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:50:19 by jhalford #+# #+# */
/* Updated: 2016/08/07 22:09:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_alphanum(char c)
{
if (c >= '0' && c <= '9')
return (1);
else if (c >= 'a' && c <= 'z')
return (1);
else if (c >= 'A' && c <= 'Z')
return (1);
return (0);
}
char *ft_strcapitalize(char *str)
{
char *s;
s = str;
while (*s != '\0')
{
if (ft_is_alphanum(*(s - 1)) && *s >= 'A' && *s <= 'Z')
*s += 32;
if (!ft_is_alphanum(*(s - 1)) && *s >= 'a' && *s <= 'z')
*s -= 32;
s++;
}
return (str);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_alpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:55:19 by jhalford #+# #+# */
/* Updated: 2016/08/07 12:06:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_alpha(char *str)
{
int i;
char c;
i = 0;
while (str[i] != '\0')
{
c = str[i];
if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z'))
return (0);
i++;
}
return (1);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_numeric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/07 10:55:25 by jhalford #+# #+# */
/* Updated: 2016/08/07 12:06:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_numeric(char *str)
{
int i;
char cur;
i = 0;
while (str[i] != '\0')
{
cur = str[i];
if (!(cur >= '0' && cur <= '9'))
return (0);
i++;
}
return (1);
}

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