Skip to content

Instantly share code, notes, and snippets.

@timjb
Created May 16, 2012 00:55
Show Gist options
  • Select an option

  • Save timjb/2706410 to your computer and use it in GitHub Desktop.

Select an option

Save timjb/2706410 to your computer and use it in GitHub Desktop.
-- 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