Canonicalize CIDR: Difference between revisions

add PicoLisp
m (Add the missing argument to a function in the CL solution)
(add PicoLisp)
Line 1,129:
161.214.74.21/24 -> 161.214.74.0/24
184.232.176.184/18 -> 184.232.128.0/18
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(de cidr (S)
(let
(L (rot (mapcar format (split (chop S) "." "/")))
N (++ L)
M
(&
(sum >> (-24 -16 -8 0) L)
(rev 32 (dec (** 2 N))) ) )
(pack
(>> 24 M)
"."
(& 255 (>> 16 M))
"."
(& 255 (>> 8 M))
"."
(& 255 (& 255 M))
"/"
N ) ) )
(let Fmt (18 3 17)
(for A
(quote
"87.70.141.1/22"
"36.18.154.103/12"
"62.62.197.11/29"
"67.137.119.181/4"
"161.214.74.21/24"
"184.232.176.184/18" )
(tab Fmt A "=>" (cidr A)) ) )</lang>
{{out}}
<pre>
87.70.141.1/22 => 87.70.140.0/22
36.18.154.103/12 => 36.16.0.0/12
62.62.197.11/29 => 62.62.197.8/29
67.137.119.181/4 => 64.0.0.0/4
161.214.74.21/24 => 161.214.74.0/24
184.232.176.184/18 => 184.232.128.0/18
</pre>
 
298

edits