diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-11 15:14:47 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-12-11 15:14:47 +0100 |
| commit | 554ad47f09974f0131df285fda8ea50a1fdad8f5 (patch) | |
| tree | d23caeb85e7fce6290664a0ebf3c96f513efbe94 /2023/06 | |
| download | aoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.tar.gz aoc-554ad47f09974f0131df285fda8ea50a1fdad8f5.zip | |
Initial commit, some solutions
Diffstat (limited to '2023/06')
| -rw-r--r-- | 2023/06/6a.c | 44 | ||||
| -rw-r--r-- | 2023/06/6b.txt | 1 | ||||
| -rw-r--r-- | 2023/06/in.txt | 2 | ||||
| -rw-r--r-- | 2023/06/in2.txt | 2 |
4 files changed, 49 insertions, 0 deletions
diff --git a/2023/06/6a.c b/2023/06/6a.c new file mode 100644 index 0000000..4ce8fd1 --- /dev/null +++ b/2023/06/6a.c | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #include <inttypes.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdbool.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | #define N 100000 | ||
| 9 | |||
| 10 | #define MIN(a, b) ((a)<(b)?(a):(b)) | ||
| 11 | #define MAX(a, b) ((a)>(b)?(a):(b)) | ||
| 12 | |||
| 13 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 14 | |||
| 15 | int64_t readl(int64_t nums[], char *buf) { | ||
| 16 | int64_t i; | ||
| 17 | for (i = 0; *buf; buf++) { | ||
| 18 | if (!isnum(*buf)) continue; | ||
| 19 | nums[i++] = atoll(buf); | ||
| 20 | while (isnum(*buf)) buf++; | ||
| 21 | } | ||
| 22 | return i; | ||
| 23 | } | ||
| 24 | |||
| 25 | int main() { | ||
| 26 | char line[N], clean[N]; | ||
| 27 | int64_t i, n, p, D, x1, x2, t[N], d[N]; | ||
| 28 | |||
| 29 | n = readl(t, fgets(line, N, stdin)); | ||
| 30 | readl(d, fgets(line, N, stdin)); | ||
| 31 | |||
| 32 | p = 1; | ||
| 33 | for (i = 0; i < n; i++) { | ||
| 34 | D = t[i]*t[i] - 4*d[i]; | ||
| 35 | if (D < 0) p = 1; | ||
| 36 | double sq = sqrt(D); | ||
| 37 | x1 = (int64_t)floor((t[i] - sq)/2) + 1; | ||
| 38 | x2 = (int64_t)ceil((t[i] + sq)/2) - 1; | ||
| 39 | p *= x2 - x1 + 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | printf("%" PRId64 "\n", p); | ||
| 43 | return 0; | ||
| 44 | } | ||
diff --git a/2023/06/6b.txt b/2023/06/6b.txt new file mode 100644 index 0000000..3d9fcf8 --- /dev/null +++ b/2023/06/6b.txt | |||
| @@ -0,0 +1 @@ | |||
| Just use 6a and modify the input file manually | |||
diff --git a/2023/06/in.txt b/2023/06/in.txt new file mode 100644 index 0000000..db24621 --- /dev/null +++ b/2023/06/in.txt | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | Time: 41 96 88 94 | ||
| 2 | Distance: 214 1789 1127 1055 | ||
diff --git a/2023/06/in2.txt b/2023/06/in2.txt new file mode 100644 index 0000000..000bcf9 --- /dev/null +++ b/2023/06/in2.txt | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | Time: 41968894 | ||
| 2 | Distance: 214178911271055 | ||
