You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1010 B

set ints [list 1 2 3 4 5 6]
set k 5
cartesianpairs1.= {foreach i $ints {foreach j $ints {lappend out [list $i $j]}}; set out} <ints| {*}$ints
pipeset cpairs1 .= {foreach i $ints {foreach j $ints {lappend out [list $i $j]}}; set out} <ints|
pipeset cpairs2 .= {foreach i $a {foreach j $b {lappend out [list $i $j]}}; set out} <a@0,b@1|
pipeset alg .= list |> \
{inspect -label K= $k} |> \
.= {foreach i $ints {foreach j $ints {lappend out [list $i $j]}}; set out} |> \
list_filter_cond { = $item |a/0,b/1> .= {expr $b > $a}} |> \
{list_filter_cond { .= list $item $k |a/0/0,b/0/1,k/1> \
.= {expr {($a + $b) % $k == 0} }} $data } <k/head,ints/tail|
puts [{*}$alg $k {*}$ints]
#todo
#https://wiki.tcl-lang.org/page/cons
proc cons {a b} {list $a $b}
proc car {p} {lindex $p 0}
proc cdr {p} {lindex $p 1}
proc LIST args {
if {![llength $args]} {
return {}
} else {
return [cons [lindex $args 0] [LIST {*}[lrange $args 1 end]]]
}
}