diff options
author | Singustromo <singustromo@disroot.org> | 2023-10-30 00:21:55 +0100 |
---|---|---|
committer | Singustromo <singustromo@disroot.org> | 2023-10-30 00:21:55 +0100 |
commit | 635625ccdf2bd8d49bdb4e425e0f10e25888b87e (patch) | |
tree | 9cc75e015173a1aae27772027425ac76119734a8 | |
download | ti3_project1-635625ccdf2bd8d49bdb4e425e0f10e25888b87e.tar.gz ti3_project1-635625ccdf2bd8d49bdb4e425e0f10e25888b87e.zip |
initial commit
-rw-r--r-- | .gitignore | 13 | ||||
-rwxr-xr-x | main.c | 49 | ||||
-rwxr-xr-x | tasks/task1.c | 12 | ||||
-rwxr-xr-x | tasks/task1.h | 7 | ||||
-rwxr-xr-x | tasks/task2.c | 7 | ||||
-rwxr-xr-x | tasks/task2.h | 7 | ||||
-rwxr-xr-x | tasks/task3.c | 15 | ||||
-rwxr-xr-x | tasks/task3.h | 6 | ||||
-rwxr-xr-x | tasks/task4.c | 18 | ||||
-rwxr-xr-x | tasks/task4.h | 13 |
10 files changed, 147 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1fe571f --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.ccsproject +.cproject +.project + +msp432p401r.cmd +startup_*_ccs.c +system_*.c + +inc/** +targetConfigs/** +Debug/** +.launches/** +.settings/** diff --git a/main.c b/main.c new file mode 100755 index 0000000..c98cab9 --- /dev/null +++ b/main.c @@ -0,0 +1,49 @@ +#include "msp.h" +#include <stdio.h> +#include <stdint.h> +#include <string.h> +#include "inc/clock.h" + +#include "tasks/task1.h" +#include "tasks/task2.h" +#include "tasks/task3.h" +#include "tasks/task4.h" + +/** + * main.c + */ +void main(void) +{ + /* DO NOT TOUCH STUFF HERE */ + WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; + Clock_Init48MHz(); + + if( !prime(5) ) printf("PRIME TEST1 FAILED WRONG ANSWER\n"); + if( prime(10) ) printf("PRIME TEST2 FAILED WRONG ANSWER\n"); + if( !prime(5813) ) printf("PRIME TEST3 FAILED WRONG ANSWER\n"); + + char task2_t1[] = "Hallo"; + char task2_t1_out[6] = {0}; + char task2_t2[] = "RUB"; + char task2_t2_out[4] = {0}; + + reverse(task2_t1,task2_t1_out,5); + reverse(task2_t2,task2_t2_out,3); + + if (strcmp(task2_t1_out, "ollaH") != 0) printf("REVERSE TEST1 FAILED WRONG ANSWER %s\n", task2_t1_out); + if (strcmp(task2_t2_out, "BUR") != 0) printf("REVERSE TEST2 FAILED WRONG ANSWER %s\n", task2_t2_out); + + int task3[] = {1000,3,1210,915,813,1600}; + if (findSum(task3,6) != 983730) printf("FINDSUM TEST1 FAILED WRONG ANSWER %d\n", findSum(task3,6)); + + float task4 = 35549; + float task4_result = sqrt(task4,20); + task4_result -= 188.544; + if (task4_result < 0.00) task4_result *= -1.00; + if( task4_result > 0.1) printf("SQRT TEST1 FAILED WRONG ANSWER %f\n", sqrt(task4,20)); + + printf("IF NO TEST FAILED, YOU ARE DONE :)\n"); + + /* DO NOT TOUCH STUFF HERE */ + while(1) __asm__(" nop"); +} diff --git a/tasks/task1.c b/tasks/task1.c new file mode 100755 index 0000000..0f5a5c3 --- /dev/null +++ b/tasks/task1.c @@ -0,0 +1,12 @@ +#include "task1.h" + +#define noRemainder(x,y) x % y == 0 + +int prime(unsigned int x) { + for (unsigned int i=2; i < x; i++) { + if (noRemainder(x, i)) + return 0; + } + + return 1; +} diff --git a/tasks/task1.h b/tasks/task1.h new file mode 100755 index 0000000..99ce0a0 --- /dev/null +++ b/tasks/task1.h @@ -0,0 +1,7 @@ +#ifndef TASKS_TASK1_H_ +#define TASKS_TASK1_H_ +#include <stdint.h> + +int prime(unsigned int x); + +#endif /* TASKS_TASK1_H_ */ diff --git a/tasks/task2.c b/tasks/task2.c new file mode 100755 index 0000000..020e3ad --- /dev/null +++ b/tasks/task2.c @@ -0,0 +1,7 @@ +#include "task2.h" + +void reverse(char* in,char* out, int len) { + for (unsigned int i=1; i < len+1; i++) { + out[len-i] = in[i-1]; + } +} diff --git a/tasks/task2.h b/tasks/task2.h new file mode 100755 index 0000000..017a3b6 --- /dev/null +++ b/tasks/task2.h @@ -0,0 +1,7 @@ +#ifndef TASKS_TASK2_H_ +#define TASKS_TASK2_H_ +#include <stdint.h> + +void reverse(char* in,char* out, int len); + +#endif /* TASKS_TASK2_H_ */ diff --git a/tasks/task3.c b/tasks/task3.c new file mode 100755 index 0000000..109922f --- /dev/null +++ b/tasks/task3.c @@ -0,0 +1,15 @@ +#include "task3.h" + +#define PRODUCT 2023 + +int findSum(int* x, int len) { + for (unsigned int i=0; i<len; i++) + { + for (unsigned int j=i+1; j<len; j++) + { + if (x[i]+x[j] == PRODUCT) + return x[i]*x[j]; + } + } + return 0; +} diff --git a/tasks/task3.h b/tasks/task3.h new file mode 100755 index 0000000..b708ae9 --- /dev/null +++ b/tasks/task3.h @@ -0,0 +1,6 @@ +#ifndef TASKS_TASK3_H_ +#define TASKS_TASK3_H_ + +int findSum(int* x, int len); + +#endif /* TASKS_TASK3_H_ */ diff --git a/tasks/task4.c b/tasks/task4.c new file mode 100755 index 0000000..2841811 --- /dev/null +++ b/tasks/task4.c @@ -0,0 +1,18 @@ +#include "task4.h" + +#define COMPUTE(x,y) 0.5 * (y + (x/y)) + +float sqrt(float x, int max_iterations) { + float current_result = (x+1) / 2; + float last_result = 0; + int i = 0; + + while (i < max_iterations) + { + last_result = current_result; + current_result = COMPUTE(x, last_result); + i++; + } + + return current_result; +} diff --git a/tasks/task4.h b/tasks/task4.h new file mode 100755 index 0000000..d59bc65 --- /dev/null +++ b/tasks/task4.h @@ -0,0 +1,13 @@ +/* + * task4.h + * + * Created on: 21 Oct 2023 + * Author: Florian Stolz + */ + +#ifndef TASKS_TASK4_H_ +#define TASKS_TASK4_H_ + +float sqrt(float x, int max_iterations); + +#endif /* TASKS_TASK4_H_ */ |