Attic/resit.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 14 Jul 2024 14:31:39 +0100
changeset 492 4ffba2f72692
parent 477 a4e1f63157d8
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
459
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
// Resit about Evil Wordle
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
//==========================
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
object Resit { 
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
import io.Source
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
import scala.util._
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
// ADD YOUR CODE BELOW
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
//======================
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
//(1)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
def get_wordle_list(url: String) : List[String] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
d59404a41d5f updated
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")
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
// secrets.length // => 12972
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
// secrets.filter(_.length != 5) // => Nil
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
//(2)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
def removeN[A](xs: List[A], elem: A, n: Int) : List[A] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
d59404a41d5f updated
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)
d59404a41d5f updated
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)
d59404a41d5f updated
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)
d59404a41d5f updated
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)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
// (3)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
abstract class Tip
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
case object Absent extends Tip
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
case object Present extends Tip
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
case object Correct extends Tip
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
def pool(secret: String, word: String) : List[Char] = ??? 
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
def aux(secret: List[Char], word: List[Char], pool: List[Char]) : List[Tip] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
def score(secret: String, word: String) : List[Tip] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
// score("chess", "caves") // => List(Correct, Absent, Absent, Present, Correct)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
// score("doses", "slide") // => List(Present, Absent, Absent, Present, Present)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
// score("chess", "swiss") // => List(Absent, Absent, Absent, Correct, Correct)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
// score("chess", "eexss") // => List(Present, Absent, Absent, Correct, Correct)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
// (4)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
def eval(t: Tip) : Int = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
def iscore(secret: String, word: String) : Int = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54
//iscore("chess", "caves") // => 21
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    55
//iscore("chess", "swiss") // => 20
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
// (5)
d59404a41d5f updated
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] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
def evil(secrets: List[String], word: String) : List[String] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
//evil(secrets, "stent").length
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
//evil(secrets, "hexes").length
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
//evil(secrets, "horse").length
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
//evil(secrets, "hoise").length
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
//evil(secrets, "house").length
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
// (6)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
def frequencies(secrets: List[String]) : Map[Char, Double] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
// (7)
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
def rank(frqs: Map[Char, Double], s: String) : Double = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
def ranked_evil(secrets: List[String], word: String) : List[String] = ???
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
d59404a41d5f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
}