Created
November 26, 2011 01:35
-
-
Save alcides/1394809 to your computer and use it in GitHub Desktop.
Haskell solution for http://blog.tommorris.org/post/13322490041/code-noodling-contest-functionalize-this
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
type DataStore = [(Int, Int)] | |
iter :: Int -> DataStore -> Int -> (DataStore, Int) | |
iter rem ks d = ( (d, rem `div` d):ks, rem `mod` d) | |
wrapper :: Int -> DataStore -> Int -> (DataStore, Int) | |
wrapper re ds 1 = (ds, re) | |
wrapper re ds d = wrapper re' ds' (d `div` 2) | |
where (ds', re') = iter re ds d | |
page_spread_count :: Int -> ([(Int, Int)], Int) | |
page_spread_count i = wrapper i [] 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found your gist, read the "contest" and made my own solution: https://gist.github.com/1395553
The last reminder is returned in the list, for the key 1.