Skip to content

Instantly share code, notes, and snippets.

View MiyamonY's full-sized avatar
🏠
Working from home

MiyamonY

🏠
Working from home
View GitHub Profile
import System.Random
import Control.Monad (when)
main :: IO ()
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
import System.Random
import Control.Monad (when)
main :: IO ()
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
import System.Random
main :: IO ()
main = do
gen <- getStdGen
putStrLn $ take 20 $ randomRs ('a', 'z') gen
gen' <- newStdGen
putStrLn $ take 20 $ randomRs ('a', 'z') gen'
import System.Random
threeCoins :: StdGen -> (Bool, Bool, Bool)
threeCoins gen =
let (firstCoin, newGen) = random gen
(secondCoin, newGen') = random newGen
(thirdCoin, _) = random newGen'
in (firstCoin, secondCoin, thirdCoin)
-- threeCoins (mkStdGen 100)
import System.Random
threeCoins :: StdGen -> (Bool, Bool, Bool)
threeCoins gen =
let (firstCoin, newGen) = random gen
(secondCoin, newGen') = random newGen
(thirdCoin, _) = random newGen'
in (firstCoin, secondCoin, thirdCoin)
-- threeCoins (mkStdGen 100)
import System.Environment
import System.Directory
import System.IO
import Data.List
import Control.Exception
dispatch :: String -> [String] -> IO ()
dispatch "add" = add
dispatch "view" = view
dispatch "remove" = remove
import System.Environment
import Data.List
main :: IO ()
main = do
args <- getArgs
progName <- getProgName
putStrLn "The arguments are:"
mapM putStrLn args
putStrLn "The program name is:"
import System.IO
import System.Directory
import Data.List
import Control.Exception
main :: IO ()
main = do
contents <- readFile "todo.txt"
let todoTasks = lines contents
numberedTasks = zipWith (\ n line -> show n ++ " - " ++ line)
import System.IO ()
main :: IO ()
main = do
todoItem <- getLine
appendFile "todo.txt" (todoItem ++ "\n")
import System.IO ()
import Data.Char
main :: IO ()
main = do
contents <- readFile "baabaa.txt"
writeFile "baabaacaps.txt" (map toUpper contents)