summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-12-02 21:55:45 +0000
committermhsn <mail@mhsn.net>2025-12-02 21:55:45 +0000
commit217524b72271de38e5358f75bf9ce7c45322f861 (patch)
tree830a33023d26b5996123f3caa1757f24241d4c36
parente0e455270f4657e2294fefbd03d9ad0b469a87e0 (diff)
downloadaoc-217524b72271de38e5358f75bf9ce7c45322f861.tar.gz
aoc-217524b72271de38e5358f75bf9ce7c45322f861.zip
25-01 c
-rw-r--r--2025/01/c.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/2025/01/c.c b/2025/01/c.c
index 44b9c78..115ea13 100644
--- a/2025/01/c.c
+++ b/2025/01/c.c
@@ -1,6 +1,19 @@
#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
-int main() {
- printf("hello world!\n");
+int main()
+{
+ char dir;
+ int64_t n;
+ int64_t p = 50;
+ int64_t p1 = 0, p2 = 0;
+ while (scanf("%c%ld ", &dir, &n) == 2) {
+ int64_t new = p + (dir == 'R' ? n : -n);
+ p2 += labs(new) / 100 + (p != 0 && new <= 0);
+ p = (p = new % 100) >= 0 ? p : p + 100;
+ p1 += p == 0;
+ }
+ printf("silver: %ld\ngold: %ld", p1, p2);
return 0;
}