25 lines
1.1 KiB
C
25 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* 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));
|
||
|
}
|