This file contains hidden or 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
// how I'd "fix" https://akrzemi1.wordpress.com/2017/01/02/not-detecting-bugs/ | |
// | |
// * Explicitly state "code assumes input vectors are same length" | |
// * Explicitly request inlining of loop's inner funcion | |
// * real world code will probably not use "v1, v2" naming | |
// * instead of relying "compiler will optimize away helper constructs", | |
// just don't use any. | |
// | |
// in general, it's a similar case, when instead of ... | |
// struct x = {a[++i], b[i]} |
This file contains hidden or 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
def hamming(s1,s2): | |
""" returns the hamming number (char differences) between two strings """ | |
hamming_number = 0 | |
for char1,char2 in itertools.izip_longest(s1,s2): | |
if char1!=char2: | |
hamming_number += 1 | |
return hamming_number |
NewerOlder