commit f78d33ff0b0e7c65e87e204c6b0b4f66cd69da5d
parent 1580b3c4c755f07896b0ef742b72d5a6f11ab539
Author: bsandro <email@bsandro.tech>
Date: Tue, 2 Dec 2025 09:11:31 +0200
day02 cleanup
Diffstat:
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/cputime.h b/cputime.h
@@ -4,12 +4,12 @@ static volatile unsigned long long now = 0;
void __attribute((constructor)) begin() {
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
now = ts.tv_sec + ts.tv_nsec;
}
void __attribute((destructor)) end() {
struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
printf("%f s\n", (double)((ts.tv_sec+ts.tv_nsec)-now)/1e9);
}
diff --git a/day02.c b/day02.c
@@ -19,13 +19,13 @@ inline uint64_t btoi(uint64_t buf[32], int bufs) {
return num;
}
-inline void itoa(uint64_t num, char str[32]) { //unused
+inline void itoa(uint64_t num, char str[32]) {
int d = digits(num);
- for (int i=0;i<d;++i) {
+ for (int i=d-1;i>=0;--i) {
str[i] = num%10+'0';
+ num = num/10;
}
str[d] = '\0';
- printf("itoa %lu -> %s\n", num, str);
}
inline bool is_silly1(uint64_t num) {
@@ -42,7 +42,7 @@ inline bool is_silly1(uint64_t num) {
inline bool is_silly2(uint64_t num) {
int d = digits(num);
char s[32] = {0};
- snprintf(s, 31, "%lu", num); // gave up on atoi for now
+ itoa(num, s);
for (int i=1;i<=d/2;++i) { // checking pattern 0-i
int rep = 0;
for (int j=0;j<d;j+=i) {
@@ -76,7 +76,6 @@ int main(void) {
} else if (c==','||c=='\n') {
range.last = btoi(buf, bufs);
bufs = 0;
- //printf("%"PRIu64"->%"PRIu64"\n", range.first, range.last);
p1 += sum_silly(range, is_silly1);
p2 += sum_silly(range, is_silly2);
}