advent2019

Advent of Code 2019 (C99)
git clone git://bsandro.tech/advent2019
Log | Files | Refs | LICENSE

commit e6a73e442a2aebf2e03a46d10a4652e9c9349a15
parent 0f399070214f191e048087d97bd821753d3e7e26
Author: bsandro <email@bsandro.tech>
Date:   Fri, 26 Dec 2025 17:20:10 +0200

day04 p2

Diffstat:
Mday04.c | 20+++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/day04.c b/day04.c @@ -25,23 +25,29 @@ int main(void) { int ifrom = btoi(from); int ito = btoi(to); int p1 = 0; + int p2 = 0; char str[7]; for (int i=ifrom;i<=ito;++i) { sprintf(str, "%d", i); - bool ok = false; + bool ok1 = false; + bool ok2 = false; for (int j=1;j<6;++j) { if (str[j]<str[j-1]) { - ok = false; + ok1 = false; break; } - if (str[j]==str[j-1]) ok = true; + if (str[j]==str[j-1]) { + ok1 = true; + if (!ok2 && !((j>1&&str[j-1]==str[j-2]) || (j<5&&str[j]==str[j+1]))) { + ok2 = true; + } + } } - if (ok) { + if (ok1) { p1++; + if (ok2) { p2++; } } } - printf("p1: %d\n", p1); + printf("p1: %d\np2: %d\n", p1, p2); return 0; } -// 186750 too high -// 1777 too high