Squashed commit of the following: commit 82aa61982e9c65f65f221fbbcdb41fe8a21321ec Author: AKP <abi@tdpain.net> Date: Thu Nov 9 12:33:56 2023 +0000 Question 5 commit 7239dcaa65545c9a5b8b634213c813438c8e52f8 Author: AKP <abi@tdpain.net> Date: Thu Nov 9 11:47:10 2023 +0000 Question 4 commit 507520373221469ea2f71ee44b67f51dbf9a2455 Author: AKP <abi@tdpain.net> Date: Thu Nov 9 11:40:56 2023 +0000 Question 3 commit 7138150a9c7f34ceb4fdb9c10a018b9cd45cb196 Author: AKP <abi@tdpain.net> Date: Thu Nov 9 11:11:26 2023 +0000 Question 2 commit 808293dff53bd033ea9138ef01a4cb2dfab8fbca Author: AKP <abi@tdpain.net> Date: Thu Nov 9 11:05:24 2023 +0000 Question 1 commit 9f4b80f7e887c0b3665e95ef1be1678e116ec2bc Author: AKP <abi@tdpain.net> Date: Thu Nov 9 11:00:25 2023 +0000 Add base files
56 lines
1.7 KiB
Haskell
56 lines
1.7 KiB
Haskell
-- setting the "warn-incomplete-patterns" flag asks GHC to warn you
|
|
-- about possible missing cases in pattern-matching definitions
|
|
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
|
|
|
|
-- see https://wiki.haskell.org/Safe_Haskell
|
|
{-# LANGUAGE Safe #-}
|
|
|
|
---------------------------------------------------------------------------------
|
|
-------------------------- DO **NOT** MODIFY THIS FILE --------------------------
|
|
---------------------------------------------------------------------------------
|
|
|
|
module Types where
|
|
|
|
-- Question 2
|
|
|
|
factors :: Int -> [Int]
|
|
factors n = [ k | k <- [1..n] , n `mod` k == 0 ]
|
|
|
|
isPrime :: Int -> Bool
|
|
isPrime n = factors n == [1, n]
|
|
|
|
primeFactors :: Int -> [Int]
|
|
primeFactors n = [x | x <- [1..n], n `mod` x == 0 && isPrime x]
|
|
|
|
-- Question 3
|
|
|
|
data TrainStop = BirminghamNewStreet
|
|
| FiveWays
|
|
| University
|
|
| SellyOak
|
|
| Bournville
|
|
| KingsNorton
|
|
| Northfield
|
|
| Longbridge
|
|
| BarntGreen
|
|
| Alvechurch
|
|
| Redditch
|
|
deriving (Eq, Show)
|
|
|
|
theStopAfter :: TrainStop -> TrainStop
|
|
theStopAfter Redditch = Alvechurch
|
|
theStopAfter Alvechurch = BarntGreen
|
|
theStopAfter BarntGreen = Longbridge
|
|
theStopAfter Longbridge = Northfield
|
|
theStopAfter Northfield = KingsNorton
|
|
theStopAfter KingsNorton = Bournville
|
|
theStopAfter Bournville = SellyOak
|
|
theStopAfter SellyOak = University
|
|
theStopAfter University = FiveWays
|
|
theStopAfter FiveWays = BirminghamNewStreet
|
|
theStopAfter BirminghamNewStreet = undefined
|
|
|
|
-- Question 4
|
|
|
|
divideBy2 :: Int -> Int
|
|
divideBy2 n = n `div` 2
|