Python checkio "IP Network: Route Summarization"解决方案
来源:互联网 发布:java wait notify实现 编辑:程序博客网 时间:2024/06/05 09:43
def checkio(data): bins = ["".join(bin(int(x))[2:].zfill(8) for x in line.split(".")) for line in data] mask = 0 binary = "" for i, v in enumerate(zip(*bins), 0): if len(set(v)) > 1: mask = i break else: binary += v[0] binary += ("0" * (32 - mask)) return ".".join(str(int(binary[i:i+8], 2)) for i in range(0, 32, 8)) + "/" + str(mask)from itertools import takewhile, chaindef checkio(adds): binint = lambda strn: '{:0=8b}'.format(int(strn)) binseqs = (''.join(map(binint, a.split('.'))) for a in adds) iscommon = lambda binset: len(binset) == 1 prefix = ''.join(chain(*takewhile(iscommon, map(set, zip(*binseqs))))) filled = '{:0<32}'.format(prefix) summary = '.'.join(str(int(filled[i: i + 8], 2)) for i in range(0, 32, 8)) return '{}/{}'.format(summary, len(prefix))
阅读全文
0 0
- Python checkio "IP Network: Route Summarization"解决方案
- Python checkio median解决方案
- Python checkio "Friends"解决方案
- route / ip route / ... network command
- Python checkio Monkey Typing解决方案
- Python checkio Pawn Brotherhood解决方案
- Python checkio Long Repeat解决方案
- Python checkio First Word解决方案
- Python checkio Secret Message解决方案
- Python checkio Index Power解决方案
- Python checkio Digits Multiplication解决方案
- Python checkio Days Between解决方案
- Python checkio Cipher map解决方案
- Python checkio Boolean Algebra解决方案
- Python checkio "Ghosts age"解决方案
- Python checkio "Striped Words"解决方案
- Python checkio "Speech Module"解决方案
- Python checkio "Making Change"解决方案
- JavaScript基础(15.Dom创建标签)
- 《你不知道的JavaScript(上)》——1.1编译原理
- java守护进程启动和关闭脚本
- 当程序员没了互联网,该如何继续学习写代码?
- IDEA Push Failed with error: fatal: Could not read from remote repository
- Python checkio "IP Network: Route Summarization"解决方案
- 数据结构课程总结
- 上传配置
- MAVEN的依赖
- 国学名句
- wzq.HorizontalScrollView——横向滑动菜单
- 导航条的精华写法
- PHP 类型是什么
- 我学到了什么?