class Scrambler {
	def scramble(word) {
		Random rand = new Random()
		def result = (word.length()..1).inject(["", word]) { carry, index ->
			def randomNumber = rand.nextInt(index)
			def buildString = carry[0]
			def stripString = carry[1]
			def letter = stripString[randomNumber]
		  [buildString << letter, stripString - letter]
		}
		result[0]
	}
	
	def score(scrambled, guess) {
		if(guess.length() > scrambled.length())
		  throw new RuntimeException("Too many letters")
		
		if(guess.find { !scrambled.contains(it) })
		  0
	  else
		  13
	}
	
	def scoreForLetter(letter) {
		def letterScores = [
		A : 1, C : 1, D : 1, E : 1, I : 1, N : 1, O : 1, R : 1, S : 1, T : 1,
		G : 2, H : 2, L : 2,
		K : 3, W : 3, X : 3,
		M : 4, U : 4, Y : 4,
		P : 5, V : 5, Z : 5,
		B : 8, F : 8, Q : 8,
		J : 10
		]
		
		letterScores.get(letter)
	}
}