Skip to content

Commit 6c4c272

Browse files
author
Loic Lord
committed
added maths and free
1 parent 8a4e629 commit 6c4c272

13 files changed

+277
-20
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 42
22
*DS_Store
3-
main.c
43
*.vscode
54

65

ft_math/ft_array_cpy.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_entropy.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:38:28 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//copies a list of ints
16+
17+
int *array_cpy(int *srclst, int n)
18+
{
19+
int *dstlst;
20+
21+
dstlst = ft_calloc(n++, sizeof(int));
22+
if (!srclst && !dstlst && !(0 < n))
23+
return (NULL);
24+
while (n--)
25+
dstlst[n] = srclst[n];
26+
return (dstlst);
27+
}
28+

ft_math/ft_math_avrg.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_mean.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:37:37 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the average value of a given list
16+
17+
void *ft_math_avrg(int *lst)
18+
{
19+
20+
}

ft_math/ft_math_entropy.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_entropy.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:38:28 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the "entropy" of a given list (see google doc)
16+
17+
void *ft_math_entropy(int *lst)
18+
{
19+
20+
}

ft_math/ft_math_exp.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_exp.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 15:22:52 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the eth exponent of a given number (below ^32)
16+
17+
int *ft_math_exp(int n, int e)
18+
{
19+
int result;
20+
21+
result = 1;
22+
if (e < 31)
23+
{
24+
while (e-- > 0 && n != 0)
25+
result *= n;
26+
return (result);
27+
}
28+
else
29+
return (void);
30+
}

ft_math/ft_math_max.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_max.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 15:31:17 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the greater number of a given list
16+
17+
int *ft_math_max(int *lst)
18+
{
19+
int result;
20+
21+
if (lst);
22+
{
23+
result = *lst;
24+
while (lst++)
25+
{
26+
if (*lst > result)
27+
result = *lst;
28+
}
29+
return (result);
30+
}
31+
else
32+
return (void);
33+
}

ft_math/ft_math_mean.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_mean.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:37:46 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the average value of a given list
16+
17+
void *ft_math_avrg(int *lst)
18+
{
19+
20+
}

ft_math/ft_math_med.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_med.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:37:00 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the median number of a given list
16+
17+
void *ft_math_med(int *lst)
18+
{
19+
20+
}

ft_math/ft_math_min.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_min.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 15:31:41 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//finds the lesser number of a given list
16+
17+
int *ft_math_min(int *lst)
18+
{
19+
int result;
20+
21+
if (lst);
22+
{
23+
result = *lst;
24+
while (lst++)
25+
{
26+
if (*lst < result)
27+
result = *lst;
28+
}
29+
return (result);
30+
}
31+
else
32+
return (void);
33+
}

ft_math/ft_math_root.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_math_root.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/07/11 13:33:14 by llord #+# #+# */
9+
/* Updated: 2022/07/11 13:34:48 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//takes the rth root of a given number
16+
17+
void *ft_math_root(int n, int r)
18+
{
19+
20+
}

ft_mem/ft_free_array.c

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* ft_free_array.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2023/03/07 15:31:17 by llord #+# #+# */
9+
/* Updated: 2023/03/07 15:39:09 by llord ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
13+
#include "libft.h"
14+
15+
//takes a pointer's adress and frees whatever is there, setting it to NULL after
16+
void ft_free_null(void **ptr)
17+
{
18+
free(*ptr);
19+
*ptr = NULL;
20+
}
21+
22+
//takes a array's adress and frees whatever is there, setting it all to NULL after
23+
void ft_free_array(void ***ptr)
24+
{
25+
int i;
26+
27+
if (*ptr)
28+
{
29+
i = -1;
30+
while (*ptr[++i])
31+
ft_free_null(&((*ptr)[i]));
32+
ft_free_null(ptr);
33+
}
34+
}

ft_str/ft_strtrim.c

+16-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/01/31 13:35:19 by llord #+# #+# */
9-
/* Updated: 2022/04/12 09:59:03 by llord ### ########.fr */
9+
/* Updated: 2022/10/21 12:45:00 by llord ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -15,7 +15,19 @@
1515
//creates a new string without the specified characters
1616
//at the begining/end of the original string
1717

18-
static int notin(char c, const char *set);
18+
static int not_in_set(char c, const char *set)
19+
{
20+
int i;
21+
22+
i = 0;
23+
while (set[i])
24+
{
25+
if (set[i] == c)
26+
return (0);
27+
i++;
28+
}
29+
return (1);
30+
}
1931

2032
char *ft_strtrim(char const *s1, char const *set)
2133
{
@@ -26,25 +38,11 @@ char *ft_strtrim(char const *s1, char const *set)
2638
if (!s1 || !set)
2739
return (0);
2840
start = 0;
29-
while (!notin(s1[start], set) && s1[start])
41+
while (!not_in_set(s1[start], set) && s1[start])
3042
start++;
3143
end = ft_strlen(s1);
32-
while (!notin(s1[end - 1], set) && start < end)
44+
while (!not_in_set(s1[end - 1], set) && start < end)
3345
end--;
3446
s2 = (ft_substr(s1, start, (size_t)(end - start)));
3547
return (s2);
3648
}
37-
38-
static int notin(char c, const char *set)
39-
{
40-
int i;
41-
42-
i = 0;
43-
while (set[i])
44-
{
45-
if (set[i] == c)
46-
return (0);
47-
i++;
48-
}
49-
return (1);
50-
}

libft.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: llord <llord@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2022/03/28 14:20:01 by llord #+# #+# */
9-
/* Updated: 2022/04/23 11:27:54 by llord ### ########.fr */
9+
/* Updated: 2023/03/07 15:39:12 by llord ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -43,6 +43,8 @@ void ft_lstclear(t_list **lst, void (*del)(void*));
4343
void ft_lstiter(t_list *lst, void (*f)(void *));
4444
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
4545

46+
void ft_free_null(void **ptr);
47+
void ft_free_array(void ***ptr);
4648
void *ft_bzero(void *s, size_t n);
4749
void *ft_calloc(size_t count, size_t size);
4850
void *ft_memset(void *b, int c, size_t len);

0 commit comments

Comments
 (0)