DEV Community

Discussion on: Daily Challenge #31 - Count IPv4 Addresses

Collapse
 
phallstrom profile image
Philip Hallstrom

Ruby, and totally cheating by using it's IPAddr class :)

def ips_between(from, to)
  IPAddr.new(to).to_i - IPAddr.new(from).to_i
end
Collapse
 
maxart2501 profile image
Massimo Artizzu

This actually made me chuckle... lol cheating indeed 😁

Collapse
 
andreasjakof profile image
Andreas Jakof

And it was my first idea as well... IPv4 Addresses are 4byte integers... so the easiest way is to subtract them. 😎