-
-
Save erikaderstedt/6b1a8994cfb0c84904e684ef5875eeda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
int main(int argc, char **argv) { | |
char digits[7]; | |
size_t pt1 = 0, pt2 = 0, k; | |
for (uint32_t i = 165432; i <= 707912; i++) { | |
sprintf(digits, "%u", i); | |
bool pt1_ok = false, pt2_ok = false; | |
for (size_t j = 0; j < 5; j++) { | |
for (k = 1; k + j < 6 && digits[k+j] == digits[j]; k++); | |
pt1_ok = pt1_ok || (k >= 2); | |
pt2_ok = pt2_ok || (k == 2); | |
if (k > 2) j += k-2; | |
} | |
for (size_t j = 0; j < 5; j++) if (digits[j] > digits[j+1]) { pt1_ok = false; pt2_ok = false; } | |
if (pt1_ok) pt1++; | |
if (pt2_ok) pt2++; | |
} | |
printf("%zu, %zu\n", pt1, pt2); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment