Longest common subsequence: Difference between revisions

add caching to m4, mostly to make performance more bearable
(add m4)
(add caching to m4, mostly to make performance more bearable)
Line 405:
=={{header|M4}}==
<lang M4>
define(`set2d',`define(`$1[$2][$3]',`$4')')
define(`get2d',`defn($1[$2][$3])')
define(`tryboth',
`pushdef(`x',lcs(`$1',substr(`$2',1),`$1 $2'))`'pushdef(`y',
Line 414 ⟶ 416:
`tryboth(`$1',`$2')')')
define(`lcs',
`ifelse(get2d(`$1',`c',`$1',`$2'),`',`',`checkfirst(`$1',`$2')')')
`pushdef(`a',ifelse(
`$1',`',`',
`$2',`',`',
`checkfirst(`$1',`$2')'))`'a`'set2d(`c',`$1',`$2',a)`'popdef(`a')',
`get2d(`c',`$1',`$2')')')
 
lcs(`1234',`1224533324')
 
lcs(`thisisatest',`testing123testing')
</lang>
Note: the caching (set2d/get2d) obscures the code even more than usual, but is necessary in order to get the second test to run in a reasonable amount of time.
 
=={{header|Mathematica}}==
Anonymous user