In Golang, assuming input is a valid integer.
package main var fibMap = map[int]int{ 0: 0, 1: 1, 2: 1, 3: 2, 4: 4, } func f(n int) int { if n <= 4 { return fibMap[n] } result := f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5) fibMap[n] = result return result } func countPentafib(n int) int { odds := make(map[int]bool) for i := 0; i < n; i++ { result := f(i) if result%2 == 1 { odds[result] = true } } return len(odds) } func main() { }
Tests
package main import "testing" func TestPentaFib(t *testing.T) { params := map[int]int{ 5: 1, 10: 3, 15: 5, } for key, value := range params { result := countPentafib(key) if result != value { t.Errorf("Incorrect answer for %d, expected: %d, got: %d", key, value, result) } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Golang, assuming input is a valid integer.
Tests