Quanti indirizzi IP ci sono in un determinato intervallo?


31

Ispirato da...

Networking - Come posso capire quanti indirizzi IP ci sono in un determinato intervallo?

Scrivi un programma o una funzione che accetta due stringhe come input, ciascuna delle quali è un indirizzo IPv4 espresso in notazione punteggiata standard e genera o restituisce il numero di indirizzi IP coperti da questo intervallo, inclusi i due indirizzi IP immessi.

  • Non è necessario utilizzare alcun codice esterno, librerie o servizi progettati per analizzare un indirizzo IP. (Sono accettabili altre funzioni di libreria standard di elaborazione stringhe.)
  • Tutti gli indirizzi IP 2 ^ 32 sono uguali. Non viene fatta alcuna distinzione per la trasmissione, la classe E, ecc.
  • Si applicano le normali regole del code-golf.

Per esempio:

"0.0.0.0","255.255.255.255" returns 4294967296.
"255.255.255.255","0.0.0.0" also returns 4294967296.
"1.2.3.4","1.2.3.4" returns 1.
"56.57.58.59","60.61.62.63" returns 67372037.
"1","2" is invalid input. Your code may do anything you like.

Ho visto questa domanda sui programmatori e stavo pensando di porla su code golf lol.
Cruncher,

3
Ho pensato che questa fosse una domanda StackOverflow su quali indirizzi IP sono impossibili secondo gli standard.
Ming-Tang,

8
IPv4 non è un po 'passe?
ugoren,

Risposte:


20

GolfScript, 20 byte

~]7/${2%256base}/)\-

Provalo online.

Casi test

$ echo 0.0.0.0 255.255.255.255 | golfscript range.gs
4294967296
$ echo 255.255.255.255 0.0.0.0 | golfscript test.gs
4294967296
$ echo 1.2.3.4 1.2.3.4 | golfscript test.gs
1
$ echo 56.57.58.59 60.61.62.63 | golfscript test.gs
67372037

Come funziona

~]        # Evaluate and collect into an array.
          #
          # “.” duplicates, so for "5.6.7.8 1.2.3.4", this leaves
          # [ 5 5 6 6 7 7 8 1 1 2 2 3 3 4 ] on the stack.
          #
7/        # Split into chunks of length 7: [ [ 5 5 6 6 7 7 8 ] [ 1 1 2 2 3 3 4 ] ]
$         # Sort the array of arrays: [ [ 1 1 2 2 3 3 4 ] [ 5 5 6 6 7 7 8 ] ]
{         # For each array:
  2%      # Extract every second element. Example: [ 1 2 3 4 ]
  256base # Convert the IP into an integer by considering it a base 256 number.
}/        #
)         # Add 1 to the second integer.
\-        # Swap and subtract. Since the integers were sorted, the result is positive.

Molto bello e piacevole $da evitare abs.
Chris Jester-Young,

4
~]è anche molto intelligente.
primo

10

Python 2 - 106

Vedi qui .

def a():x=map(int,raw_input().split("."));return x[0]*2**24+x[1]*2**16+x[2]*2**8+x[3]
print abs(a()-a())+1

Esempio di input

0.0.0.0
0.0.0.255

Esempio di output

256


1
def a():return reduce(lambda c,d:c*256+d,map(int,raw_input().split(".")))è molto più breve
Michael M.

5
@Michael Grazie per il suggerimento. L'ho usato per alcuni minuti, poi l'ho guardato e ho pensato: "Non ho scritto il 90% di quello". così l'ho riavviato.
Rainbolt

@Michael a=lambda:invece di def a():return salvare 6 personaggi
media

@Rusher Sono 107 caratteri, non 106
media

1
@avall: suppongo che stai contando la LF finale.
Dennis,

8

CJam - 15

