commit 0f399070214f191e048087d97bd821753d3e7e26 parent 537e8e9ebfd79fdc0cba37596e75c57c12012403 Author: bsandro <email@bsandro.tech> Date: Fri, 26 Dec 2025 13:59:03 +0200 day04 p1 Diffstat:
| A | day04.c | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/day04.c b/day04.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <string.h> +#include <stdbool.h> +#include "cputime.h" + +typedef struct { + int data[16]; + int len; +} Buffer; + +static int btoi(Buffer buf) { + int num = 0; + for (int i=0;i<buf.len;++i) num = num*10+buf.data[i]; + return num; +} + +int main(void) { + Buffer from = {0}; + Buffer to = {0}; + Buffer *cur = &from; + for (int c=getchar();c!=EOF;c=getchar()) { + if (c>='0'&&c<='9') cur->data[cur->len++] = c-'0'; + else if (c=='-') cur = &to; + } + int ifrom = btoi(from); + int ito = btoi(to); + int p1 = 0; + char str[7]; + for (int i=ifrom;i<=ito;++i) { + sprintf(str, "%d", i); + bool ok = false; + for (int j=1;j<6;++j) { + if (str[j]<str[j-1]) { + ok = false; + break; + } + if (str[j]==str[j-1]) ok = true; + } + if (ok) { + p1++; + } + } + printf("p1: %d\n", p1); + return 0; +} +// 186750 too high +// 1777 too high