Re: String compare



On Mar 12, 5:13 pm, Muhs <shumy...@xxxxxxxxx> wrote:
lol.. i know what you mean by being it a homework... actually its my
final year degree project.. on which i'll be working on till
sepetember... my project is about mutation clustering... and i have
data in the form of 1's and 0's(data= 101010000011000001, could be int
or string)... now i want to cluster the data based on some similarity
measure.... i thought i could compare the string data and find the
number of characters that are different... but somebody above sent a
link and there was this algo of hamming distance... i wrote the algo
as follows:

int distance = 0;
int val = 0;
int x= 8;
int y=15;
val = x ^ y;

while(val!=0)
{
++distance;
val = val - 1;
}
but the distance that i get is 7, same as val... i was thinking of
converting 7 to binary and count the number of 1's (111) that way i
could get distance 3..

Well yes. As currently coded, the while loop is equivalent to:
distance = val;
val = 0;
(... provided x,y are constrainted to be >= 0). Go look at the
wikipedia page again, and code the updated correctly, and it will
indeed count the bits.



On 12 Mar, 16:43, Martin Bonner <martinfro...@xxxxxxxxxxx> wrote:

On Mar 12, 4:20 pm, Muhs <shumy...@xxxxxxxxx> wrote:

Hi !!
i want to compare two strings and return the difference

For example, i have two strings,
string str1="then";
string str2="than";

it compared the two strings and returns 1, as only one character is
different (a and e).
Is there a function in c# that can do this??

I don't think so.

This is quite easy, so I suspect it is homework. You won't learn if
you get somebody else to write the code for you. If you have written
some code and are having trouble, then post it with a description of
the problem and we can probably help.

If it is not homework, then what is the application? (I can think of
a number of issues with the specification as it stands, and the
resolution will depend on the application.)

.



Relevant Pages

  • Re: String compare
    ... data in the form of 1's and 0's(data= 101010000011000001, could be int ... link and there was this algo of hamming distance... ... so I suspect it is homework. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Maximum, Average, and Likely Minimum Gap Distances
    ... of fairly specified residue positions. ... Or, more simply, your "average gap size" is just the number of ... maximum distance between those two islands. ... this clustering becomes less and less clustered at higher and higher ...
    (talk.origins)
  • Re: How PROC CLUSTER deals with Distance data sets ?
    ... This has been the situation since before there were packages and each agglomeration method had its own piece of software. ... Especially on matters related to different proximity measures, different agglomeration procedures, and their interaction, I suggest that you post your query on the discussion list for the society that specializes in such questions. ... In most packages, the abscissa would be the "distance" used to make the decision about which two clusters to combine, although sometimes only the order of clustering is visualized. ...
    (sci.stat.consult)
  • Re: How PROC CLUSTER deals with Distance data sets ?
    ... agglomeration method had its own piece of software. ... Especially on matters related to different proximity measures, ... the abscissa would be the "distance" used to ... sometimes only the order of clustering is visualized. ...
    (sci.stat.consult)
  • misc idea: Mini-LZ
    ... one can copy the files, however, for finer grained usages (and where deflate is overkill), this is not optimal. ... in truth, the encoder may not work at all, or may be slow. ... next byte is the low 8 bits of distance. ... int MiniLZ2_Decode ...
    (comp.compression)