Amazon now owns 3.0.0.0/8
Apparently bought in two chunks: 3.0.0.0/9 and 3.128.0.0/9.
How do I write program in Ruby to add 3.0.0.0/9 and 3.128.0.0/9 and get result - 3.0.0.0/8?
I can convert mask to cidr this way:
"255.255.255.0" \
.split(".") \
.map { |e| e.to_i.to_s(2).rjust(8, "0") } \
.join \
.count("1") # => 24
But how can I add one mask to another?
This is what I have now:
[1] pry(main)> "3.128.0.0".split('.').map { |e| e.to_i.to_s(2).rjust(8, "0") }
=> ["00000011", "10000000", "00000000", "00000000"]
[2] pry(main)> "3.0.0.0".split('.').map { |e| e.to_i.to_s(2).rjust(8, "0") }
=> ["00000011", "00000000", "00000000", "00000000"]
How do I apply /9 to both of addresses above?