add basic math functions
This commit is contained in:
@ -36,7 +36,7 @@ char *get_input(const char *path) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
char **split(const char *s, size_t *lsz, const char *delim) {
|
||||
char **split(char *s, size_t *lsz, const char *delim) {
|
||||
char **lines = NULL;
|
||||
char *t = strtok(s, delim);
|
||||
size_t n = 0;
|
||||
|
28
src/math.c
Normal file
28
src/math.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
int max_int(int a, int b) {
|
||||
if (a > b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int min_int(int a, int b) {
|
||||
if (a < b) {
|
||||
return a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int binstr_to_int(const char *s) {
|
||||
int n = 0, m = 1;
|
||||
for (size_t i = strlen(s) - 1; i >= 0; --i) {
|
||||
if (s[i] == '1') {
|
||||
n += m;
|
||||
}
|
||||
m *= 2;
|
||||
}
|
||||
return n;
|
||||
}
|
Reference in New Issue
Block a user