initial commit

This commit is contained in:
laura 2025-12-08 21:41:49 +01:00
commit 0bc074c0b3
11 changed files with 525 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
**/input
**/input.txt
**/input-.txt
**/main

13
1/Makefile Normal file
View file

@ -0,0 +1,13 @@
client: main.c
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
client-debug: main.c
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
client-debug-nosanitize: main.c
gcc -o main main.c -O1 -Wall -Wextra -g
clean:
rm main
.PHONY: clean

73
1/main.c Normal file
View file

@ -0,0 +1,73 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
char input[] =
{
#embed "input.txt"
,'\0' // null terminator
};
//char input[] = "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82\n";
int width = 0;
int height = 0;
int result = 0;
int parseNum(char* str){
int i = 0;
int out = 0;
while(str[i] != '\n'){
out += str[i]-0x30;
out *= 10;
i++;
}
out /=10;
return out;
}
int main(int argc, char *argv[]){
clock_t start, end;
start = clock();
int i = 0;
int num;
int position = 50;
while(input[i] != 0){
//printf("\n\n%.10s\n\n", &input[i+1]);
//sscanf(&input[i+1], "%d\n*", &num);
num = parseNum(&input[i+1]);
if(input[i] == 'L'){
position = (position + 10000 - num)%100;
}
else{
position = (position + num)%100;
}
if(position == 0){
result++;
}
//printf("%d, %d\n", num, position);
//fflush(stdout);
if(num<10){
i += 3;
} else if(num<100){
i += 4;
} else if(num<1000){
i += 5;
}
}
end = clock();
printf("count: %d\n", result);
clock_t ticks_taken = end - start;
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
printf("time take: %f ticks\n", time_taken);
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
exit(1);
}

13
1_2/Makefile Normal file
View file

@ -0,0 +1,13 @@
client: main.c
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
client-debug: main.c
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
client-debug-nosanitize: main.c
gcc -o main main.c -O1 -Wall -Wextra -g
clean:
rm main
.PHONY: clean

87
1_2/main.c Normal file
View file

@ -0,0 +1,87 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
char input[] =
{
#embed "input.txt"
,'\0' // null terminator
};
//char input[] = "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82\n";
int width = 0;
int height = 0;
int result = 0;
int parseNum(char* str){
int i = 0;
int out = 0;
while(str[i] != '\n'){
out += str[i]-0x30;
out *= 10;
i++;
}
out /=10;
return out;
}
int main(int argc, char *argv[]){
clock_t start, end;
start = clock();
int i = 0;
int num;
int position = 50;
int old_pos = 50;
while(input[i] != 0){
//printf("\n\n%.10s\n\n", &input[i+1]);
//sscanf(&input[i+1], "%d\n*", &num);
num = parseNum(&input[i+1]);
if(input[i] == 'L'){
//result += (((position + 10000 - num)%100)-10000-((position + 10000 - num)-10000))/100;
if(position == 0){
result -=100;
}
position = (position - num);
old_pos = position;
position = (position+10000)%100;
result += position-old_pos;
if(position == 0){
result +=100;
}
}
else{
//result += (((position + num))-((position + num)%100))/100;
//position = (position + num)%100;
position = (position + num);
old_pos = position;
position = (position)%100;
result += old_pos-position;
}
//printf("%d, %d, %d\n", num, position, result);
//fflush(stdout);
if(num<10){
i += 3;
} else if(num<100){
i += 4;
} else if(num<1000){
i += 5;
}
}
end = clock();
printf("count: %d\n", result/100);
clock_t ticks_taken = end - start;
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
printf("time take: %f ticks\n", time_taken);
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
exit(1);
}

13
2/Makefile Normal file
View file

@ -0,0 +1,13 @@
client: main.c
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
client-debug: main.c
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
client-debug-nosanitize: main.c
gcc -o main main.c -O1 -Wall -Wextra -g
clean:
rm main
.PHONY: clean

144
2/main.c Normal file
View file

