Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions modules/fun/wordle.nu
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ export def main [
--max_count(-M) : int = 6 # Give yourself more chances than default
--alternative_source(-a) : string = "https://raw.githubusercontent.com/charlesreid1/five-letter-words/master/sgb-words.txt" # Alternative link to provide as a word source
] {
let words = (if ($alternative_source | str substring 0..4 | str contains "http") {http get $alternative_source} else {open $alternative_source} | from ssv -n)
let word = ($words | get (random int 0..($words | length)) | get column1)
if ((($words | each {|it| ($it.column1 | str length)}) | where $it != 5 | length) != 0 ) {
echo $"(ansi rb)Warning:(ansi reset) The words list contains words that are not length 5"
let words = (if ($alternative_source | str starts-with "http") {http get $alternative_source} else {open $alternative_source} | lines)
let word = ($words | get (random int 0..($words | length)))
if ((($words | each {|it| $it | str length}) | where $it != 5 | length) != 0 ) {
print $"(ansi rb)Warning:(ansi reset) The words list contains words that are not length 5"
}
mut end = false
mut guess_count = 0
mut avail = "abcdefghijklmnopqrstuvyxwz"
mut avail = "abcdefghijklmnopqrstuvwxyz"
while (not ($end)) {
$guess_count += 1
if ($guess_count <= $max_count or $unlimited) {
echo $"(ansi xterm_aquamarine1a)Enter your guess (ansi reset)\((ansi green)($guess_count)(ansi reset)/(ansi yellow)(if ($unlimited) {inf} else {$max_count})(ansi reset)\)"
mut guess = (input | str downcase )
if (((($words | where column1 =~ $guess) | length) >= 1) and ($guess | str length) == 5) {
print $"(ansi xterm_aquamarine1a)Enter your guess (ansi reset)\((ansi green)($guess_count)(ansi reset)/(ansi yellow)(if ($unlimited) {inf} else {$max_count})(ansi reset)\)"
let guess = (input | str downcase)
if ($guess | str length) == 5 and ($words | any {|w| $w == $guess}) {
mut out = ""
mut checked = $word
for i in ($guess | split chars | enumerate) {
if ($i.item == ($word | str substring ($i.index)..($i.index + 1)) ) {
if ($i.item == ($word | str substring ($i.index)..($i.index)) ) {
$out += $"(ansi green_reverse)($i.item)(ansi reset)"
$avail = ($avail | str replace $i.item $"(ansi green_reverse)($i.item)(ansi white_reverse)")
$checked = ($checked | str replace $i.item "")
Expand All @@ -38,17 +38,17 @@ export def main [
}
}
$avail = $"(ansi white_reverse)($avail)(ansi reset)"
echo $"($out) possible -> ($avail)"
print $"($out) possible -> ($avail)"
if ($guess == $word) {
$end = true
echo $"(ansi xterm_green1 )You guessed right!(ansi reset)"
print $"(ansi xterm_green1 )You guessed right!(ansi reset)"
}
} else {
echo "please enter a valid [5 letter] word!"
$guess_count -= 1
print "please enter a valid [5 letter] word!"
$guess_count -= 1
}
} else {
echo $"(ansi yellow )You loose, the word was: (ansi red)($word)(ansi reset)"
print $"(ansi yellow )You loose, the word was: (ansi red)($word)(ansi reset)"
$end = true
}
}
Expand Down
Loading