Skip to content

Instantly share code, notes, and snippets.

@benjcal
Last active September 12, 2022 13:31
Show Gist options
  • Save benjcal/eb877e919bc3708cc21b6afb7aa45564 to your computer and use it in GitHub Desktop.
Save benjcal/eb877e919bc3708cc21b6afb7aa45564 to your computer and use it in GitHub Desktop.
Wordle with Tcl
# wordle.tcl
set inc_l s
set excl_l judgemcbn
set inc_pt [list '.la.k' ]
set excl_pt [list 's....']
proc include-letters {letters} {
set letters_list [split $letters {}]
lmap x $letters_list {
set x "rg $x"
}
}
proc exclude-letters {letters} {
set letters_list [split $letters {}]
lmap x $letters_list {
set x "rg -v $x"
}
}
proc include-pattern {pattern} {
list "rg -e $pattern"
}
proc exlclude-pattern {pattern} {
list "rg -ve $pattern"
}
set cmd [list {cat /usr/share/dict/words}]
lappend cmd {*}[include-pattern {'^.....$'}]
if {[info exists inc_l]} {
lappend cmd {*}[include-letters $inc_l]
}
if {[info exists excl_l]} {
lappend cmd {*}[exclude-letters $excl_l]
}
if {[info exists inc_pt]} {
foreach pt $inc_pt {
lappend cmd {*}[include-pattern $pt]
}
}
if {[info exists excl_pt]} {
foreach pt $excl_pt {
lappend cmd {*}[exlclude-pattern $pt]
}
}
set cmd [join $cmd |]
# puts $cmd
set out [exec zsh -c $cmd]
puts $out
puts {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment