Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
fp:lab09 [2021/05/13 12:01] pdmatei created |
fp:lab09 [2021/05/13 17:39] (current) pdmatei |
||
---|---|---|---|
Line 37: | Line 37: | ||
9.1.3. Implement the ADT of an ID, where an ID may be defined as: | 9.1.3. Implement the ADT of an ID, where an ID may be defined as: | ||
- | - a CNP (Personal Identification Number). In Romania, the CNP has the following structure: ''SDDMMYYXXXXXX'' where: | + | * a CNP (Personal Identification Number). In Romania, the CNP has the following structure: ''SDDMMYYXXXXXX'' where: |
- ''S'' is the **gender** and **birth-period** digit: | - ''S'' is the **gender** and **birth-period** digit: | ||
- ''S=1'' - male born before year ''2000'' | - ''S=1'' - male born before year ''2000'' | ||
Line 46: | Line 46: | ||
- ''XXXXXX'' - the last six digits encode other info which are not relevant for us. | - ''XXXXXX'' - the last six digits encode other info which are not relevant for us. | ||
or | or | ||
- | + | * a collection of strings which represent: | |
- | - a collection of strings which represent: | + | |
- Full name | - Full name | ||
- Complete year of birth | - Complete year of birth | ||
- gender (''male'' or ''female'') | - gender (''male'' or ''female'') | ||
- | * Implement the type ''Gender'' (it is better to define a gender separately, instead of using True/False or strings, because it reduces the occurrence of bugs). | + | * Implement the type ''Gender'' (it is better to define a gender separately, instead of using True/False or strings, because it reduces the occurrence of bugs). |
- | * Implement a function which takes a gender, a list of ID's and returns those having that gender (you can safely assume that the CNP has valid form. **Hint:** use functional closures and higher-order functions). | + | * Implement a function which takes a gender, a list of ID's and returns those having that gender (you can safely assume that the CNP has valid form. **Hint:** use functional closures and higher-order functions). |
<code haskell> | <code haskell> | ||
Line 65: | Line 64: | ||
</code> | </code> | ||
- | 9.1.5. (**Optional**) Define an ADTs called ''Range'', which encodes a **range** of birth years together with a gender. For instance: | + | 9.1.5. Define an ADTs called ''Range'', which encodes a **range** of birth years together with a gender. For instance: |
- one range could designate people of gender //female// born between 1956 and 2005 | - one range could designate people of gender //female// born between 1956 and 2005 | ||
- another range could designate both //male// and //female// born between 1991 and 2006 | - another range could designate both //male// and //female// born between 1991 and 2006 | ||
Line 97: | Line 96: | ||
- | ===== 9.3. Trees ===== | ||
- | |||
- | 9.3.1. Implement a datatype for trees of integers. Write a function which checks if a tree is complete: | ||
- | <haskell code> | ||
- | isComplete :: IntTree -> Bool | ||
- | </haskell> | ||
- | |||
- | 9.3.2. Write a function which flattens a tree to a list: | ||
- | <haskell code> | ||
- | flatten :: IntTree -> [Integer] | ||
- | </code> | ||
- | |||
- | 9.3.3. The game Tic-Tac-Toe (or X and 0) is played on a three-by-three board of **positions**. Each position may be: free, with an X or with a 0. | ||
- | * write a ADT ''Position'' which encodes the value of each position. | ||
- | * write an ADT ''Board'' which encodes (using matrices) a 3-by-3 board of positions. | ||
- | * write a function which checks if either '''X''' or '''0''' have won (''won :: Char -> Board -> Bool'') | ||
- | |||
- | Starting from a given (initial) board, we want to build **a tree** of all possible outcomes of the game. |