Re: ブロックソートを Haskell で書いてみた

ref: http://d.hatena.ne.jp/mono-hate/20081119/1227100016

おお、面白い。ブロックソートは全然知らなかったので、ぼくも書いてみた。

import Data.List (sort, tails, transpose, elemIndex)
import Data.Maybe (fromJust)

encode s = (succ $ fromJust $ elemIndex s t, last $ transpose t)
 where t = sort $ map f $ f $ tails $ cycle s
       f = take (length s)

decode (n, s) = iterate f (repeat []) !! length s !! pred n
 where f = sort . zipWith (:) s

あんまり変わらないですね。
関係ないけど、キャメルケースの関数を使ったら負けた気になる。fromJust とか zipWith とか。