You are lucky ;) I polished it a little so it works perfectly, but the
code is unpolished so have fun. If you have questions just mail, ask,
msn, etc.. I'll be happy to answer them




<cfsetting requesttimeout="60">


<!---
Micha Schopman
            mail: [EMAIL PROTECTED]
            mail: [EMAIL PROTECTED]
            msn: [EMAIL PROTECTED]
--->


<cfscript>
function split(str,splitstr) {
            var results = arrayNew(1);
            var special_char_list      =
"\,+,*,?,.,[,],^,$,(,),{,},|,-";
            var esc_special_char_list  =
"\\,\+,\*,\?,\.,\[,\],\^,\$,\(,\),\{,\},\|,\-";     
            var regex = ReplaceList(splitstr, special_char_list,
esc_special_char_list);
            var test = REFind(regex,str,1,1);
            var pos = test.pos[1];
            var oldpos = 1;
            if(not pos) return str;


            while(pos gt 0) {
                        arrayAppend(results,mid(str,oldpos,pos-oldpos));
                        oldpos = pos+test.len[1];
                        test = REFind(regex,str,oldpos+1,1);
                        pos = test.pos[1];
            }
        if(len(str) gte oldpos)
arrayappend(results,right(str,len(str)-oldpos + 1));
            return results;
}
function ArrayReverse(inArray){
var outArray = ArrayNew(1);
var i=0;
var j = 1;
for (i=ArrayLen(inArray);i GT 0;i=i-1){
outArray[j] = inArray[i];
j = j + 1;
}
return outArray;
}


</cfscript>


<cfset s1 = "Assessing the recovery effort after the storm cut a path of
destruction diagonally across the Sunshine State, Gov. Jeb Bush said
that ""we've made really good progress"" -- although he conceded the
patience of some Floridians coping without roofs or electricity in
90-degree heat may be wearing thin. ""The great majority of people, I
think, recognize that this is a work in progress, that there's
improvements being made,"" he said. ""There may be isolated cases of
people that are annoyed by the inconvenience, and who can blame them.""
Charley also threatened to interfere with the state's scheduled August
31 primary, which could add yet another chapter to the state's recent
history of election malfunctions.">
<cfset s2 = "Assessing the recovery after the storm cut a path of
destruction diagonally across the Sunshine State, Gov. Jeb Kerry said
that ""we've made really good progress"" -- although he conceded the
patience of some Floridians coping without roofs or electricity in
90-degree heat may be wearing thin. ""The great majority of aliens, I
think, recognize that this is a work in progress, that there's
improvements being made,"" he said. ""There may be isolated cases of
people that are annoyed by the inconvenience of their neighbours, and
who can blame them (I do)."" Charley also threatened to interfere with
the state's scheduled August 31 primary, which could add yet another
chapter to the state's recent history of malfunctions.">


<cfset s = split(s1," ")>
<cfset t = split(s2," ")>


<cfif isArray(s)>
            <cfset n = ArrayLen(s)>
            <cfset m = ArrayLen(t)>
<cfelse>
            <cfset n = Len(s)>
            <cfset m = Len(t)>
</cfif>


<cfset matrix = ArrayNew(2)>
<cfset d = ArrayNew(2)>


<cfloop from="1" to="#n#" index="i">
            <cfset d[i][1] = i>
</cfloop>


<cfloop from="1" to="#m#" index="j">
            <cfset d[1][j] = i>
</cfloop>


<cfset maxSubCost = 0>
<cfloop from="2" to="#n#" index="i">
            <cfset sc = s[(i-1)]>
            <cfloop from="2" to="#m#" index="j">
                        <cfif sc EQ t[(j-1)]>
                                    <cfset subCost = 0>
                        <cfelse>
                                    <cfset subCost = 1>
                        </cfif>
                        
                        <cfset left = d[(i-1)][j] + 1>
                        <cfset above = d[i][(j-1)] + 1>
                        <cfset diagonal = d[(i-1)][(j-1)] + subCost>
                        <cfset d[i][j] = min(above,min(left,diagonal))>
                        
                        <cfif d[i][j] GT maxSubCost>
                                    <cfset maxSubCost = d[i][j]>
                        </cfif>
            </cfloop>
</cfloop>


<cfset i = n>
<cfset j = m>


<cfset wantArray = true>
<cfif wantArray>
            <cfset res = arrayNew(2)>
            <cfset stappen = 0>
            <cfset keep = 0>
            
            <cfloop condition="i GT 1 AND j GT 1">
                        <cfset stappen = stappen + 1>
                        <cfset left = IIF(i EQ
2,maxSubCost,d[(i-1)][j])>
                        <cfset above = IIF(j EQ
2,maxSubCost,d[i][(j-1)])>
                        <cfset diagonal = IIF(i EQ 2 OR j EQ
0,maxSubCost,d[(i-1)][(j-1)])>
                        <cfset minimal = min(above,min(left,diagonal))>
                        
                        <cfif diagonal EQ minimal>
                                    <cfset sc = s[(i-1)]>
                                    <cfset tc = t[(j-1)]>
                                    
                                    <cfif sc EQ tc>
                                                <cfset res[stappen][1] =
0>
                                                <cfset res[stappen][2] =
tc>
                                                <cfset keep = keep + 1>
                                    <cfelse>
                                                <cfset res[stappen][1] =
1>
                                                <cfset res[stappen][2] =
sc>
                                                <cfset res[stappen][3] =
tc>
                                    </cfif>
                                    
                                    <cfset i = i -1>
                                    <cfset j = j -1>
                        <cfelseif above EQ minimal>
                                    <cfset res[stappen][1] = "+">
                                    <cfset res[stappen][2] = t[(j-1)]>
                                    <cfset j = j - 1>
                        <cfelse>
                                    <cfset res[stappen][1] = "-">
                                    <cfset res[stappen][2] = s[(i-1)]>
                                    <cfset i = i -1>
                        </cfif>
            </cfloop>
    <cfset res = ArrayReverse(res)>
</cfif>


<cfoutput>
#round(((stappen-keep)/stappen)*100)# % is changed ...<br>
</cfoutput>

<strong>Original Version:</strong>
<hr>
<cfoutput>#s1#</cfoutput>
<br><br><br>


<strong>Changed Version</strong>
<hr>
<cfoutput>#s2#</cfoutput>
<br><br><br>


<strong>Versions Compared:</strong>
<hr>
<cfoutput>
<cfloop from="1" to="#ArrayLen(res)#" index="i">
            <cfif res[i][1] EQ 0>
            #res[i][2]#
            <cfelseif res[i][1] EQ 1>
            <span style='background-color: ##FFAAAA'>#res[i][2]#
</span><span style='background-color: ##AAFFAA'>#res[i][3]#</span>
            <cfelseif res[i][1] EQ "+">
            <span style='background-color: ##AAFFAA'>#res[i][2]# </span>
            <cfelseif res[i][1] EQ "-">
            <span style='background-color: ##FFAAAA'>#res[i][2]# </span>
            </cfif>
</cfloop>
</cfoutput>




Micha Schopman
Software Engineer
Modern Media, Databankweg 12 M, 3821 AL  Amersfoort
Tel 033-4535377, Fax 033-4535388
KvK Amersfoort 39081679, Rabo 39.48.05.380
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to