We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d1c8e41 commit b3d2addCopy full SHA for b3d2add
5 kyu/Count IP Addresses/s.r
@@ -0,0 +1,23 @@
1
+ips_between <- function(start, end) {
2
+ sum(Reduce(function(a, b) as.integer(a) - as.integer(b),
3
+ strsplit(c(end, start), "\\.")) * 256^(3:0))
4
+}
5
+____________
6
7
+ s <- as.integer(unlist(strsplit(start, ".", fixed = TRUE)))
8
+ e <- as.integer(unlist(strsplit(end, ".", fixed = TRUE)))
9
+ difference <- rev(e-s)
10
+ sum(sapply(seq_along(difference), function(i){
11
+ difference[i]*256^(i-1)
12
+ }))
13
+
14
15
+__________________
16
17
+ toBase256 <- function(ip) {
18
+ ip <- as.numeric(strsplit(ip,"\\.")[[1]])
19
+ sum(mapply(`*`, ip, 256^(3:0)))
20
+ }
21
22
+ toBase256(end) - toBase256(start)
23
0 commit comments