<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 30 Mar 2020, at 12:18, I Gusti Ngurah Oka Prinarjaya <<a href="mailto:okaprinarjaya@gmail.com" class="">okaprinarjaya@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">I need longest common substring erlang implementation. Please help me</div><div class=""><br class=""></div><div class="">I've tried <a href="https://rosettacode.org/wiki/Longest_common_subsequence#Erlang" class="">https://rosettacode.org/wiki/Longest_common_subsequence#Erlang</a> but very very slow T_T</div><div class=""><br class=""></div><div class="">and i've tried <span style="color:rgb(0,128,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre" class="">binary:longest_common_prefix([<<"i love you 2020-03-28">>,<<"i love you 2020-03-01">>])</span> not effective / not valid</div><div class=""><br class=""></div><div class="">Thank you </div><div class=""><br class=""></div></div>
</div></blockquote></div><br class=""><div class="">It may be faster to do this with lists, but this should do the trick:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class="">lcs( <<A/binary>>, <<B/binary>>, Off )</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class="">-></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class=""> case {A, B} of</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class=""> {<<_:Off/binary-unit:8, C:8, _/binary>>, <<_:Off/binary-unit:8, C:8, _/binary>>} -> lcs( A, B, Off+1 );</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class=""> {<<Common:Off/binary-unit:8, _/binary>>, _}<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> -> Common</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class=""> end</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="Courier New" class="">.</font></div><div class=""><br class=""></div><div class="">Fro example, a call to <font face="Courier New" class="">lcs( <<“Hello World”>>, <<"Hellao World”>>, 0 )</font>will return <font face="Courier New" class=""><<“Hell”>></font>.</div><div class=""><br class=""></div><div class="">NOTE (and just in case): you’d need to put this function in your own module.</div><div class=""><br class=""></div><div class="">V/</div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></body></html>