Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Amb/Tcl/amb-1.tcl
Normal file
24
Task/Amb/Tcl/amb-1.tcl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
set amb {
|
||||
{the that a}
|
||||
{frog elephant thing}
|
||||
{walked treaded grows}
|
||||
{slowly quickly}
|
||||
}
|
||||
|
||||
proc joins {a b} {
|
||||
expr {[string index $a end] eq [string index $b 0]}
|
||||
}
|
||||
|
||||
foreach i [lindex $amb 0] {
|
||||
foreach j [lindex $amb 1] {
|
||||
if ![joins $i $j] continue
|
||||
foreach k [lindex $amb 2] {
|
||||
if ![joins $j $k] continue
|
||||
foreach l [lindex $amb 3] {
|
||||
if [joins $k $l] {
|
||||
puts [list $i $j $k $l]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Task/Amb/Tcl/amb-2.tcl
Normal file
41
Task/Amb/Tcl/amb-2.tcl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package require Tcl 8.6
|
||||
proc cp {args} {
|
||||
coroutine cp.[incr ::cps] apply {{list args} {
|
||||
yield [info coroutine]
|
||||
foreach item $list {
|
||||
if {[llength $args]} {
|
||||
set c [cp {*}$args]
|
||||
while 1 { yield [list $item {*}[$c]] }
|
||||
} else { yield $item }
|
||||
}
|
||||
return -code break
|
||||
}} {*}$args
|
||||
}
|
||||
proc amb {name filter args} {
|
||||
coroutine $name apply {{filter args} {
|
||||
set c [cp {*}$args]
|
||||
yield [info coroutine]
|
||||
while 1 {
|
||||
set value [$c]
|
||||
if {[{*}$filter $value]} { yield $value }
|
||||
}
|
||||
return -code break
|
||||
}} $filter {*}$args
|
||||
}
|
||||
|
||||
proc joins {a b} {
|
||||
expr {[string index $a end] eq [string index $b 0]}
|
||||
}
|
||||
proc joins* list {
|
||||
foreach a [lrange $list 0 end-1] b [lrange $list 1 end] {
|
||||
if {![joins $a $b]} {return 0}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
amb words joins* \
|
||||
{the that a} \
|
||||
{frog elephant thing} \
|
||||
{walked treaded grows} \
|
||||
{slowly quickly}
|
||||
while 1 { puts [words] }
|
||||
Loading…
Add table
Add a link
Reference in a new issue