diff options
Diffstat (limited to 'comp')
29 files changed, 202 insertions, 27 deletions
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++){ + + } +} |