Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created April 9, 2011 04:06
Show Gist options
  • Select an option

  • Save oskimura/911092 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/911092 to your computer and use it in GitHub Desktop.
type L x = Array Int (x,Int)
combine :: Num x => L x -> L x -> L x
combine lut1 lut2 = listArray (bounds lut1) [let (p1,s1) = lut1!i; (p2,s2) = lut2!s1 in (p1+p2,s2) |
i <- range (bounds lut1)]
times :: Num x => Integer -> L x -> L x
times 0 lut = listArray (bounds lut) [(0,x) | x <- range (bounds lut)]
times 1 lut = lut
times 2 lut = combine lut lut
times n lut = combine (times 2 (times (n `div` 2) lut))
(times (n `mod` 2) lut)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment