Last active
May 4, 2018 00:15
-
-
Save briancordanyoung/49bf65bd40ba995c9f1f9dd799ad5f68 to your computer and use it in GitHub Desktop.
Rough code for to count the 100 point words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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