{r'./256b}2*-z)

Provalo su http://cjam.aditsu.net/

Grazie Dennis, wow, non so come ottenere il meglio dalla mia lingua: p


È possibile salvare due byte eliminando :i( bsembra eseguire il cast di numeri interi) e uno utilizzando {r...}2*invece diqS/{...}/
Dennis

6

Bash puro, 66 byte

p()(printf %02x ${1//./ })
r=$[0x`p $1`-0x`p $2`]
echo $[1+${r/-}]

Gli appunti:

  • Definisce una funzione a pcui viene passato un indirizzo IP decimale puntato e genera la rappresentazione esadecimale di quell'indirizzo:
    • ${1//./ }è un'espansione dei parametri che sostituisce .con l'indirizzo IP passato ap()
    • Il printfè in gran parte auto esplicativo. Poiché esiste solo un identificatore di formato %02xe quattro argomenti rimanenti, l'identificatore di formato viene riutilizzato per ogni argomento rimanente, concatenando efficacemente le 2 cifre esadecimali di ciascuno dei 4 ottetti insieme
  • $[]provoca espansione aritmetica. Facciamo una sottrazione di base e assegniamo alla variabiler
  • ${r/-}è un'espansione dei parametri per rimuovere un possibile -carattere - efficacemente abs ()
  • Visualizza 1 + la differenza assoluta per indicare l'intervallo.

Produzione:

$ ./iprangesize.sh 0.0.0.0 255.255.255.255
4294967296
$ ./iprangesize.sh 255.255.255.255 0.0.0.0
4294967296
$ ./iprangesize.sh 1.2.3.4 1.2.3.4
1
$ ./iprangesize.sh 56.57.58.59 60.61.62.63
67372037
$ ./iprangesize.sh 1 2
2
$ 

Rilevo printfe echo. Ne fanno parte bash?
Calcolatrice

1
@CatsAreFluffy Sono builtins.
fase

6

Python 2.7 - 96 91 90 87

Fatto una funzione.

f=lambda a:reduce(lambda x,y:x*256+int(y),a.split("."),0)
p=lambda a,b:abs(f(a)-f(b))+1

Uso:

>>> p("1.2.3.4","1.2.3.5")
2

Modifica: rimosso non necessario int()dalla ffunzione. Grazie a isaacg

Edit2: rimosso LFalla fine del file (grazie a @Rusher) e rimosso map()al costo reduce()dell'inizializzatore (grazie a @ njzk2)


1
perché la funzione f ha bisogno di int () all'esterno?
isaacg,

1
Bene. Non ne avevo idea: D
avall

può ottenere 2 caratteri inserendo int nella riduzione invece di utilizzare la mappa (solo 2 in quanto è necessario aggiungere un ,0parametro alla funzione di riduzione)
njzk2

Ho appena scritto qualcosa che è quasi esattamente il tuo codice, quindi non mi preoccuperò di inviare ora. In realtà, il mio è più lungo di tre caratteri!
danmcardle,

5

GolfScript, 27 byte

' '/{'.'/{~}%256base}/-abs)

Esempi:

$ echo 0.0.0.0 255.255.255.255 | ruby golfscript.rb iprange.gs
4294967296
$ echo 255.255.255.255 0.0.0.0 | ruby golfscript.rb iprange.gs
4294967296
$ echo 1.2.3.4 1.2.3.4 | ruby golfscript.rb iprange.gs
1
$ echo 56.57.58.59 60.61.62.63 | ruby golfscript.rb iprange.gs
67372037

2
Puoi salvare un carattere usando /invece di %~.
Dennis,

4

CoffeeScript - 94, 92, 79, 72

I=(a)->a.split(".").reduce((x,y)->+y+x*256)
R=(a,b)->1+Math.abs I(b)-I a

Non golfato :

I = ( a ) ->
    return a.split( "." ).reduce( ( x, y ) -> +y + x * 256 )

R = ( a, b ) ->
    return 1 + Math.abs I( b ) - I( a )

JavaScript equivalente :

function ip2long( ip_str )
{
    var parts = ip_str.split( "." );    
    return parts.reduce( function( x, y ) {
        return ( +y ) + x * 256; //Note: the unary '+' prefix operator casts the variable to an int without the need for parseInt()
    } );
}

function ip_range( ip1, ip2 )
{
    var ip1 = ip2long( ip1 );
    var ip2 = ip2long( ip2 );

    return 1 + Math.abs( ip2 - ip1 );
}

Provalo online .


1
Puoi salvare alcuni personaggi sostituendo alcune parentesi con spazi:I=(a)->n=0;a.split(".").forEach((x)->n<<=8;n+=parseInt x);n>>>0 R=(a,b)->1+Math.abs I(b)-I a
Rob W

Sembra che stai perdendo molto spazio Math.abs, ma non riesco a trovare niente di più corto. (z>0)*z||-zè il migliore che ho (stessa lunghezza e ha bisogno di un input a carattere singolo). Hai qualcosa di più intelligente di quello?
Aaron Dufour,

questa versione javascript mi ​​aiuta davvero, lo sto cercando da un'ora. Grazie!
nodeffect

4

dc, 61 caratteri

?[dXIr^*rdXIr^*256*+r1~dXIr^*r256*+65536*+]dspxsalpxla-d*v1+p

Penso che sia abbastanza sorprendente che questo possa essere risolto con DC in quanto non ha la capacità di analizzare le stringhe. Il trucco è che 192.168.123.185 vanno in pila come

.185
.123
192.168

e dXIr^*sposta il punto decimale a destra di quante cifre della frazione ci sono e funziona anche per .100.

$ echo 56.57.58.59 60.61.62.63 | dc -e '?[dXIr^*rdXIr^*256*+r1~dXIr^*r256*+65536*+]dspxsalpxla-d*v1+p'
67372037.00

Sottrai un personaggio se lasci che l'input sia già in pila.


4

Powershell - 112 108 92 78 byte

Questa è la mia prima volta a giocare a golf. Qui non va niente:

Golfed (vecchio):

$a,$b=$args|%{$t='0x';$_-split'\.'|%{$t+="{0:X2}"-f[int]$_};[uint32]$t};1+[math]::abs($a-$b)

Golfed (nuovo)

$a,$b=$args|%{$t='0x';$_-split'\.'|%{$t+="{0:X2}"-f+$_};[long]$t}|sort;1+$b-$a

Ungolfed:

$a, $b = $args | % {           #powershell's way of popping an array. In a larger array
                               #$a would equal the first member and $b would be the rest.
    $t = '0x';                 #string prefix of 0x for hex notation
    $_ -split '\.' | % {       #split by escaped period (unary split uses regex)
        $t += "{0:X2}" -f +$_  #convert a dirty casted int into a hex value (1 octet)
    };
    [long]$t                   #and then cast to long
} | sort;                      #sort to avoid needing absolute value
1 + $b - $a                    #perform the calculation

uso

Salvare come file (in questo caso getipamount.ps1) e quindi chiamare dalla console

getipamount.ps1 255.255.255.255 0.0.0.0

4

C # con LINQ - 139 byte

(Da 140 dopo aver applicato il suggerimento di Bob.)

long f(params string[] a){return Math.Abs(a.Select(b=>b.Split('.').Select(long.Parse).Aggregate((c,d)=>c*256+d)).Aggregate((e,f)=>e-f))+1;}

Ungolfed ....

    long f(params string[] a)                           // params is shorter than two parameters.
    {
        return Math.Abs(                                // At the end, make all values +ve.
             a.Select(                                  // Go through both items in the array...
                b =>                                    // Calling each one 'b'. 
                    b.Split('.')                        // Separating out each "." separated byte...
                    .Select(long.Parse)                 // Converting them to a long.
                    .Aggregate((c, d) => c*256 + d)     // Shift each byte along and add the next one.
             )
             .Aggregate((e,f) => e-f)                   // Find the difference between the two remaining values.
         )+1;                                           // Add one to the result of Math.Abs.
    }

https://dotnetfiddle.net/XPTDlt


Qualcuno potrebbe spiegarmi come funziona tutto questo spostamento di byte lungo la cosa?
Obversity,

@Obversity a.b.c.dè equivalente a (a << 24) | (b << 16) | (c << 8) | (d << 0)è equivalente a (((a << 8) << 8) << 8) + ((b << 8) << 8) + (c << 8) + d). Fondamentalmente, ogni iterazione dell'aggregazione prende la somma esistente e la sposta a sinistra di un ottetto, quindi aggiunge l'ottetto successivo.
Bob,

Puoi salvare un personaggio usando c*256invece di (c<<8).
Bob,

@Bob Ben notato.
billpg,

È possibile salvare più di due caratteri, sostituendo e-fcon e<f?f-e:e-fe far cadere ilMath.Abs()
Patrick Huizinga

4

Perl, 43 byte

#!perl -pa
$_=1+abs${\map{$_=vec eval,0,32}@F}-$F[0]

Contando lo shebang come due byte.

Esempio di utilizzo:

$ echo 0.0.0.0 255.255.255.255 | perl count-ips.pl
4294967296

$ echo 255.255.255.255 0.0.0.0 | perl count-ips.pl
4294967296

$ echo 56.57.58.59 60.61.62.63 | perl count-ips.pl
67372037

Gli appunti

  • vec eval,0,32è un drop-in per ip2long. Perl consente ai letterali dei caratteri di essere espressi come prefisso ordinale con a v, ad esempio v0può essere utilizzato per il carattere nullo. Questi possono anche essere concatenati insieme, ad esempio v65.66.67.68ABCD. Quando sono presenti tre o più valori, l'iniziale vnon è necessaria. La vecfunzione interpreta una stringa come un array intero, ogni cella ha il numero specificato di bit (qui, 32). unpack N,evalavrebbe funzionato allo stesso modo.

3

JavaScript ES6 - 68 byte

f=x=>prompt().split('.').reduce((a,b)=>+b+a*256);1+Math.abs(f()-f())

Provalo con la console (premi F12) di Firefox.


Dovresti usare alerto console.log. L'output della console è economico.
nderscore,

4
@nderscore, assolutamente nessuna differenza tra console.loge uscita diretta. Questo è code-golf, non si tratta di fare codice pulito.
Michael M.,

La risposta più votata a questo meta post non è d'accordo: standard JavaScript per IO . Non è una questione di codice pulito. Si tratta in realtà di non produrre nulla.
nderscore,

@DigitalTrauma, non funzionerà a causa della precedenza dell'operatore . (aggiunta vs spostamento bit a bit)
Michael M.

2

Python 2.7, 104 byte

y=lambda:map(int,input().split("."));a,b=y(),y();print sum(256**(3-i)*abs(a[i]-b[i])for i in range(4))+1

1
Grazie per la soluzione Pensi di poter: 1. Passare dai punti e virgola alle nuove righe, per leggibilità senza sacrificare la lunghezza. 2. Spiegare come funziona il codice?
Isaacg,

2

Perl, 72 byte

#!perl -ap
@a=map{unpack N,pack C4,split/\./,$_}@F;$_=abs($a[1]-$a[0])+1

Uso:

$ echo 10.0.2.0 10.0.3.255 | perl ip-range.pl
512$ 

Questo è già più lungo del programma Perl di Primo , quindi non troppo interessante.

Perl, 119 byte, per formato di indirizzo IP obsoleto

#!perl -ap
sub v(){/^0/?oct:$_}@a=map{$m=3;@p=split/\./,$_;$_=pop@p;$s=v;$s+=v<<8*$m--for@p;$s}@F;$_=abs($a[1]-$a[0])+1

Uso:

$ echo 10.0.2.0 10.0.3.255 | perl ip-obsolete.pl
512$ 
$ echo 10.512 10.1023 | perl ip-obsolete.pl
512$ 
$ echo 0xa.0x200 012.01777 | perl ip-obsolete.pl 
512$ 

Questo programma accetta il formato obsoleto per gli indirizzi IP! Questo include indirizzi con 1, 2 o 3 parti o con parti esadecimali o ottali. Citando la pagina di manuale inet_addr (3) ,

I valori specificati usando la notazione punto assumono una delle seguenti forme:

a.b.c.d
a.b.c
a.b
a

... Quando viene specificato un indirizzo in tre parti, l'ultima parte viene interpretata come una quantità a 16 bit e posizionata nei due byte più a destra dell'indirizzo di rete. ... Quando viene fornito un indirizzo in due parti, l'ultima parte viene interpretata come una quantità di 24 bit e posizionata nei tre byte più a destra dell'indirizzo di rete. ... Quando viene fornita solo una parte, il valore viene memorizzato direttamente nell'indirizzo di rete senza riorganizzazione di byte.

Tutti i numeri forniti come `` parti '' in una notazione punto possono essere decimali, ottali o esadecimali, come specificato nel linguaggio C (ovvero, uno 0x o 0X iniziale implica esadecimale; uno 0 iniziale implica ottale; altrimenti, il numero è interpretato come decimale).

La maggior parte dei programmi non accetta più questo formato obsoleto, ma ping 0177.1funziona ancora in OpenBSD 5.5.


Il fatto che stai usando BSD è più sorprendente della cosa IP.
fase

2

PHP, 138 110 byte

<?php

function d($a,$b){foreach(explode('.',"$a.$b")as$i=>$v){$r+=$v*(1<<24-$i%4*8)*($i<4?1:-1);}return 1+abs($r);}

// use it as
d('0.0.0.0','255.255.255.255');

Poiché non vi è alcuna menzione di "nessun avviso di deprecazione", è possibile salvare un carattere sostituendolo explode('.',"$a.$b")con split('\.',"$a.$b").
MrLore,

Conto 109, non 110. Risparmia 9 byte con un programma anziché una funzione e altri 8 con questi passaggi golf: sandbox.onlinephpfunctions.com/code/…
Titus

1

Mathematica 9, 108 byte

c[f_,s_]:=1+First@Total@MapIndexed[#1*256^(4-#2)&,First@Abs@Differences@ToExpression@StringSplit[{f,s},"."]]

Ungolfed:

countIpAddresses[first_, second_] := Module[{digitArrays, differences},

  (* Split the strings and parse them into numbers. 
  Mathematica automatically maps many/most of its functions across/
  through lists *)

  digitArrays = ToExpression[StringSplit[{first, second}, "."]];

  (* Find the absolute value of the differences of the two lists, 
  element-wise *)
  differences = Abs[Differences[digitArrays]];

  (* differences looks like {{4, 4, 4, 4}} right now, 
  so take the first element *)
  differences = First[differences];

  (* now map a function across the differences, 
  taking the nth element (in code, '#2') which we will call x (in 
  code, '#1') and setting it to be equal to (x * 256^(4-n)). 
  To do this we need to track the index, so we use MapIndexed. 
  Which is a shame, 
  because Map can be written '/@' and is generally a huge character-
  saver. *)
  powersOf256 = MapIndexed[#1*256^(4 - #2) &, differences];

  (* now we essentially have a list (of singleton lists, 
  due to MapIndexed quirk) which represents the digits of a base-256, 
  converted to decimal form. 
  Example: {{67108864},{262144},{1024},{4}}

  We add them all up using Total, 
  which will give us a nested list as such: {67372036}

  We need to add 1 to this result no matter what. But also, 
  to be fair to the challenge, we want to return a number - 
  not a list containing one number. 
  So we take the First element of our result. If we did not do this, 
  we could chop off 6 characters from our code. *)

  1 + First[Total[powersOf256]]
]


0

C # - 135

long f(string x,string y){Func<string,long>b=s=>s.Split('.').Select((c,i)=>long.Parse(c)<<(3-i)*8).Sum();return Math.Abs(b(x)-b(y))+1;}

Formattato correttamente

long g(string x, string y) { 
    Func<string, long> b = s => s.Split('.').Select((c, i) => long.Parse(c) << (3 - i) * 8).Sum(); 
    return Math.Abs(b(x) - b(y)) + 1; 
}

https://dotnetfiddle.net/Q0jkdA


0

Rubino, 93 byte

a=->(x){s=i=0;x.split('.').map{|p|s+=256**(3-i)*p.to_i;i+=1};s}
s=->(x,y){1+(a[x]-a[y]).abs}

Produzione

irb(main):003:0> s['1.1.1.1', '1.1.1.2']
=> 2
irb(main):006:0> s['0.0.0.0', '255.255.255.255']
=> 4294967296

0

J, 25 byte

Prende le stringhe IP a punti tratteggiati come argomenti sinistro e destro.

>:@|@-&(256#.".;.2@,&'.')

Ha spiegato:

>:@|@-&(256#.".;.2@,&'.')  NB. ip range
      &(                )  NB. on both args, do:
                   ,&'.'   NB.   append a .
               ;.2@        NB.   split by last character:
             ".            NB.     convert each split to number
        256#.              NB. convert from base 256
   |@-                     NB. absolute difference
>:@                        NB. add 1 to make range inclusive

Esempi:

   '0.0.0.0' >:@|@-&(256#.".;.2@,&'.') '255.255.255.255'
4294967296
   iprange =: >:@|@-&(256#.".;.2@,&'.')
   '255.255.255.255' iprange '0.0.0.0'
4294967296
   '1.2.3.4' iprange '1.2.3.4'
1
   '56.57.58.59' iprange '60.61.62.63'
67372037

0

Fattore, 73 byte

Traduzione della risposta CoffeeScript.

[ "." split [ 10 base> ] [ [ 256 * ] dip + ] map-reduce ] bi@ - abs 1 + ]

0

Javascript ES6, 81 caratteri

(a,b)=>Math.abs(eval(`(((((${a})>>>0)-(((((${b})>>>0)`.replace(/\./g,")<<8|")))+1

Test:

f=(a,b)=>Math.abs(eval(`(((((${a})>>>0)-(((((${b})>>>0)`.replace(/\./g,")<<8|")))+1
;`0.0.0.0,255.255.255.255,4294967296
255.255.255.255,0.0.0.0,4294967296
1.2.3.4,1.2.3.4,1
56.57.58.59,60.61.62.63,67372037`.split`
`.map(x=>x.split`,`).every(x=>f(x[0],x[1])==x[2])

PS: proverò a ottimizzarlo un po 'più tardi.


0

Lua, 153 byte

È un peccato che lua non abbia una funzione split, ho dovuto definire la mia!

a,b=...r=0y=8^8x={}t={}function f(t,s)s:gsub("%d+",function(d)t[#t+1]=d end)end
f(x,a)f(t,b)for i=1,4 do r=r+y*math.abs(t[i]-x[i])y=y/256 end print(r+1)

Ungolfed

a,b=...                    -- unpack the arguments into two variables
r=0                        -- initialise the sume of ip adress
y=8^8                      -- weight for the rightmost value
x={}t={}                   -- two empty arrays -> will contains the splittedip adresses
function f(t,s)            -- define a split function that takes:
                           --   a pointer to an array
                           --   a string
  s:gsub("%d+",function(d) -- iterate over the group of digits in the string
    t[#t+1]=d              -- and insert them into the array
  end)
end
f(x,a)                     -- fill the array x with the first address
f(t,b)                     -- fill the array t with the second address
for i=1,4                  -- iterate over t and x
do
  r=r+y*math.abs(t[i]-x[i])-- incr r by weight*abs(range a- range b)
  y=y/256                  -- reduce the weight
end
print(r+1)                 -- output the result

0

Gelatina , 12 byte, sfida postdatati in lingua

ṣ”.V€ḅ⁹µ€ạ/‘

Provalo online!

Spiegazione

ṣ”.V€ḅ⁹µ€ạ/‘
       µ€     On each element of input:
ṣ”.             Split on periods
   V€           Convert string to number in each section
     ḅ⁹         Convert base 256 to integer
         ạ/   Take absolute difference of the resulting integers
           ‘  Increment

Il numero di elementi in un intervallo inclusivo è la differenza assoluta dei loro endpoint, più 1.


0

Assioma, 385 byte

c(a:String):INT==(d:=digit();s:NNI:=#a;t:INT:=0;for i in 1..s repeat(~member?(a.i,d)=>return-1;t:=t+(ord(a.i)-48)*10^(s-i)::NNI);t)
g(x:String):List NNI==(a:=split(x,char".");s:NNI:=#a;r:=[];for i in s..1 by -1 repeat(y:=c(a.i);y=-1=>return [];r:=concat(y,r));r)
m(x:NNI,y:NNI):NNI==x*256+y
f(a:String,b:String):INT==(x:=g(a);y:=g(b);#x~=4 or #y~=4=>-1;1+abs(reduce(m,x)-reduce(m,y)))

scappare e testare

-- convert the string only digit a in one not negative number
-- return -1 in case of error
cc(a:String):INT==
     d:=digit();s:NNI:=#a;t:INT:=0
     for i in 1..s repeat
               ~member?(a.i,d)=>return -1
               t:=t+(ord(a.i)-48)*10^(s-i)::NNI
     t

-- Split the string x using '.' as divisor in a list of NNI
-- if error return []
gg(x:String):List NNI==
    a:=split(x,char".");s:NNI:=#a;r:=[]
    for i in s..1 by -1 repeat
          y:=cc(a.i)
          y=-1=>return []
          r:=concat(y,r)
    r


mm(x:NNI,y:NNI):NNI==x*256+y

-- Return absolute value of difference of address for IP strings in a and in b 
-- Retrun -1 for error
-- [Convert the IP strings in a and in b in numbers ad subtract and return the difference]
ff(a:String,b:String):INT==(x:=gg(a);y:=gg(b);#x~=4 or #y~=4=>-1;1+abs(reduce(mm,x)-reduce(mm,y)))


(14) -> f("0.0.0.0", "255.255.255.255")
   (14)  4294967296
                                                    Type: PositiveInteger
(15) -> f("255.255.255.255", "0.0.0.0")
   (15)  4294967296
                                                    Type: PositiveInteger
(16) -> f("1.2.3.4", "1.2.3.4")
   (16)  1
                                                    Type: PositiveInteger
(17) -> f("56.57.58.59", "60.61.62.63")
   (17)  67372037
                                                    Type: PositiveInteger
(18) -> f("1", "2")
   (18)  - 1
                                                            Type: Integer
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.