Determine if a string is collapsible: Difference between revisions

Content deleted Content added
Line 658: Line 658:
, "I never give 'em hell, I just tell the truth, and they think it's hell. "
, "I never give 'em hell, I just tell the truth, and they think it's hell. "
, " --- Harry S Truman "
, " --- Harry S Truman "
, "😍😀🙌💃😍😍😍🙌"
]
]


collapse :: String -> String
collapse :: Eq a => [a] -> [a]
collapse s = catMaybes $ zipWith (\a b -> if a /= b then a else Nothing) (Nothing : ms) (ms <> [Nothing])
collapse s = catMaybes $ zipWith (\a b -> if a /= b then a else Nothing) (Nothing : ms) (ms <> [Nothing])
where ms = map Just s
where ms = map Just s
Line 691: Line 692:
old: 72 ««« --- Harry S Truman »»»
old: 72 ««« --- Harry S Truman »»»
new: 17 ««« - Hary S Truman »»»
new: 17 ««« - Hary S Truman »»»

old: 8 «««😍😀🙌💃😍😍😍🙌»»»
new: 6 «««😍😀🙌💃😍🙌»»»
</pre>
</pre>