Skip to content

Instantly share code, notes, and snippets.

@jagajaga
Created November 8, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagajaga/a1da69bd287dbba3ec2c to your computer and use it in GitHub Desktop.
Save jagajaga/a1da69bd287dbba3ec2c to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.List
import Data.Text (Text)
import Data.Text.IO as IO
import Prelude hiding (drop, lenght, take)
import System.Random
type Tasks = [[ Text ]]
type TasksWithBackup = ([ Text ], [ Text ])
type Version = [ Text ]
deleteNth n xs = take (n-1) xs ++ drop n xs
genVer :: [TasksWithBackup] -> IO ([TasksWithBackup], Version)
genVer t = do
mapM getItem t >>= return . foldl (\(a, b) (c, d) -> (a ++ [c], b ++ d)) ([], [])
where
getItem :: TasksWithBackup -> IO (TasksWithBackup, Version)
getItem (tasks, allTasks) = do
i <- randomRIO (0, 1000) >>= return . flip mod (length tasks)
let res = tasks !! i
let newTasks = if (length tasks) - 1 == 0 then allTasks else (deleteNth i tasks)
return $ ((newTasks, allTasks), [res])
generate :: Int -> [TasksWithBackup] -> IO [Version]
generate n tasks | n > 0 = do
(newTasks, ver) <- genVer tasks
vars <- (generate (n - 1) newTasks)
return $ ver:vars
generate n tasks = return []
canonizeTasks :: Tasks -> [TasksWithBackup]
canonizeTasks a = map (\b -> (b, b)) a
main = do
versions <- generate 45 $ canonizeTasks cw
mapM_ (\(n, v) -> print n >> IO.putStrLn header >> mapM_ IO.putStrLn (concat $ zipWith (\a b -> a : [b]) exers v) >> IO.putStrLn "-------------") $ zip [1..] versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment