Created
May 16, 2012 00:55
-
-
Save timjb/2706410 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
| -- http://mysliceofpizza.blogspot.de/2012/04/puzzle.html | |
| colorsRow :: Int -> Int | |
| colorsRow 0 = 0 | |
| colorsRow 1 = 1 | |
| colorsRow n = 1 + colorsRow (n `div` 2) | |
| -- colorsRow = (+1) . floor . logBase 2 . fromIntegral | |
| -- | Computes the number of colors needed to colorize an n*n field | |
| -- such that every subrectangle has at least one color that appears | |
| -- exactly once in the subrectangle | |
| colorsField :: Int -> Int | |
| colorsField 0 = 0 | |
| colorsField 1 = 1 | |
| colorsField n = colorsRow n + colorsField (n `div` 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment