This commit is contained in:
Timo Schmidt 2023-04-01 02:22:16 +02:00
parent d5d49af2bd
commit b4f9739ec2
2 changed files with 5 additions and 6 deletions

View File

@ -6,13 +6,14 @@
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 00:36:21 by tosuman #+# #+# */
/* Updated: 2023/03/30 00:36:22 by tosuman ### ########.fr */
/* Updated: 2023/04/01 02:20:35 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
#define NUM_TYPE int
#define MAX_INDEX 10000
NUM_TYPE memoized_fibonacci(unsigned int index, NUM_TYPE *cache)
{
@ -25,12 +26,11 @@ NUM_TYPE memoized_fibonacci(unsigned int index, NUM_TYPE *cache)
int ft_fibonacci(int index)
{
int i;
NUM_TYPE *cache;
NUM_TYPE cache[MAX_INDEX + 1];
NUM_TYPE fibn;
if (index < 0)
return (-1);
cache = malloc(sizeof(NUM_TYPE) * (index + 1));
cache[0] = 0;
cache[1] = 1;
i = 2;
@ -38,7 +38,6 @@ int ft_fibonacci(int index)
cache[i++] = (NUM_TYPE)(-1);
fibn = memoized_fibonacci((unsigned int) index, cache);
i = 0;
free(cache);
return (fibn);
}

View File

@ -6,7 +6,7 @@
/* By: tosuman </var/spool/mail/tosuman> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/30 17:05:04 by tosuman #+# #+# */
/* Updated: 2023/04/01 02:17:57 by tischmid ### ########.fr */
/* Updated: 2023/04/01 02:18:59 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
@ -52,7 +52,7 @@ int is_valid_board(int cols[SIZE], int col)
int backtrack(int cols[SIZE], int col)
{
int i;
int sols;
int sols;
if (col >= SIZE)
return (new_sol(cols));