Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created May 26, 2012 20:22
Show Gist options
  • Save kosugi/2795197 to your computer and use it in GitHub Desktop.
Save kosugi/2795197 to your computer and use it in GitHub Desktop.
-- -*- coding: utf-8 -*-
import Test.HUnit
deal :: Int -> String -> [String]
deal n s = deal_ 0 (take n $ repeat "") (take ((length s) - (length s `mod` n)) s)
where deal_ _ ys [] = ys
deal_ m ys (x:xs) = deal_ ((m + 1) `mod` n) ((take m ys) ++ [(ys!!m) ++ [x]] ++ (drop (m + 1) ys)) xs
tests = test [
["111", "222", "333"] ~=? deal 3 "123123123",
["12", "23", "31","12"] ~=? deal 4 "123123123",
["000", "111", "222", "333", "444", "555"] ~=? deal 6 "012345012345012345",
["123", "123", "123", "123"] ~=? deal 4 "111122223333",
["012345012345012345"] ~=? deal 1 "012345012345012345",
["", "", "", "", "", ""] ~=? deal 6 "01234",
["", ""] ~=? deal 2 ""]
main = runTestTT tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment