๐Ÿ“ฆ malash / codewars-solutions

๐Ÿ“„ largest-5-digit-number-in-a-series.hs ยท 19 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19module LargestDigits where

import Data.Ord

maxInt :: String -> String -> String
maxInt x y = case comparing (read :: String -> Int) x y of
    GT -> x
    LT -> y
    EQ -> x

findDigit :: String -> String
findDigit [] = "0"
findDigit xs = take 5 xs `maxInt` (findDigit . tail $ xs)

digit5 :: String -> Int
digit5 xs
    | length xs <= 5 = read xs
    | otherwise      =  read . findDigit $ xs