Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- import qualified Data.ByteString.Char8 as B
- import Data.Maybe
- import Data.List
- import Control.Arrow
- readInt :: B.ByteString -> Int
- readInt = fst . fromJust . B.readInt
- main :: IO ()
- main = do
- [len] <- liftM (map readInt . B.words) B.getLine
- lst <- liftM (map readInt . take len . B.words) B.getLine :: IO [Int]
- [n] <- liftM (map readInt . B.words) B.getLine
- putStrLn "Input: "
- print lst
- print n
- putStrLn "Result: "
- print (distribute lst len n n)
- erase idx xs = lft ++ rgt
- where (lft, (_:rgt)) = splitAt idx xs
- distribute _ _ _ 0 = []
- distribute [] _ _ todo = [[]] ++ distribute [] 0 0 (todo - 1)
- distribute (h:t) len groups todo = [sublst] ++ distribute t (len - 1) groups (todo - 1)
- where sublst = select_sublist ([h] ++ t) len 0 groups
- select_sublist [] n i m = []
- select_sublist (h:t) n i m | mod i m == 0 = [h] ++ select_sublist t n (i + 1) m
- | otherwise = (select_sublist t n (i + 1) m)
- -- 10
- -- 1 2 3 4 5 6 7 8 9 10
- -- 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement