42/d09/ex07/ft_collatz_conjecture.c

25 lines
1.1 KiB
C
Raw Permalink Normal View History

2016-11-20 02:20:23 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_collatz_conjecture.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 01:39:43 by gtertysh #+# #+# */
/* Updated: 2016/11/04 04:01:26 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
unsigned int ft_collatz_conjecture(unsigned int base)
{
static unsigned int i = 0;
i++;
if (base == 1)
return (i);
else if (base % 2 == 0)
return (ft_collatz_conjecture(base / 2));
else
return (ft_collatz_conjecture(base * 3 + 1));
}