Skip to content

Commit

Permalink
Improvements for B182 (#4)
Browse files Browse the repository at this point in the history
* Changed for new semester

* Add GitLab CI config

* intervalSimplify was too complex
  • Loading branch information
MarekSuchanek authored Mar 4, 2019
1 parent bc6dc71 commit b56ac23
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 198 deletions.
18 changes: 18 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
image: haskell:8

variables:
STACK_ROOT: "${CI_PROJECT_DIR}/.stack"

cache:
paths:
- .stack
- .stack-work
- target

stages:
- test

test:
stage: test
script:
- stack test
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ Open `src/Lib.hs` and implement all the TODOs there. You can also check the spec
To complete you will need to work also with `src/Examples.hs` and `src/Data/DummyList/Examples.hs`, but you are **not allowed** to change those nor data types in `src/Lib.hs` and it is also forbidden to add new dependencies.

1. `czechSalutation` should return salutation (in nominative, 1st case = "1. pád") in the Czech language for given person (gender, age, marital status and academic titles must be used appropriately). For details read the comment in code and check test specification, you can also read [(1)](https://www.muni.cz/o-univerzite/uredni-deska/oslovovani-akademickych-pracovniku), [(2)](http://www.etiketavse.estranky.cz/clanky/etiketa/4.-oslovovani-a-spolecenska-vyznamnost.html), and [(3)](http://www.studenta.cz/vysokoskolske-tituly-jak-oslovovat-na-akademicke-pude/magazin/article/587) if interested (Czech only). *Do not edit prepared data types, just implement the function.*
2. `allensComparison` should return relation in [Allen's Interval Algebra](https://en.wikipedia.org/wiki/Allen%27s_interval_algebra) of two given intervals as tuples. Notice that you can use data constructor in infix notation. *Do not edit prepared data type, just implement the function.*
2. `intervalContains` should tell for given number if is in interval or not. *Do not edit prepared data type, just implement the function.*
3. `shapeCircumference` and `shapeArea` should return circumference and area of given shape (can be Circle, Square, Rectangle, or Triangle). *Do not edit prepared data type, just implement the function.*
4. `geometricSequence` should return for given `a` (first parameter) and `r` (second parameter) a [geometric sequence](https://en.wikipedia.org/wiki/Geometric_progression) as endless list.
5. `primes` should return an endless list of [primes](https://en.wikipedia.org/wiki/List_of_prime_numbers). Try to find a solution on your own, don't think too much about effectiveness and enjoy laziness with Haskell. You can use the definition of prime which leads to [generating primes](https://en.wikipedia.org/wiki/Generating_primes).
6. `factorization` should return for a given number a sorted list of its [prime factors](https://en.wikipedia.org/wiki/Prime_factor) in ascending order (e.g. for `50` the result should be `[2,5,5]`, because of `2*5*5 = 50`). Using `primes` is recommended.
7. `phi` should work as [Euler's totient function](https://en.wikipedia.org/wiki/Euler%27s_totient_function) known also as φ or ϕ (Greek letter [Phi](https://en.wikipedia.org/wiki/Phi). You may use `primes` and `factorization` to make your life easier.
8. `dummyListExample1`, `stringExample2`, `stringExample2` should be assigned with values from `Data.DummyList.Examples` (`example1`) and `Data.MyString.Examples` (`example2` and `example3`). It is **not allowed** to copy or "implement" them, working import must be used.
4. `arithmeticSequence` should return for given `a` (first parameter) and `d` (second parameter) a [arithmetic sequence](https://en.wikipedia.org/wiki/Arithmetic_progression) as endless list.
5. `fibonacciNumbers` should return an endless list of [Fibonacci numbers](https://en.wikipedia.org/wiki/Fibonacci_number). Try to find a solution on your own and enjoy laziness with Haskell - it is so easy...
6. `matrixMultiplication` returns a product of two matrices `x` and `y` ([matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication), check the size). You must use list comprehension!
7. `dummyListExample1`, `stringExample2`, `stringExample2` should be assigned with values from `Data.DummyList.Examples` (`example1`) and `Data.MyString.Examples` (`example2` and `example3`). It is **not allowed** to copy or "implement" them, working import must be used.

Hints & general requirements:
Hints & general requirements:

* Being [DRY](https://cs.wikipedia.org/wiki/Don%27t_repeat_yourself) is essential, do not repeat code (for example, in inversed comparison of intervals).
* Local names (via `where` or `let-in`) in functions should be introduced to make the code more readable. Creating helper functions in module scope is **awful**.
* Avoid using `if-then-else` with patterns and guards (and/or combination of those two) if possible and better for readability.
* Look up functions that can help you (`Prelude`, `Data.List`) with general tasks like finding a maximum in list, converting `Integers` to generic numbers, or getting unique values from a list. *Do not re-invent the wheel!*
* You must understand your code completely!

## Notes
## Notes

* In case of uncertainty, check the [dummy homework](https://github.com/MI-AFP/hw00) to recall what is the homework workflow for this course.
* If you encounter some trouble, create an issue in your repository.
Expand Down
77 changes: 35 additions & 42 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,23 @@ czechSalutation = undefined

-------------------------------------------------------------------------------
-- DO NOT EDIT DATA TYPE!
-- https://en.wikipedia.org/wiki/Allen%27s_interval_algebra
-- Notice that even DATA CONSTRUCTOR can be written in infix by using ` `
-- - it is normal, because data constructor is actually function!
--
-- X Y
data AllensIAlgebraRelation a = (a, a) `Equals` (a, a) -- X = Y
| (a, a) `Before` (a, a) -- X < Y
| (a, a) `Meets` (a, a) -- X m Y
| (a, a) `Overlaps` (a, a) -- X o Y
| (a, a) `Starts` (a, a) -- X s Y
| (a, a) `During` (a, a) -- X d Y
| (a, a) `Finishes` (a, a) -- X f Y
deriving (Show, Read, Eq)

-- | Compare two intervals given as tuples and return appropriate
-- | Allen's Interval Algebra relation between them
-- | It assumes that for (x, y) is always x <= y
-- TODO: implement Allen's algebra relation detection of intervals
allensComparison :: Ord a => (a, a) -> (a, a) -> AllensIAlgebraRelation a
allensComparison = undefined
-- https://en.wikipedia.org/wiki/Interval_(mathematics)
data IntervalBoundary = PositiveInfinity
| NegativeInfinity
| Inclusive Double
| Exclusive Double
deriving (Show, Read, Eq)

data Interval = Empty
| Interval IntervalBoundary IntervalBoundary
| Union [Interval]
| Disjoint [Interval]
| AllNumbers
deriving (Show, Read, Eq)

-- | Check if number is in given interval
intervalContains :: Interval -> Double -> Bool
intervalContains = undefined

-------------------------------------------------------------------------------
-- DO NOT EDIT DATA TYPE!
Expand All @@ -75,28 +72,24 @@ shapeArea :: Shape2D -> Double
shapeArea = undefined

-------------------------------------------------------------------------------
-- | Geometric sequence as infinite list
-- | https://en.wikipedia.org/wiki/Geometric_progression
-- TODO: implement geometric series
geometricSequence :: Num b => b -> b -> [b]
geometricSequence a r = undefined


-- TODO: implement infinite list of primes [2, 3, 5, 7, 11, ...]
primes :: [Integer]
primes = undefined

-- TODO: implement list of prime factors for given number (use primes list)
factorization :: Integer -> [Integer]
factorization = undefined


-- | Euler's totient function
-- | https://en.wikipedia.org/wiki/Euler%27s_totient_function
-- TODO: implement phi(n) by using search in primes & factorization
phi :: Integer -> Integer
phi = undefined

-- | Arithmetic sequence as infinite list
-- | https://en.wikipedia.org/wiki/Arithmetic_progression
-- TODO: implement arithmetic series
arithmeticSequence :: Num b => b -> b -> [b]
arithmeticSequence a d = undefined


-- TODO: implement infinite list of fibonacciNumbers [0, 1, 1, 2, 3, 5, ...]
fibonacciNumbers :: [Integer]
fibonacciNumbers = undefined

-- TODO: multiply matrices x and y
-- TODO: use list comprehension!!!
-- https://en.wikipedia.org/wiki/Matrix_multiplication
-- Note: sublists are rows
-- if wrong sizes, raise error "Incorrect matrix sizes" (use "error" function)
matrixMultiplication :: Num a => [[a]] -> [[a]] -> [[a]]
matrixMultiplication x y = undefined
-------------------------------------------------------------------------------
-- !!! DO NOT COPY, JUST IMPORT (avoid conflicts, pick the best option for you)
-- iii visit the content of modules
Expand Down
Loading

0 comments on commit b56ac23

Please sign in to comment.