// // program to find words that can be formed from list of letters // // command line argument: name of file with list of words // import scala.io.Source if (args.length < 1) { println("need file as command-line argument") sys.exit() } println("your Scrabble letters (no spaces):") val letters = readLine println("words that can be formed:") val wordfile = Source.fromFile(args(0)) for (wordInFile <- wordfile.getLines) { if (canMakeThisWord(wordInFile, letters)) println(wordInFile) } wordfile.close // say whether the word can be formed with the given letters // not as efficient as it could be but gets the job done def canMakeThisWord(wordInFile : String, letters : String) : Boolean = { var result = true for (ch <- wordInFile.toArray) { if (wordInFile.count(_ == ch) > letters.count(_ == ch)) result = false } result }