Created
November 15, 2016 15:39
-
-
Save berdario/46070970cab92b20d16056ea973dbc00 to your computer and use it in GitHub Desktop.
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
import Data.List (permutations, sortBy) | |
import Test.QuickCheck | |
readInt :: String -> Int | |
readInt = read | |
comp GT _ _ _ = GT | |
comp LT _ _ _ = LT | |
comp EQ _ [] [] = EQ | |
comp EQ previous [x] [] = compare x previous | |
comp EQ previous [] [y] = compare previous y | |
comp EQ _ (x:xs) (y:ys) = comp (compare x y) (max x y) xs ys | |
biggest :: [Int] -> String | |
biggest = concat . sortBy (flip $ comp EQ '0') . map show | |
bruteForce :: [Int] -> Int | |
bruteForce ns = maximum $ map (readInt . concat) $ permutations numbers | |
where | |
numbers = map show ns | |
prop_biggest :: NonEmptyList (NonNegative Int) -> Bool | |
prop_biggest (NonEmpty ns) = read (biggest numbers) == bruteForce numbers | |
where | |
numbers = map (\(NonNegative x) -> x) ns | |
main :: IO () | |
main = quickCheck $ property prop_biggest | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment