Here's how you can change the code to a one-liner in Ruby:
main.rb170 chars5 linesExplanation:
zip method to combine each character of dn1 with the corresponding character of dn2. This creates an array of pairs.count method with a block that checks if the characters in each pair are not equal. The count method counts the number of elements that satisfy the block condition.dn1 and dn2.Note: I have also added a raise ArgumentError to handle the case where the lengths of dn1 and dn2 do not match.
gistlibby LogSnag