Skip to content

Instantly share code, notes, and snippets.

@erica
Last active January 10, 2022 00:36
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 erica/54f25c47a656c247dc080c09a6acef20 to your computer and use it in GitHub Desktop.
Save erica/54f25c47a656c247dc080c09a6acef20 to your computer and use it in GitHub Desktop.
import Foundation
let string = """
Wordle 204 6/6
⬜⬜⬜⬜🟨
🟨🟨⬜⬜⬜
⬜🟩🟩🟨⬜
⬜🟩🟩⬜🟩
⬜🟩🟩⬜🟩
🟩🟩🟩🟩🟩
"""
let lines = string.components(separatedBy: .newlines)
let solution = lines[2...]
let wordles = lines[0]
.components(separatedBy: CharacterSet.init(charactersIn: " /"))
let solutions = solution
.map({ line -> String in
let correct = line.filter({$0 == "🟩"}).count
let wrongPosition = line.filter({$0 == "🟨"}).count
if correct == 5 { return "was the correct solution." }
if correct == 0 && wrongPosition == 0 { return "was completely incorrect." }
let sCorrect = correct > 1 ? "s" : ""
let sWrong = wrongPosition > 1 ? "s" : ""
if correct == 0 {
return "had \(wrongPosition) letter\(sWrong) in the wrong position."
}
if wrongPosition == 0 {
return "had \(correct) letter\(sCorrect) in the right position."
}
return "had \(correct) letter\(sCorrect) in the right position and \(wrongPosition) letter\(sWrong) in the wrong position."
})
.enumerated()
.map({ (count: Int, line: String) -> String in
"Guess \(count + 1) " + line
})
let axdescription = """
The visual summary of a wordle game session. The player used \(wordles[2]) guesses out of \(wordles[3]).
""" + solutions.joined(separator: "\n")
print(axdescription)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment