From 02653ab40d93fb7e6d07edb747fe0e07c5d60c74 Mon Sep 17 00:00:00 2001 From: thing1 Date: Thu, 30 Jan 2025 12:49:01 +0000 Subject: did many new things --- bio/1/1 | Bin 0 -> 20288 bytes bio/1/1.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bio/1/1.c.sh | 5 ++ bio/1/1.txt | 5 ++ bio/1/Makefile | 4 ++ bio/1/count | 1 + bio/1/loopstr | Bin 0 -> 15544 bytes bio/1/loopstr.c | 9 +++ bio/3/3 | Bin 0 -> 17312 bytes bio/3/3.c | 27 +++++++++ bio/3/Makefile | 4 ++ 11 files changed, 234 insertions(+) create mode 100755 bio/1/1 create mode 100644 bio/1/1.c create mode 100644 bio/1/1.c.sh create mode 100644 bio/1/1.txt create mode 100644 bio/1/Makefile create mode 100644 bio/1/count create mode 100755 bio/1/loopstr create mode 100644 bio/1/loopstr.c create mode 100755 bio/3/3 create mode 100644 bio/3/3.c create mode 100644 bio/3/Makefile (limited to 'bio') diff --git a/bio/1/1 b/bio/1/1 new file mode 100755 index 0000000..612a0ae Binary files /dev/null and b/bio/1/1 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 +#include +#include +#include +#include + +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 new file mode 100755 index 0000000..94ee2f9 Binary files /dev/null and b/bio/1/loopstr differ 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 +#include + +int main(int argc, char **argv) { + for (int i = 0; i < atoi(argv[1]); i++){ + printf("%d ", i); + } + printf("\n"); +} diff --git a/bio/3/3 b/bio/3/3 new file mode 100755 index 0000000..83cc1c2 Binary files /dev/null and b/bio/3/3 differ diff --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 + +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 -- cgit v1.2.3