@ -0,0 +1,144 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <limits.h>
char input[] =
{
#embed "input.txt"
,'\0' // null terminator
};
//char input[] = "L68\nL30\nR48\nL5\nR60\nL55\nL1\nL99\nR14\nL82\n";
int width = 0;
int height = 0;
uint64_t result = 0;
uint64_t parseNum(char* str, int* len){
int i = 0;
uint64_t out = 0;
while(str[i] != ',' && str[i] != '-' && str[i] != '\n'){
out += str[i]-0x30;
out *= 10;
i++;
}
out /=10;
*len = i;
return out;
}
int numPlaces (uint64_t n) {
int r = 1;
while (n > 9) {
n /= 10;
r++;
}
//printf("%d has %d places\n", n, r);
return r;
}
uint64_t power(uint64_t base, uint64_t exp) {
uint64_t i, result = 1;
for (i = 0; i < exp; i++)
result *= base;
return result;
}
bool check_silly(uint64_t in){
int num = numPlaces(in);
if(!(num%2)){
uint64_t div = 1+power(10, num/2);
//printf("check dividend is %d\n", div);
if(in%div == 0){
return true;
}
}
return false;
}
void sort_ranges(uint64_t* starts, uint64_t* ends, int len){
int curr_min = 0;
for(int i = 0; i<len-1; i++){
for(int o = i; o<len; o++){
if(starts[curr_min]>starts[o]){
curr_min = o;
}
}
uint64_t tmp_start = starts[curr_min];
uint64_t tmp_end = ends[curr_min];
starts[curr_min] = starts[i];
ends[curr_min] = ends[i];
starts[i] = tmp_start;
ends[i] = tmp_end;
}
}
int main(int argc, char *argv[]){
clock_t start, end;
start = clock();
printf("INT_MAX: %d\n", INT_MAX);
int i = 0;
int num_ranges = 1;
while(input[i] != 0){
if(input[i]==','){
num_ranges++;
}
i++;
}
uint64_t starts[num_ranges];
uint64_t ends[num_ranges];
i = 0;
int range_num = 0;
int len = 0;
while(input[i] != 0){
starts[range_num] = parseNum(&input[i], &len);
i+=len+1;
ends[range_num] = parseNum(&input[i], &len);
i+=len+1;
//printf("%d-%d\n", starts[range_num], ends[range_num]);
range_num++;
}
sort_ranges(starts, ends, num_ranges);
for(i = 0; i<num_ranges; i++){
printf("checking range %lu-%lu\n\n", starts[i], ends[i]);
for(uint64_t o = starts[i]; o<=ends[i]; o++){
//printf("checking %d for sillyness\n", o);
if(check_silly(o)){
result += o;
printf("%lu is SILLY!\t\tcount is %lu\n", o, result);
}
}
}
//if(check_silly(1212)){
// result += 1212;
// printf("%d is SILLY!\n", 1212);
//}
end = clock();
printf("count: %lu\n", result);
clock_t ticks_taken = end - start;
double time_taken = ((double)ticks_taken)/CLOCKS_PER_SEC;
printf("time take: %f ticks\n", time_taken);
printf("CLOCKS_PER_SEC: %ld\n", CLOCKS_PER_SEC);
exit(1);
}

13
7/Makefile Normal file
View file

@ -0,0 +1,13 @@
client: main.c
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
client-debug: main.c
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
client-debug-nosanitize: main.c
gcc -o main main.c -O1 -Wall -Wextra -g
clean:
rm main
.PHONY: clean

70
7/main.c Normal file

File diff suppressed because one or more lines are too long

13
7_2/Makefile Normal file
View file

@ -0,0 +1,13 @@
client: main.c
gcc -o main main.c -O3 -Wall -Wextra -g -march=x86-64-v3
client-debug: main.c
gcc -o main main.c -O1 -Wall -Wextra -g -fsanitize=address
client-debug-nosanitize: main.c
gcc -o main main.c -O1 -Wall -Wextra -g
clean:
rm main
.PHONY: clean

82
7_2/main.c Normal file

File diff suppressed because one or more lines are too long