challenge-algorithms-Ana-Ca.../04-fibonnaci/index.html

37 lines
1.0 KiB
HTML
Raw Normal View History

2021-08-18 21:00:43 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
Faça um algoritmo que resolva a função de fibonnaci
Fibonnaci: https://pt.wikipedia.org/wiki/Sequ%C3%AAncia_de_Fibonacci
*/
function fib(values) {
// implementar logica aqui
var sqrt5 = Math.sqrt(5);
return Math.round(Math.pow(((1 + sqrt5) / 2), values) / sqrt5);
2021-08-18 21:00:43 +00:00
}
// Resultados esperados
console.log(fib(0), 0) // 0
console.log(fib(1), 1) // 1
console.log(fib(2), 1) // 1
console.log(fib(3), 2) // 2
console.log(fib(4), 3) // 3
console.log(fib(5), 5) // 5
console.log(fib(35), 9227465) // 9227465
console.log(fib(46), 1836311903) // 1836311903
</script>
</body>
</html>