Tag Archives: overengineered

Ridiculous UTF-8 character counting

So, Colin Percival has posted a UTF-8 strlen which improves on my previous post. While his code runs slightly slower than mine on my PC, I assume that’s because his code is aimed at a 64-bit architecture. With 32-bits (reading 4 bytes at a time, instead of 8 ) it doesn’t quite get the same [...]

Overengineering

Douglas, you’re not alone.

import Data.List (sortBy)
import Data.Function (on)
import Data.Maybe (mapMaybe)
import Control.Monad.Instances
 
gizzabuzz pairs combiner = zipWith ($) (cycle funcs) [1..]
where
sortedPairs = sortBy (compare `on` fst) pairs
funcs = map (\n -> display $ mapMaybe (filterOut n) sortedPairs) [1..foldr1 lcm $ map fst $ sortedPairs]
display [] = show
display xs = foldr1 combiner . sequence (map const xs)
filterOut [...]