Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancordanyoung/49bf65bd40ba995c9f1f9dd799ad5f68 to your computer and use it in GitHub Desktop.
Save briancordanyoung/49bf65bd40ba995c9f1f9dd799ad5f68 to your computer and use it in GitHub Desktop.
Rough code for to count the 100 point words
import Cocoa
// a = 97
// z = 122
let value = UInt8(ascii: "z")
extension Character {
var testValues: UInt8? {
guard let scaler = self.unicodeScalars.first else { return .none}
let value = UInt8(ascii: scaler)
return value - 96
}
}
// "quarter".reduce(0, {sum, character in
// sum + character.testvalues
// })
//
func countValue(word: String) -> UInt8 {
var sum: UInt8 = 0
for character in word {
if let charValue = character.testValues {
sum = sum + charValue
}
}
return sum
}
var dictionary: String = ""
do {
dictionary = try String(contentsOfFile: "/usr/share/dict/web2")
} catch {
}
let words = dictionary.split(separator: "\n")
words.count
var oneHundredValueWords: [String] = []
//words.forEach {
// if (countValue(word: String($0)) == 100) {
// oneHundredValueWords.append(String($0))
// }
//}
for word in words {
if (countValue(word: String(word)) == 100) {
oneHundredValueWords.append(String($0))
}
}
oneHundredValueWords.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment