Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,22 @@
import Text.Printf (printf)
import Data.Maybe (catMaybes)
import Control.Monad (guard)
input :: [String]
input = [ ""
, "The better the 4-wheel drive, the further you'll be from help when ya get stuck!"
, "headmistressship"
, "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln "
, "..1111111111111111111111111111111111111111111111111111111111111117777888"
, "I never give 'em hell, I just tell the truth, and they think it's hell. "
, " --- Harry S Truman "
, "😍😀🙌💃😍😍😍🙌"
]
collapse :: Eq a => [a] -> [a]
collapse = catMaybes . (\xs -> zipWith (\a b -> guard (a /= b) >> a) (Nothing : xs) (xs <> [Nothing])) . map Just
main :: IO ()
main =
mapM_ (\(a, b) -> printf "old: %3d «««%s»»»\nnew: %3d «««%s»»»\n\n" (length a) a (length b) b)
$ ((,) <*> collapse) <$> input

View file

@ -0,0 +1,7 @@
import Data.List (group)
isCollapsible :: String -> Bool
isCollapsible = any ((1 <) . length) . group
collapsed :: String -> String
collapsed = map head . group

View file

@ -0,0 +1,11 @@
isCollapsible :: String -> Bool
isCollapsible [] = False
isCollapsible [_] = False
isCollapsible (h:t@(x:_)) = h == x || isCollapsible t
collapsed :: String -> String
collapsed [] = []
collapsed [x] = [x]
collapsed (h:t@(x:_))
| h == x = collapsed t
| otherwise = h : collapsed t