diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2025-01-31 16:22:52 +0000 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2025-01-31 16:22:52 +0000 |
commit | 45b06ac98819bfcad5f490c580d25fb0bf90c8ad (patch) | |
tree | 4f00b8a96847bccc605eea0e7154a3bd36a2fb5a | |
parent | 00e419fa183247d6d94b7eaf274bd2ae6225c646 (diff) | |
parent | 02653ab40d93fb7e6d07edb747fe0e07c5d60c74 (diff) |
performing merge
Merge branch 'master' of git://git.seacrossedlovers.xyz/school
40 files changed, 436 insertions, 27 deletions
Binary files differ diff --git a/bio/1/1.c b/bio/1/1.c new file mode 100644 index 0000000..d086119 --- /dev/null +++ b/bio/1/1.c @@ -0,0 +1,179 @@ +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdbool.h> +#include <stdlib.h> + +char *reverse(char *s){ + char *rev = malloc(strlen(s)); + int j = 0; + for (int i = strlen(s)-1; i >= 0; i--){ + rev[j] = s[i]; + j++; + } + rev[j] = 0; + + return rev; +} + +bool ispal(int n){ + char *strnum = malloc(128); + snprintf(strnum, 128, "%d", n); + char *rev = reverse(strnum); + + if (strcmp(rev, strnum) == 0) { // is the same both ways round + free(strnum); + free(rev); + return true; + } + free(strnum); + free(rev); + return false; +} + +int findhighestsumof2(int sums[][2], int sumcount){ + int highest = sums[0][0]; + int highestIndex = 0; + + for (int i = 0; i < sumcount; i++) { + if (sums[i][0] > highest) { + highest= sums[i][0]; + highestIndex = i; + } + if (sums[i][1] > highest) { + highest = sums[i][1]; + highestIndex = i; + } + } + + return highestIndex; +} + +int findlowesetsumof2(int sums[][2], int sumcount){ + if (sumcount == 0) return -1; // no sums + int lowest = sums[0][0]; + int lowestIndex = 0; + bool needscheck = false; + + for (int i = 0; i < sumcount; i++) { + if (sums[i][0] < lowest) { + lowest = sums[i][0]; + lowestIndex = i; + needscheck = false; + } + if (sums[i][1] < lowest) { + lowest = sums[i][1]; + lowestIndex = i; + needscheck = false; + } + if (sums[i][0] == lowest || sums[i][1] == lowest) needscheck == true; + } + if (needscheck) return findhighestsumof2(sums, sumcount); + return lowestIndex; +} + +int findhighestsumof3(int sums[][3], int sumcount){ + int highest = sums[0][0]; + int highestIndex = 0; + + for (int i = 0; i < sumcount; i++) { + if (sums[i][0] > highest) { + highest= sums[i][0]; + highestIndex = i; + } + if (sums[i][1] > highest) { + highest = sums[i][1]; + highestIndex = i; + } + if (sums[i][2] > highest) { + highest = sums[i][2]; + highestIndex = i; + } + } + return highestIndex; +} + +int findlowesetsumof3(int sums[][3], int sumcount){ + if (sumcount == 0) return -1; // no sums + // + int lowest = sums[0][0]; + int lowestIndex = 0; + bool needscheck = false; + + for (int i = 0; i < sumcount; i++) { + if (sums[i][0] < lowest) { + lowest = sums[i][0]; + lowestIndex = i; + needscheck = false; + } + if (sums[i][1] < lowest) { + lowest = sums[i][1]; + lowestIndex = i; + needscheck = false; + } + if (sums[i][2] < lowest) { + lowest = sums[i][2]; + lowestIndex = i; + needscheck = false; + } + if (sums[i][0] == lowest || sums[i][1] == lowest || sums[i][0] == lowest) needscheck == true; + } + if (needscheck) return findhighestsumof3(sums, sumcount); + return lowestIndex; +} + + +int main(int argc, char **argv){ + int input; + if (argc == 1) { + assert(scanf("%d", &input) != 0); + } else input = atoi(argv[1]); + + if (ispal(input)) { // if 1 number is enough + printf("%d\n", input); + return 1; + } + + int sums[input*2][2]; + int sumcount = 0; + for (int i = 1; i < input/2+1; i++){ // if 2 is enough + for (int j = input; j > (input/2) - 1; j--){ + if ((i + j) == input) { + if (ispal(i) & ispal(j)){ + sums[sumcount][0] = i; + sums[sumcount][1] = j; + sumcount++; + } + } + } + } + + int index = findlowesetsumof2(sums, sumcount); + if (index != -1) { + printf("%d %d\n", sums[index][0], sums[index][1]); + return 2; + } + + int triples[input*3][3]; + int triplecount = 0; + for (int i = 0; i < input; i++){ // if 3 is enough + for (int j = 0; j < input; j++){ + for (int k = 0; k < input; k++){ + if ((i + j + k) == input) { + if (ispal(i) & ispal(j) & ispal(k)){ + triples[triplecount][0] = i; + triples[triplecount][1] = j; + triples[triplecount][2] = k; + triplecount++; + } + } + } + } + } + + index = findlowesetsumof3(triples, triplecount); + if (index != -1) { + printf("%d %d %d\n", triples[index][0], triples[index][1], triples[index][2]); + return 3; + } +} diff --git a/bio/1/1.c.sh b/bio/1/1.c.sh new file mode 100644 index 0000000..e05be5a --- /dev/null +++ b/bio/1/1.c.sh @@ -0,0 +1,5 @@ +for i in $(./loopstr 1000000) +do + if [ $(./1 $i | grep -o "[0-9] " | wc -l) == "2" ]; then echo hit; fi + echo $i > ./count +done diff --git a/bio/1/1.txt b/bio/1/1.txt new file mode 100644 index 0000000..2bec6cd --- /dev/null +++ b/bio/1/1.txt @@ -0,0 +1,5 @@ +1)a) see sourcecode +1)b) 1 9 44 +1)c) ... + + diff --git a/bio/1/Makefile b/bio/1/Makefile new file mode 100644 index 0000000..7ba1ac5 --- /dev/null +++ b/bio/1/Makefile @@ -0,0 +1,4 @@ +all: 1.c + cc 1.c -o 1 -ggdb +clean: + rm 1 diff --git a/bio/1/count b/bio/1/count new file mode 100644 index 0000000..113c4d2 --- /dev/null +++ b/bio/1/count @@ -0,0 +1 @@ +1093 diff --git a/bio/1/loopstr b/bio/1/loopstr Binary files differnew file mode 100755 index 0000000..94ee2f9 --- /dev/null +++ b/bio/1/loopstr diff --git a/bio/1/loopstr.c b/bio/1/loopstr.c new file mode 100644 index 0000000..8319c19 --- /dev/null +++ b/bio/1/loopstr.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + for (int i = 0; i < atoi(argv[1]); i++){ + printf("%d ", i); + } + printf("\n"); +} Binary files differdiff --git a/bio/3/3.c b/bio/3/3.c new file mode 100644 index 0000000..3ecb08d --- /dev/null +++ b/bio/3/3.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +int main() { + int fusecount; + scanf("%d", &fusecount); + int fuses[fusecount]; + + for (int i = 0; i < fusecount; i++) + scanf("%d", &fuses[i]); + + float burntimes[fusecount * 3]; + int counter = 0; + for (int i = 0; i < fusecount; i++) { + for (int j = 0; j < 3; j++) { // for each state, (dont light, light, light both ends) + if (j == 0) burntimes[counter] = 0; + else if (j == 1) burntimes[counter] = fuses[i]; + else if (j == 2) burntimes[counter] = (float)fuses[i] / 2.0; + counter++; + } + } + + for (int i = 0; i < counter/2; i++) { + for (int j = counter-1; j > counter/2; j--){ + printf("%f %f\n", burntimes[i], burntimes[j]); + } + } +} diff --git a/bio/3/Makefile b/bio/3/Makefile new file mode 100644 index 0000000..6dc3b82 --- /dev/null +++ b/bio/3/Makefile @@ -0,0 +1,4 @@ +all: 3.c + cc 3.c -o 3 -ggdb +clean: + rm 3 diff --git a/comp/lucas-standen-NEA/code2/Makefile.new b/comp/lucas-standen-NEA/code2/Makefile.new deleted file mode 100644 index 8dcb4db..0000000 --- a/comp/lucas-standen-NEA/code2/Makefile.new +++ /dev/null @@ -1,25 +0,0 @@ -CC=cc -CFLAGS=-O3 - -SRC = zpy.c comp.c tokenizer.c fileread.c util.c appendsnprintf.c -OBJ = ${SRC:.c=.o} - -all: zpy - -.c.o: - ${CC} -c ${CFLAGS} $< -zpy: ${OBJ} - ${CC} -o $@ ${OBJ} - cd stdlib && make -install: all - cp zpy /usr/local/bin/zpy - cd stdlib && make install - cd zpypkg && make install -clean: - rm -rf zpy*.o - cd stdlib && make clean - cd examples && make clean -uninstall: - rm /usr/local/bin/zpy - -.PHONY: all clean install uninstall diff --git a/comp/lucas-standen-NEA/code2/appendsnprintf.o b/comp/lucas-standen-NEA/code2/appendsnprintf.o Binary files differdeleted file mode 100644 index 27fd51b..0000000 --- a/comp/lucas-standen-NEA/code2/appendsnprintf.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/code.zip b/comp/lucas-standen-NEA/code2/code.zip Binary files differnew file mode 100644 index 0000000..3c6a0a1 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/code.zip diff --git a/comp/lucas-standen-NEA/code2/comp.o b/comp/lucas-standen-NEA/code2/comp.o Binary files differdeleted file mode 100644 index eff68f5..0000000 --- a/comp/lucas-standen-NEA/code2/comp.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/examples/fib_example b/comp/lucas-standen-NEA/code2/examples/fib_example Binary files differdeleted file mode 100755 index 5422fe2..0000000 --- a/comp/lucas-standen-NEA/code2/examples/fib_example +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders b/comp/lucas-standen-NEA/code2/examples/spaceinvaders Binary files differdeleted file mode 100755 index 5d4134c..0000000 --- a/comp/lucas-standen-NEA/code2/examples/spaceinvaders +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/examples/str_example b/comp/lucas-standen-NEA/code2/examples/str_example Binary files differdeleted file mode 100755 index 084ef05..0000000 --- a/comp/lucas-standen-NEA/code2/examples/str_example +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c b/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c deleted file mode 100644 index 2305f24..0000000 --- a/comp/lucas-standen-NEA/code2/examples/tmp.zpy.c +++ /dev/null @@ -1,2 +0,0 @@ -#include <zpylib.h> -int main(){ diff --git a/comp/lucas-standen-NEA/code2/fileread.o b/comp/lucas-standen-NEA/code2/fileread.o Binary files differdeleted file mode 100644 index c7ebfad..0000000 --- a/comp/lucas-standen-NEA/code2/fileread.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/stdlib/String/String.o b/comp/lucas-standen-NEA/code2/stdlib/String/String.o Binary files differdeleted file mode 100644 index 6d68e10..0000000 --- a/comp/lucas-standen-NEA/code2/stdlib/String/String.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/stdlib/zpylib.o b/comp/lucas-standen-NEA/code2/stdlib/zpylib.o Binary files differdeleted file mode 100644 index f25e724..0000000 --- a/comp/lucas-standen-NEA/code2/stdlib/zpylib.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/tokenizer.o b/comp/lucas-standen-NEA/code2/tokenizer.o Binary files differdeleted file mode 100644 index e059ddc..0000000 --- a/comp/lucas-standen-NEA/code2/tokenizer.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/util.o b/comp/lucas-standen-NEA/code2/util.o Binary files differdeleted file mode 100644 index f9420e9..0000000 --- a/comp/lucas-standen-NEA/code2/util.o +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/zpy b/comp/lucas-standen-NEA/code2/zpy Binary files differdeleted file mode 100755 index 6ad15f3..0000000 --- a/comp/lucas-standen-NEA/code2/zpy +++ /dev/null diff --git a/comp/lucas-standen-NEA/code2/zpy.o b/comp/lucas-standen-NEA/code2/zpy.o Binary files differdeleted file mode 100644 index b3a1ccf..0000000 --- a/comp/lucas-standen-NEA/code2/zpy.o +++ /dev/null diff --git a/comp/work/37/rpn b/comp/work/37/rpn Binary files differindex e087f49..a2bc627 100755 --- a/comp/work/37/rpn +++ b/comp/work/37/rpn diff --git a/comp/work/37/stack.o b/comp/work/37/stack.o Binary files differnew file mode 100644 index 0000000..0b144c4 --- /dev/null +++ b/comp/work/37/stack.o diff --git a/comp/work/41/exersise.py b/comp/work/41/exersise.py new file mode 100644 index 0000000..2633c4c --- /dev/null +++ b/comp/work/41/exersise.py @@ -0,0 +1,24 @@ +def getdigits(number): + digits = [] + for i in number: + digits.append(int(i)) + return digits + +def testnumber(number): + d = getdigits(number) + total = sum(d) + + if (int(number) % total) == 0: + return True + return False + +n = int(input("which harshad number should you go to: ")) + +count = 0 +i = 0 +while count < n: + i += 1 + if testnumber(str(i)): + count += 1 + +print(i) diff --git a/comp/work/41/starter.txt b/comp/work/41/starter.txt new file mode 100644 index 0000000..e7328a1 --- /dev/null +++ b/comp/work/41/starter.txt @@ -0,0 +1,5 @@ +1) bundling data with relevant functions to do with the data +2) a class is the blueprint for an object, it will contain atributes (variables), and methods (functions) that can be used to manipulate/set or retrive the atributes +3) an object is the instance of a class in memory, it can be treated as a variable +4) this is the creation of an object from a class, it will often contain an initilization function to allow for it to have starting values +5) inheritence is the concept of creating a subclass that contains the same methods and atributes as an existing object and more data, it is a derived class diff --git a/comp/work/42/rpn/Makefile b/comp/work/42/rpn/Makefile new file mode 100644 index 0000000..6718c5b --- /dev/null +++ b/comp/work/42/rpn/Makefile @@ -0,0 +1,21 @@ +CC=cc +CFLAGS=-ggdb -Wextra -Wall -Werror +LIBS=-lm + +SRC = rpn.c stack.c +OBJ = ${SRC:.c=.o} + +all: rpn + +.c.o: + ${CC} -c ${CFLAGS} $< +rpn: ${OBJ} + ${CC} -o $@ ${OBJ} ${LIBS} +install: all + cp rpn /usr/local/bin/rpn +clean: + rm -rf rpn *.o +uninstall: + rm /usr/local/bin/rpn + +.PHONY: all clean install uninstall diff --git a/comp/work/42/rpn/rpn b/comp/work/42/rpn/rpn Binary files differnew file mode 100755 index 0000000..424fbc5 --- /dev/null +++ b/comp/work/42/rpn/rpn diff --git a/comp/work/42/rpn/rpn.c b/comp/work/42/rpn/rpn.c new file mode 100644 index 0000000..f5cd6b7 --- /dev/null +++ b/comp/work/42/rpn/rpn.c @@ -0,0 +1,56 @@ +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include "stack.h" + +char *readword(FILE *f) { + if (getc(f) == EOF) return NULL; + fseek(f, -1, SEEK_CUR); + + char *word = malloc(10); + char c; + int i = 0; + while ((c = getc(f)) != ' ') { + if (c == EOF || c == '\n') break; + word[i] = c; + i++; + } + word[i] = 0; + return word; +} + +int main() { + FILE *f = fopen("test.rpn", "r"); + stack *s = initstack(0 ,100); + + char *word; + int a, b; + while ((word = readword(f)) != NULL) { + if (!isdigit(word[0])) { + b = pop(s); + a = pop(s); + switch (word[0]) { + case '+': push(s, a+b); break; + case '-': push(s, a-b); break; + case '*': push(s, a*b); break; + case '/': push(s, a/b); break; + case '^': push(s, pow(a, b)); break; + case '~': + push(s, a); + push(s, -b); + break; + default: + printf("unknown symbol %c\n",word[0]); + exit(1); + break; + } + } + else push(s, atoi(word)); + free(word); + } + printf("%d\n", pop(s)); + + deinitstack(s); +} diff --git a/comp/work/42/rpn/rpn.o b/comp/work/42/rpn/rpn.o Binary files differnew file mode 100644 index 0000000..169c928 --- /dev/null +++ b/comp/work/42/rpn/rpn.o diff --git a/comp/work/42/rpn/stack.c b/comp/work/42/rpn/stack.c new file mode 100644 index 0000000..0311404 --- /dev/null +++ b/comp/work/42/rpn/stack.c @@ -0,0 +1,35 @@ +#include <stddef.h> +#include <stdlib.h> + +typedef struct stack { + int *sp; + int value; + int *stack; +} stack; + +int pop(stack *stack){ + stack->sp -= sizeof(int); + int i = *stack->sp; + *stack->sp = stack->value; + return i; +} + +void push(stack *stack, int value){ + *stack->sp = value; + stack->sp += sizeof(int); +} + +void deinitstack(stack *stack){ + free(stack->stack); + free(stack); + stack = NULL; +} + +stack *initstack(int value, size_t size){ + stack *s = malloc(sizeof(stack)); + s->stack = calloc(0, size*sizeof(int)); + s->sp = s->stack; + s->value = value; + return s; +} + diff --git a/comp/work/42/rpn/stack.h b/comp/work/42/rpn/stack.h new file mode 100644 index 0000000..0c78a10 --- /dev/null +++ b/comp/work/42/rpn/stack.h @@ -0,0 +1,10 @@ +typedef struct stack { + int *sp; + int value; + int *stack; +} stack; + +int pop(stack *stack); +void push(stack *stack, int value); +void deinitstack(stack *stack); +stack *initstack(int value, int size); diff --git a/comp/work/42/rpn/stack.o b/comp/work/42/rpn/stack.o Binary files differnew file mode 100644 index 0000000..05aa2e6 --- /dev/null +++ b/comp/work/42/rpn/stack.o diff --git a/comp/work/42/rpn/test.rpn b/comp/work/42/rpn/test.rpn new file mode 100644 index 0000000..02f9f8a --- /dev/null +++ b/comp/work/42/rpn/test.rpn @@ -0,0 +1 @@ +2 ~ 4 + diff --git a/comp/work/42/test/test.py b/comp/work/42/test/test.py new file mode 100644 index 0000000..4e70d92 --- /dev/null +++ b/comp/work/42/test/test.py @@ -0,0 +1,21 @@ +def tostring(list): + string = "" + for i in list: + string += str(i) + print(string) + +def getbin(n): + out = [] + while (n >= 1): + out.append(n % 2) + n = int(n / 2) + + out.reverse() + return out + +def tobin(n): + raw = getbin(n) + tostring(raw) + +n = int(input("what number would you like to convert: ")) +tobin(n) diff --git a/comp/work/42/torpn/torpn.c b/comp/work/42/torpn/torpn.c new file mode 100644 index 0000000..58b939a --- /dev/null +++ b/comp/work/42/torpn/torpn.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +typedef enum op { + ADD = '+', + SUB = '-', + MUL = '*', + DIV = '/', +} op; + +typedef struct ast { + op o; + int val1; + struct ast *child1; + + int val2; + struct ast *child2; +} ast; + +int main(){ + FILE *f = fopen("test.in", "r"); + char *expr = malloc(256); + fgets(expr, 256, f); + + for (int i = 0; i < strlen(expr); i++){ + + } +} |