Last active
August 29, 2015 14:20
-
-
Save jan-swiecki/2436ee025cab94a25320 to your computer and use it in GitHub Desktop.
Problem4
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
-- Write a function that given a list of non negative integers, | |
-- arranges them such that they form the largest possible number. | |
-- For example, given [50, 2, 1, 9], the largest formed number is 95021. | |
-- Source: https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour | |
import Data.List | |
intCombinations :: [Int] -> [Int] | |
intCombinations xs = map (read.concat.(map show)) (permutations xs) | |
-- usage: solve [50, 2, 1, 9] | |
solve :: [Int] -> Int | |
solve = (foldl max 0) . intCombinations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment