Created
March 9, 2021 09:09
-
-
Save viercc/aa52e1cfeeb250e28b6e43df7a5f80e1 to your computer and use it in GitHub Desktop.
Answering effectfully<HYPHEN>ou/haskell<HYPHEN>challenges<SLASH>h4-largest-powers
This file contains hidden or 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
| module Lib | |
| ( largestPowersInt ) where | |
| class Eq a => Iterable a where | |
| zer :: a | |
| inc :: a -> a | |
| dec :: a -> a | |
| instance Iterable Int where | |
| zer = 0 | |
| inc = succ | |
| dec = pred | |
| largestPowersInt :: Int -> [Int] | |
| largestPowersInt = largestPowers | |
| largestPowers :: Iterable a => Int -> [a] | |
| largestPowers n = aux (inc zer) | |
| where aux k = spread (n-1) k (aux (inc k)) | |
| -- > spread 2 '.' "apple" = "..a..p..p..l..e.." | |
| spread :: Int -> a -> [a] -> [a] | |
| spread n space as = spaces ++ (as >>= \a -> a : spaces) | |
| where spaces = replicate n space |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment