Last active
August 7, 2018 03:29
-
-
Save zetashift/90d87d2fa3b8c9545b9f0fa8128026c8 to your computer and use it in GitHub Desktop.
Mortal Fibonacci Rabbits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
import math | |
const | |
input = "95 17".split(" ") | |
n = input[0].parseInt | |
m = input[1].parseInt | |
proc mortalRabbits(n: int, m: int): uint64 = | |
var a = newSeq[uint64](m) | |
a[m-1] = 1 | |
for generation in 1..n-1: | |
var children: uint64 = 0 | |
for i in 0..m-2: | |
children += a[i] | |
for i in 0..m-2: | |
a[i] = a[i+1] | |
a[m-1] = children | |
result = a.sum | |
echo mortalRabbits(n,m) # shows 13175509047921107537 | |
#should be 31622253121630659153 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment