Skip to content

Instantly share code, notes, and snippets.

@jan-swiecki
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-swiecki/2436ee025cab94a25320 to your computer and use it in GitHub Desktop.
Save jan-swiecki/2436ee025cab94a25320 to your computer and use it in GitHub Desktop.
Problem4
-- 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