Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Longest common subsequence
# Length of the longest common subsequence of sequences a and b set a AGCAT set b GAC for {set j -1} {$j<[string length $a]} {incr j} { set l(-1,$j) 0} for {set i 0} {$i<[string length $b]} {incr i} { for {set l($i,-1) 0;set j 0} {$j<[string length $a]} {incr j} { set l($i,$j) [ expr {[string index $b $i]eq[string index $a $j]? 1+$l([expr {$i-1}],[expr {$j-1}]): max($l([expr {$i-1}],$j),$l($i,[expr {$j-1}]))}] }} set o " [join [split $a {}] { }]" for {set i 0} {$i<[string length $b]} {incr i} { append o "\n[string index $b $i]" for {set j 0} {$j<[string length $a]} {incr j} { append o [format %2s $l($i,$j)] }} puts $o puts \nLongest:$l([incr i -1],[incr j -1])
run
|
edit
|
history
|
help
1
Perfect bin mul eo float
Perfect binary mul and even odd assign 2
mysrc.tcl
XorShift On Tcl
1
Counting occurences of substring in string
NISP - Planning ID Unit Test
Convert a collection to a list
Huffman code size
Perfect neg float bin multiplier