76 lines
1.4 KiB
C
76 lines
1.4 KiB
C
#include "_.h"
|
|
#include <pthread.h>
|
|
|
|
typedef struct structure {
|
|
int nbr;
|
|
struct structure *next;
|
|
} struc;
|
|
|
|
typedef struct data_t {
|
|
long nbr;
|
|
int max;
|
|
} data;
|
|
|
|
long long lenght_struc(struc *head) {
|
|
long long count = 0;
|
|
while (head->next != NULL) {
|
|
head = head->next;
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
void print_struc(struc *head) {
|
|
while (head->next != NULL) {
|
|
head = head->next;
|
|
printf("%d ", head->nbr);
|
|
}
|
|
}
|
|
|
|
long count = 0;
|
|
|
|
void blink(long nbr, int max) {
|
|
for (; max > 0; max--) {
|
|
if (nbr == 0) {
|
|
nbr = 1;
|
|
}
|
|
else if (((int)floor(log10(ABS(nbr))) + 1) % 2 == 0) {
|
|
double len = floor(log10(ABS(nbr))) + 1;
|
|
int left = nbr / (pow(10, len / 2));
|
|
nbr = nbr % (long)(pow(10, len / 2));
|
|
|
|
blink(left, max - 1);
|
|
}
|
|
else
|
|
nbr *= 2024;
|
|
}
|
|
count++;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if (argc != 2)
|
|
return 1;
|
|
|
|
char *input = argv[1];
|
|
char **inputs = str_split(strdup(input), ' ');
|
|
struc *head = calloc(1, sizeof(struc));
|
|
struc *cur = head;
|
|
|
|
for (int i = 0; inputs[i] != NULL; i++) {
|
|
cur->nbr = atol(inputs[i]);
|
|
cur->next = calloc(1, sizeof(struc));
|
|
cur = cur->next;
|
|
}
|
|
|
|
cur = head;
|
|
while (cur->next != NULL) {
|
|
blink(cur->nbr, 75);
|
|
cur = cur->next;
|
|
}
|
|
|
|
printf("count: %ld\n", count);
|
|
|
|
return 0;
|
|
}
|