Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create HammingDistance.py * Update README.md * Create HammingDistance.c * Update README.md * Update HammingDistance.c * Update HammingDistance.py
- Loading branch information
1 parent
4181774
commit b113795
Showing
3 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @author : ashwek | ||
* @date : 24/12/2018 | ||
*/ | ||
|
||
#include<stdio.h> | ||
#include<string.h> | ||
|
||
int HammingDistance(char Str1[], char Str2[]){ | ||
|
||
int i, count = 0; | ||
|
||
if( strlen(Str1) != strlen(Str2) ) | ||
return -1; | ||
|
||
for(i=0; i<strlen(Str1); i++){ | ||
if( Str1[i] != Str2[i]) | ||
count++; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
void main(){ | ||
|
||
char Str1[50], Str2[50]; | ||
int HD; | ||
|
||
printf("Enter string 1 = "); | ||
scanf("%s", Str1); | ||
printf("Enter string 2 = "); | ||
scanf("%s", Str2); | ||
|
||
HD = HammingDistance(Str1, Str2); | ||
|
||
if( HD == -1 ) | ||
printf("Strings are of different length"); | ||
else | ||
printf("Hamming Distance = %d", HD); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
@author : ashwek | ||
@date : 24/12/2018 | ||
""" | ||
def HammingDistance(Str1, Str2): | ||
|
||
count = 0 | ||
|
||
if( len(Str1) != len(Str2) ): | ||
return None | ||
|
||
for i in range(len(Str1)): | ||
if( Str1[i] != Str2[i]): | ||
count += 1 | ||
|
||
return count | ||
|
||
Str1 = input("Enter string 1 = ") | ||
Str2 = input("Enter string 2 = ") | ||
|
||
HD = HammingDistance(Str1, Str2) | ||
|
||
if( HD is None ): | ||
print("Strings are of different length") | ||
else: | ||
print("Hamming Distance = ", HD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters