LetterPress helper

Keywords: decisive advantage, nice combination, count, word, code, explanation, logic, var, scrabble, dictionary, filter, equal, letterpress. Powered by TextRank.

LetterPress is a nice combination of Go and scrabble. Here are a few lines of scala code that will give a decisive advantage

import scala.io.Source
def freq(w:String) : Map[Char,Int] = {
 w.map(x=>(x,1)).groupBy(_._1).map { 
  case (key,values) => (key, values.map(_._2).sum)
  }
}
val src = freq("rfcdpnrxqgeruenaolhntutim")
//val src = freq("wasttaxnmerhenriehxldtihr")
val words = Source.fromFile("corncob_lowercase.txt").getLines.toList.map(_.trim)
val f = words.map(x=>(x, freq(x)))
f.filter(x=> x._2.map({ case (k,v) => src.contains(k) && src(k) >= v}).forall(x=>x == true) )
 .sortWith(_._1.size > _._1.size)
 .take(10)
 .foreach(println)

Explanation

The logic behind it is very simple:


Metadata

Similar posts

Powered by TF-IDF/Cosine similarity

First published on 2018-05-09

Generated on May 5, 2024, 8:48 PM

Index

Mobile optimized version. Desktop version.