Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fp2025:hw3 [2026/05/02 10:49]
silviu [Submission rules]
fp2025:hw3 [2026/05/02 10:58] (current)
silviu
Line 41: Line 41:
  
 <code scala> <code scala>
-def apply(s: String): Board = {+def apply(s: String, p: Player = One): Board = {
     def toPos(c: Char): Player =     def toPos(c: Char): Player =
       c match {       c match {
Line 78: Line 78:
 </​code>​ </​code>​
  
-**7.** Implement the following functions for extracting diagonals above/below the first/​second diagonal, as lines. It's not really necessary to make sure that at least 5 positions are available, for now. Hint: if one function must be implemented with element-by-element iteration, the three other can be implemented using each-other, as single-line calls.+**7.** Implement the following functions for extracting diagonals above/below the first/​second diagonal, as lines. It's not really necessary to make sure that at least 5 positions are available, for now. Hint: if one function must be implemented with element-by-element iteration, the three other can be implemented using each-other, as single-line calls. **Note!** you need to extract the diagonals, **not** the elements that remain above/below the main diagonals.
 <code scala> <code scala>
 def getAboveFstDiag:​ List[Line] = ??? def getAboveFstDiag:​ List[Line] = ???
Line 103: Line 103:
 **11.** Implement a function ''​sequences'',​ that returns a map of the form: ''​(5,​a),​ (4,b), (3,c), (2,​d)''​ where: **11.** Implement a function ''​sequences'',​ that returns a map of the form: ''​(5,​a),​ (4,b), (3,c), (2,​d)''​ where:
   * ''​a''​ is the number sequences of length 5 that the player has established (on lines, columns or diagonals).   * ''​a''​ is the number sequences of length 5 that the player has established (on lines, columns or diagonals).
-  * ''​b''​ is the number of sequences of length 4 **which can be filled-out in order to achieve a 5-sequence**. For example: ''​XX XX''​ is such a sequence for player ''​One'',​ however ''​XX0XX''​ is not, since this cannot be filled-out in order to achieve a 5-sequence.+  * ''​b''​ is the number of sequences of length 4 **which can be filled-out in order to achieve a 5-sequence**. For example: ''​XX.XX''​ is such a sequence for player ''​One'',​ however ''​XX0XX''​ is not, since this cannot be filled-out in order to achieve a 5-sequence. Also, in instances where you have ''​..XXX.''​ you have two ways to complete the row with two additional positions filled resulting in ''​.XXXX''​ and ''​XXXX.''​.
   * ''​c''​ (resp. ''​d''​) is the number of sequences of length 3 (resp. 2) which can be filled-out in order to achieve a 5-sequence.   * ''​c''​ (resp. ''​d''​) is the number of sequences of length 3 (resp. 2) which can be filled-out in order to achieve a 5-sequence.