Skip to content

Instantly share code, notes, and snippets.

@sordina
Created October 5, 2014 05:07
Show Gist options
  • Save sordina/0c3d470351d197d038f9 to your computer and use it in GitHub Desktop.
Save sordina/0c3d470351d197d038f9 to your computer and use it in GitHub Desktop.
import Data.List
import Control.Lens
import Data.Bits.Lens
import Test.QuickCheck
pascal = iterate stepper firstrow
where
firstrow = [1]
stepper r = zipWith (+) ([0] ++ r) (r ++ [0])
binomial n k = pascal !! n !! k
prop_lucas n k = n >= 0
==> k >= 0
==> k <= n
==> odd (binomial n k) == and (zipWith onBitMatches (toListOf bits k) (toListOf bits n))
onBitMatches True False = False
onBitMatches _ _ = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment