Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (33 sloc) 1.14 KB
module Y2018.M02.D13.Solution where
Okay, SOME of the articles from yesterday's problem MAY have unicode, and that
plays havok with plain-old String values.
Of course, the solution to that is to use Text values, instead, but will we?
Of course not! Instead, we're going to remove any special characters from
the article texts and deal, instead, with just plain old ASCII.
import Codec.Compression.GZip as GZ
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Char (ord)
import qualified Data.Map as Map
-- below import available via 1HaskellADay git repository
import Y2018.M02.D12.Solution
asciify :: Article -> Article
asciify art = art { text = map asc (text art) }
asc :: Char -> Char
asc c = if ord c < 128 then c else ' '
-- how many articles from yesterday's data set changed?
>>> articles <- json2Arts "Y2018/M02/D12/arts.json.gz"
>>> old = arts articles
>>> length old
>>> new = map asciify old
>>> diffs = zipWith (/=) old new
>>> map fst (filter snd (zip [1..] diffs))
>>> length it
21 out of 26 articles had non-ASCII characters.