I wrote: > jim burton <[EMAIL PROTECTED]> wrote: > > Thankyou! It's http://www.rubyquiz.com - They are mostly well suited to > > haskell, lot of mazes etc. I've done 5 or 6 with varying degrees of success > > but have learned a lot. This thing about strings in fifths is from #1, the > > solitaire cipher. > > At a quick glance I can't see which bit needs it. The only > mention of five is where it asks to split the string into > groups of five characters (not into five equal parts), > padded with Xs. > > You can do that like this: > > splitAtMb n l = let p = splitAt n l > in if null $ fst p > then Nothing > else Just p
Gah! Brain AWOL. I'm surprised no-one picked me up on that. Why didn't I use: splitAtMb n [] = Nothing splitAtMb n l = Just $ splitAt n l ? > in_fives l = unfoldr (splitAtMb 5) > (l ++ replicate (length l `mod` 5) 'X') And using length makes this over-strict. maybe something like groups_of n = unfoldr (splitPad 5) where splitPad [] = Nothing splitPad l = Just $ mapFst (padwith 'X') (splitAt n l) padwith c l = take n $ l ++ replicate n c mapFst f (a,b) = (f a, b) -- in Data.Graph.Inductive.Query.Monad which is a little bit inefficient, but less clunky than checking for the end of list in order to apply padwith just once. -- Jón Fairbairn [EMAIL PROTECTED] _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe