Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Year
  def self.leap?(year)
    year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)
  end
end

module Hamming
  def self.distance(a,b)
    a.chars.zip(b.chars).count{|first, second| first != second }
  end
end

puts "Year.leap?"
puts "==============="
puts Year.leap?(1900)
puts Year.leap?(2000)
puts Year.leap?(2016)

puts "Hamming.distance"
puts "==============="
puts Hamming.distance("ACCAGGG", "ACTATGG")
puts Hamming.distance("A", "A")
puts Hamming.distance("GGACTGA", "GGACTGA")
puts Hamming.distance("A", "G")
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]