Longest common subsequence: Difference between revisions

m
→‎{{header|Tcl}}: Small fixes, better organization
(Logo)
m (→‎{{header|Tcl}}: Small fixes, better organization)
Line 481:
=={{header|Tcl}}==
Both solutions translated from the Java.
===Recursive===
{{works with|Tcl|8.5}}
<lang tcl>rocproc r_lcs {a b} {
'''recursive'''
<lang tcl>roc r_lcs {a b} {
if {$a eq "" || $b eq ""} {return ""}
set a_ [string range $a 1 end]
Line 494 ⟶ 493:
return [expr {[string length $x] > [string length $y] ? $x :$y}]
}
}</lang>
===Dynamic===
'''dynamic'''
{{works with|Tcl|8.5}}
<lang tcl>package require Tcl 8.5
namespace import ::tcl::mathop::+
Line 535:
return [string reverse $result]
}</lang>
===Performance: Comparison===
<prelang tcl>% time {d_lcs thisisatest testing123testing} 10
637.5 microseconds per iteration
% time {r_lcs thisisatest testing123testing} 10
1275566.8 microseconds per iteration</prelang>
Anonymous user