Largest int from concatenated ints: Difference between revisions
Content added Content deleted
Line 110: | Line 110: | ||
Since repeating numerical string "1234" is the same as taking all the digits of 1234/9999 after the decimal point, the following does essentially the same as above: |
Since repeating numerical string "1234" is the same as taking all the digits of 1234/9999 after the decimal point, the following does essentially the same as above: |
||
<lang haskell>import Data.List (sortBy) |
<lang haskell>import Data.List (sortBy) |
||
import Data.Ord (comparing) |
|||
import Data.Ratio ((%)) |
|||
nines = iterate ((+9).(*10)) 9 |
nines = iterate ((+9).(*10)) 9 |
||
maxcat = foldl (\a (n,d)->a * (1 + d) + n) 0 . |
maxcat = foldl (\a (n,d)->a * (1 + d) + n) 0 . |
||
sortBy ( |
sortBy (flip $ comparing $ uncurry (%)) . |
||
map (\a->(a, head $ dropWhile (<a) nines)) |
map (\a->(a, head $ dropWhile (<a) nines)) |
||