Skip to content

Instantly share code, notes, and snippets.

@berdario berdario/Spec.hs
Created Nov 15, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.