Created
April 9, 2011 04:06
-
-
Save oskimura/911092 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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