Skip to content

Instantly share code, notes, and snippets.

@jhedev
Created May 29, 2015 11:23
Show Gist options
  • Select an option

  • Save jhedev/87b2e5d86f4361a237c4 to your computer and use it in GitHub Desktop.

Select an option

Save jhedev/87b2e5d86f4361a237c4 to your computer and use it in GitHub Desktop.

Revisions

  1. jhedev created this gist May 29, 2015.
    16 changes: 16 additions & 0 deletions problem4.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    problem4 :: [Int] -> Int
    problem4 = read . foldl1 (++) . map show . sortBy f

    f:: Int -> Int -> Ordering
    f x y | v1 == v2 = EQ
    | v1 < v2 = GT
    | v1 > v2 = LT
    where
    v1 = concatInt x y
    v2 = concatInt y x

    toString :: Int -> Int -> String
    toString a b = show a ++ show b

    concatInt :: Int -> Int -> Int
    concatInt a = read . toString a