IPv6 Shortener
Statement
An IPv6-Address is the next-generation network address for electronic devices.
Compared to an IPv4 address, it is made up of 8 blocks that are 4 hexadecimal digits long, split by colons.
An example of an IPv6 address is [[2001:0000:3c4d:0015:0000:0000:0db8:1a2b]]
To avoid needing to write so many digits, you can short an IPv6 address very easily by removing unneeded zeros.
The goal of this puzzle is to compress the IPv6 address, that it gets shortened.
The shortened version would look like this: [[2001:0:3c4d:15::db8:1a2b]]
You can see that the leading zeros of all the blocks were removed, and a double colon replaced the longest chains of blocks that contained zeros only.
<<Notes:>> The double colon may only be used once in the whole address at the longest streak of zero blocks, and only if there are two or more zero blocks next to each other. The rest of the single blocks that contain zeros only must be represented as only one zero in the whole block, no matter if they are next to each other.
Input description
A string [[ip]] that is the uncompressed IPv6 address.
Output description
A string [[output]] that is the compressed IPv6 address.
Constraints
<<Length of IP:>> 39 symbols, 8 blocks to 4 hexadecimal symbols split by 7 colons
Game modes
Fastest, Shortest
Test cases
Simple Address Test
Input
2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b
Output
2001:db8:3c4d:15::1a2f:1a2b
Simple Address Validator
Input
2001:0000:0000:0015:27ab:1203:1a2f:1a2b
Output
2001::15:27ab:1203:1a2f:1a2b
Loopback Address Test
Input
0000:0000:0000:0000:0000:0000:0000:0001
Output
::1
Loopback Address Validator
Input
0000:0000:0000:0000:0000:0000:0000:0001
Output
::1
Multiple Zero Blocks Test
Input
2001:0000:0000:0000:0001:0000:1a2f:1a2b
Output
2001::1:0:1a2f:1a2b
Multiple Zero Blocks Validator
Input
2001:0000:0000:0000:3ac3:0000:0000:1a2b
Output
2001::3ac3:0:0:1a2b
No Zero Blocks Test
Input
2001:2021:ab23:82ae:0021:0001:1a2f:1a2b
Output
2001:2021:ab23:82ae:21:1:1a2f:1a2b
No Zero Blocks Validator
Input
2001:2071:ab23:82ae:0021:0073:1a3f:1a2b
Output
2001:2071:ab23:82ae:21:73:1a3f:1a2b
One Zero Block Test
Input
fe80:5c77:3430:7667:0000:ce27:43d0:ab34
Output
fe80:5c77:3430:7667:0:ce27:43d0:ab34
One Zero Block Validator
Input
1a4b:cafe:0029:1317:abe2:0000:2acg:90ab
Output
1a4b:cafe:29:1317:abe2:0:2acg:90ab
No Full Zero Blocks Test
Input
fe80:0023:2027:00dd:918f:0001:0023:0e68
Output
fe80:23:2027:dd:918f:1:23:e68
No Full Zero Blocks Validator
Input
fe80:0273:2027:00dd:91ef:0001:023b:0e68
Output
fe80:273:2027:dd:91ef:1:23b:e68
Solution language
Solution
Stub generator input