diff --git a/d25/part1_imp.py b/d25/part1_imp.py new file mode 100644 index 0000000..79515ce --- /dev/null +++ b/d25/part1_imp.py @@ -0,0 +1,20 @@ +S = 0 +I = open("input").read() +th=2 +@par(num_threads=th,chunk_size=500//th) +for i in range(500): + if I[43*i] == '#': + #@par # much slower + for j in range(500): + if I[43*j] == '.': + for k in range(6,37): + if I[43*i+k]=='#' and I[43*j+k]=='#': + break + else: + S += 1 +print(S) +# 130ms with cpython +# with codon +# par 1 th: 6ms +# par 2 th: 4ms +# more // is slower \ No newline at end of file diff --git a/d25/part1_mm.c b/d25/part1_mm.c new file mode 100644 index 0000000..3243b48 --- /dev/null +++ b/d25/part1_mm.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +int main() { + // from stdin + //char I[21500]; // 500 * 43 + //fread(I, sizeof(char), sizeof(I), stdin); + // mmap input + struct stat sb; + int fd = open("input", O_RDONLY); + fstat(fd, &sb); + char *I = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + // timer + struct timespec start, end; + clock_gettime(CLOCK_MONOTONIC, &start); + + int S = 0; + for (int i = 0; i < 500; i++) { + if (I[43 * i] == '#') { + for (int j = 0; j < 500; j++) { + if (I[43 * j] == '.') { + int skip = 0; + for (int k = 6; k < 37; k++) { + if (I[43 * i + k] == '#' && I[43 * j + k] == '#') { + skip = 1; + break; + } + } + S += !skip; // Increment S only if skip is false + } + } + } + } + // stop timer + clock_gettime(CLOCK_MONOTONIC, &end); + double time_taken = ((end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec)) * 1e-9; + printf("%f\n", time_taken); + + printf("%d\n", S); + return 0; +} +// 2ms ; read input is 0.5ms ; process is 1.5ms \ No newline at end of file diff --git a/d25/part1_set.py b/d25/part1_set.py new file mode 100644 index 0000000..27a1178 --- /dev/null +++ b/d25/part1_set.py @@ -0,0 +1,9 @@ +A = { + frozenset({i for i, c in enumerate(B) if c == "#"}) + for B in open("input").read().strip().split("\n\n") +} +L = {a for a in A if 1 in a} +U = A - L +print(sum(not l & u for l in L for u in U)) +# 40ms with cpython +# 30ms with codon \ No newline at end of file