aboutsummaryrefslogtreecommitdiff
path: root/c05/ex07
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-08-06 16:56:43 +0200
committerCharles <sircharlesaze@gmail.com>2019-08-06 16:56:43 +0200
commit056a88ee9c2c9e26f9712d14c645e367d851f394 (patch)
tree52b54df3e809e1526325dd9123078a9cc01e9831 /c05/ex07
parente534578eecebd27c4e7e235ce85961446e6c2e43 (diff)
downloadpiscine-056a88ee9c2c9e26f9712d14c645e367d851f394.tar.gz
piscine-056a88ee9c2c9e26f9712d14c645e367d851f394.tar.bz2
piscine-056a88ee9c2c9e26f9712d14c645e367d851f394.zip
c05
- primality test correction for ft_is_prime and ft_find_next_prime - queens puzzle solved with backtracking (similar to rush01)
Diffstat (limited to 'c05/ex07')
-rw-r--r--c05/ex07/ft_find_next_prime.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/c05/ex07/ft_find_next_prime.c b/c05/ex07/ft_find_next_prime.c
index 80227da..d8650eb 100644
--- a/c05/ex07/ft_find_next_prime.c
+++ b/c05/ex07/ft_find_next_prime.c
@@ -10,10 +10,10 @@
/* */
/* ************************************************************************** */
-int is_prime(int nb)
+
+static int is_prime(int nb)
{
long unsigned int i;
- long unsigned int nbu;
if (nb <= 1)
return (0);
@@ -21,20 +21,17 @@ int is_prime(int nb)
return (1);
if (nb % 2 == 0 || nb % 3 == 0)
return (0);
- i = 1;
- nbu = nb;
- while (i * i <= nbu)
+ i = 5;
+ while (i * i <= nb)
{
- if (nbu % (i * 6 - 1) == 0)
- return (0);
- if (nbu % (i * 6 + 1) == 0)
- return (0);
- i += 1;
+ if (nb % i == 0 || nb % (i + 2) == 0)
+ return (0);
+ i += 6;
}
return (1);
}
-int ft_find_next_prime(int nb)
+int ft_find_next_prime(int nb)
{
while (!is_prime(nb))
nb++;