Canonicalize CIDR: Difference between revisions

m
more test cases to fit changes in task description
m (C - simplified code)
m (more test cases to fit changes in task description)
Line 191:
dig = length(ip) > 1 ? 2^(32 - parse(UInt8, ip[2])) : 1
ip4 = IPv4(UInt64(IPv4(ip[1])) & (0xffffffff - dig + 1))
return length(ip) == 1 ? "$ip4/32" : "$ip4/$(ip[2])"
end
 
Line 197:
println(canonCIDR("100.68.0.18/18"))
println(canonCIDR("10.4.30.77/30"))
println(canonCIDR("10.207.219.251/32"))
println(canonCIDR("10.207.219.251"))
println(canonCIDR("110.200.21/4"))
println(canonCIDR("10..55/8"))
Line 205 ⟶ 207:
100.68.0.0/18
10.4.30.76/30
10.207.219.251/32
10.207.219.251/32
96.0.0.0/4
10.0.0.0/8
4,108

edits