Open kytrinyx opened 9 years ago
Here's another example of inconsistent indentation that I would expect to trigger the rule:
class Hamming
def self.compute(a,b)
biggerList = []
smallerList = []
#detect which string is longer and split into arrays.
if a.length > b.length
bigger_list = a.chars
smaller_list = b.chars
else
bigger_list = b.chars
smaller_list = a.chars
end
#iterate over smaller array and check against larger array
smaller_list.zip(bigger_list).count {|y, z| y != z }
end
end
Here's one more:
class Hamming
def self.compute(strand1, strand2)
count = 0
if strand1.length == strand2.length
strand1.length.times { |x| count += 1 unless strand1[x] == strand2[x]}
end
count
end
end
And as a string to make it easier to use in a test:
"class Hamming\n def self.compute(strand1, strand2)\n count = 0\n if strand1.length == strand2.length\n strand1.length.times { |x| count += 1 unless strand1[x] == strand2[x]}\n end\n count\n end\nend"
I found another one...
class Hamming
class << self
def compute(a,b)
return -1 if a.length != b.length
d = 0
(a.length).times do |i|
d+=1 if a[i] != b[i]
end
d
end
end
end
I saw another one today:
class Hamming
def self.compute(sequence1,sequence2)
if sequence1.length != sequence2.length
puts "ValueError, cannot calculate hamming distance for sequences of different length!"
else
@distance = 0
hamming_pairs = sequence1.split('').zip(sequence2.split(''))
hamming_pairs.each do |pair|
@distance += 1 if pair[0] != pair[1]
end
@distance
end
end
end
Howdy Katrina,
I've been out of town but I'm now actively working on this. The current rule only looks for inconsistent endings of expressions with block-like syntax. It disregards the indentation of the body. I've got a few ideas on how to solve this but it's a bit tricky to generalize the rule due to nasty edge cases. I'm experimenting with a solution that should solve all of these cases. I'll post back with my findings.
Yeah, if it's nasty then let's be more conservative. I'd rather rikki- be correct than aggressive :)
I saw the following submission today, which didn't trigger the inconsistent indentation rule. Notice how the indentation is variously 1, 2, and 4 spaces.
Here's the curl call: