Loading fibonacci_ops.c +11 −4 Original line number Diff line number Diff line Loading @@ -18,16 +18,23 @@ unsigned long long get_fibonacci_value_at(unsigned int index) { fibonacci_head = &fibonacci_first_element; unsigned int current_i = 0; unsigned int current_value = 0; unsigned long long current_value = 0; unsigned int a = 1; unsigned int b = 0; unsigned long long a = 1; unsigned long long b = 0; for (current_i = 0; current_i < index; current_i++) { if (*fibonacci_head == NULL) { push(fibonacci_head, next_fibonacci_number(a, b)); } current_value = (*fibonacci_head)->value; // overflow check if (current_value < a || current_value < b) { printf("error: fibonacci sequence overflow\n"); return 0; } if (current_i % 2 == 0) { a = (*fibonacci_head)->value; } else { Loading @@ -40,6 +47,6 @@ unsigned long long get_fibonacci_value_at(unsigned int index) { return current_value; } unsigned int next_fibonacci_number(const unsigned int a, const unsigned int b) { unsigned long long next_fibonacci_number(const unsigned long long a, const unsigned long long b) { return a + b; } fibonacci_ops.h +2 −1 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ #define FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H unsigned long long get_fibonacci_value_at(unsigned int index); unsigned int next_fibonacci_number(unsigned int a, unsigned int b); unsigned long long next_fibonacci_number(unsigned long long a, unsigned long long b); #endif //FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H No newline at end of file linked_list.c +2 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ // Created by Chris on 9/12/25. // linked_list_item *create_node(const unsigned int value) { linked_list_item *create_node(const unsigned long long value) { linked_list_item *node = malloc(sizeof(*node)); if (node == NULL) { return NULL; Loading @@ -14,7 +14,7 @@ linked_list_item *create_node(const unsigned int value) { return node; } int push(linked_list_item **head, const unsigned int value) { int push(linked_list_item **head, const unsigned long long value) { linked_list_item *new_node = create_node(value); if (new_node == NULL) { return -1; Loading linked_list.h +2 −2 Original line number Diff line number Diff line Loading @@ -9,12 +9,12 @@ typedef struct linked_list_item linked_list_item; struct linked_list_item { unsigned int value; unsigned long long value; linked_list_item *next; linked_list_item *prev; }; int push(linked_list_item **head, unsigned int value); int push(linked_list_item **head, unsigned long long value); void delete_linked_list(linked_list_item **head); // unsigned int get_at(linked_list_item **head, unsigned int index); Loading main.c +2 −2 Original line number Diff line number Diff line Loading @@ -32,9 +32,9 @@ int main(void) { // -> here's a fibonacci number test // note the inefficiency: with a singly linked list, get_fibonacci_value_at() always works linearly // todo as improvement, keep a doubly linked list & retain current index + value for shorter moves // todo as improvement, keep a doubly linked list & retain current index + value for potentially shorter moves for (unsigned int i = 0; i < 100; i++) { printf("fibonacci number: %lld \n", get_fibonacci_value_at(i)); printf("i %u, fibonacci number: %llu\n", i, get_fibonacci_value_at(i)); } return 0; Loading Loading
fibonacci_ops.c +11 −4 Original line number Diff line number Diff line Loading @@ -18,16 +18,23 @@ unsigned long long get_fibonacci_value_at(unsigned int index) { fibonacci_head = &fibonacci_first_element; unsigned int current_i = 0; unsigned int current_value = 0; unsigned long long current_value = 0; unsigned int a = 1; unsigned int b = 0; unsigned long long a = 1; unsigned long long b = 0; for (current_i = 0; current_i < index; current_i++) { if (*fibonacci_head == NULL) { push(fibonacci_head, next_fibonacci_number(a, b)); } current_value = (*fibonacci_head)->value; // overflow check if (current_value < a || current_value < b) { printf("error: fibonacci sequence overflow\n"); return 0; } if (current_i % 2 == 0) { a = (*fibonacci_head)->value; } else { Loading @@ -40,6 +47,6 @@ unsigned long long get_fibonacci_value_at(unsigned int index) { return current_value; } unsigned int next_fibonacci_number(const unsigned int a, const unsigned int b) { unsigned long long next_fibonacci_number(const unsigned long long a, const unsigned long long b) { return a + b; }
fibonacci_ops.h +2 −1 Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ #define FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H unsigned long long get_fibonacci_value_at(unsigned int index); unsigned int next_fibonacci_number(unsigned int a, unsigned int b); unsigned long long next_fibonacci_number(unsigned long long a, unsigned long long b); #endif //FIBONACCI_STEP_SEARCH_FIBONACCI_OPS_H No newline at end of file
linked_list.c +2 −2 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ // Created by Chris on 9/12/25. // linked_list_item *create_node(const unsigned int value) { linked_list_item *create_node(const unsigned long long value) { linked_list_item *node = malloc(sizeof(*node)); if (node == NULL) { return NULL; Loading @@ -14,7 +14,7 @@ linked_list_item *create_node(const unsigned int value) { return node; } int push(linked_list_item **head, const unsigned int value) { int push(linked_list_item **head, const unsigned long long value) { linked_list_item *new_node = create_node(value); if (new_node == NULL) { return -1; Loading
linked_list.h +2 −2 Original line number Diff line number Diff line Loading @@ -9,12 +9,12 @@ typedef struct linked_list_item linked_list_item; struct linked_list_item { unsigned int value; unsigned long long value; linked_list_item *next; linked_list_item *prev; }; int push(linked_list_item **head, unsigned int value); int push(linked_list_item **head, unsigned long long value); void delete_linked_list(linked_list_item **head); // unsigned int get_at(linked_list_item **head, unsigned int index); Loading
main.c +2 −2 Original line number Diff line number Diff line Loading @@ -32,9 +32,9 @@ int main(void) { // -> here's a fibonacci number test // note the inefficiency: with a singly linked list, get_fibonacci_value_at() always works linearly // todo as improvement, keep a doubly linked list & retain current index + value for shorter moves // todo as improvement, keep a doubly linked list & retain current index + value for potentially shorter moves for (unsigned int i = 0; i < 100; i++) { printf("fibonacci number: %lld \n", get_fibonacci_value_at(i)); printf("i %u, fibonacci number: %llu\n", i, get_fibonacci_value_at(i)); } return 0; Loading