459
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
// Main Part 2 about Evil Wordle
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
//===============================
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
object M2 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
import io.Source
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
import scala.util._
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
// ADD YOUR CODE BELOW
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
//======================
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
//(1)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
def get_wordle_list(url: String) : List[String] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
// val secrets = get_wordle_list("https://nms.kcl.ac.uk/christian.urban/wordle.txt")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
// secrets.length // => 12972
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
// secrets.filter(_.length != 5) // => Nil
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
//(2)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
def removeN[A](xs: List[A], elem: A, n: Int) : List[A] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
25 |
// removeN(List(1,2,3,2,1), 3, 1) // => List(1, 2, 2, 1)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
// removeN(List(1,2,3,2,1), 2, 1) // => List(1, 3, 2, 1)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
// removeN(List(1,2,3,2,1), 1, 1) // => List(2, 3, 2, 1)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
// removeN(List(1,2,3,2,1), 0, 2) // => List(1, 2, 3, 2, 1)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
// (3)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
abstract class Tip
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
case object Absent extends Tip
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
case object Present extends Tip
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
case object Correct extends Tip
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
def pool(secret: String, word: String) : List[Char] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
def aux(secret: List[Char], word: List[Char], pool: List[Char]) : List[Tip] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
def score(secret: String, word: String) : List[Tip] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
// score("chess", "caves") // => List(Correct, Absent, Absent, Present, Correct)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
// score("doses", "slide") // => List(Present, Absent, Absent, Present, Present)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
// score("chess", "swiss") // => List(Absent, Absent, Absent, Correct, Correct)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
// score("chess", "eexss") // => List(Present, Absent, Absent, Correct, Correct)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
// (4)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
def eval(t: Tip) : Int = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
def iscore(secret: String, word: String) : Int = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
//iscore("chess", "caves") // => 21
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
//iscore("chess", "swiss") // => 20
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
// (5)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
def lowest(secrets: List[String], word: String, current: Int, acc: List[String]) : List[String] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
def evil(secrets: List[String], word: String) : List[String] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
//evil(secrets, "stent").length
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
//evil(secrets, "hexes").length
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
//evil(secrets, "horse").length
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
//evil(secrets, "hoise").length
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
//evil(secrets, "house").length
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
// (6)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
def frequencies(secrets: List[String]) : Map[Char, Double] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
// (7)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
def rank(frqs: Map[Char, Double], s: String) : Double = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
def ranked_evil(secrets: List[String], word: String) : List[String] = ???
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
}
|