Given the following sequence, what is the number of total values for the odd terms of the sequence, up to the n-th term. The number n will be given as a positive integer.
f(0) = 0 f(1) = 1 f(2) = 1 f(3) = 2 f(4) = 4; f(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5);
1 is the only value that will be duplicated in the sequence, it should only be counted once.
Examples:
countPentafib(5)
=> 1
because the terms up to 5 are: [0, 1, 1, 2, 4, 8], 1 is the only odd and is only counted once.
countPentafib(10)
=> 3
[1, 1, 31, 61] are each odd and should be counted.
countPentafib(15)
=> 5
[1, 1, 31, 61, 1793, 3525] are all odd and 1 is only counted once.
Good luck!
This challenge comes from raulbc777 on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (3)
Haskell
Online playground
Hosted on Repl.it.
In Golang, assuming input is a valid integer.
Tests
Javascript: