Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The app reads text from the clipboard -- the text is two columns of
- -- words separated by tab characters -- removes the first column and
- -- the tab characters, splits the remaining text into single letters,
- -- removes duplicates, shuffles the letters and capitalizez the
- -- letters. The result is stored in the clipboard.
- import System.Hclip (getClipboard, setClipboard)
- import Data.List (dropWhile, intersperse, nub, transpose)
- import Data.Char (toUpper)
- import System.Exit (die)
- main :: IO ()
- main = do
- input <- getClipboard
- if null input
- then die "The clipboard is empty!"
- else setClipboard $
- insertNewLines $
- stringToUppers $
- stringShuffler $ reverse $ nub $ concatMap dropAtTab (lines input)
- dropAtTab :: String -> String
- dropAtTab [] = []
- dropAtTab string = tail $ dropWhile (/= '\t') string
- stringToUppers :: String -> String
- stringToUppers [] = []
- stringToUppers string = map toUpper string
- insertNewLines :: String -> String
- insertNewLines [] = []
- insertNewLines string = intersperse '\n' string
- stringShuffler :: String -> String
- stringShuffler string =
- concat $ transpose $ chunksOf (transposableSize string) string
- where
- transposableSize lst = roundedUpSquareRoot $ length lst
- roundedUpSquareRoot :: (Integral t, Integral b) => t -> b
- roundedUpSquareRoot x = truncate $ sqrt x_double
- where
- x_double = fromIntegral x :: Double
- chunksOf :: Int -> [a] -> [[a]]
- chunksOf _ [] = []
- chunksOf size string = take size string : chunksOf size (drop size string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement