[Programming] C1: dot-n-dash xp0int Posted on Nov 23 2018 题目把输入的每一个字符转为ascii码,然后把ascii码的二进制中1的数目转化一下作为杠的数目再加个点,比如`[2,3,4]`变成`--.---.----.` ```javascript var t = a.pop(); r = r + "-".repeat(t) + "."; ``` 观察发现转化`x = 1 + j + (input_len - 1 - i) * 8`有类似进位的性质,而且x达到最大值时i为0。 ![title](https://leanote.com/api/file/getImage?fileId=5bed7ef1ab64412530007bdc) 首先把点和杠换成数组: ```python with open('instructions.txt') as f: data = [len(x) for x in f.read().strip()[:-1].split('.')] ``` 找到最大值x 可以计算`j = (x - 1) % 8`, `i = 0` `input_len = (x - j - 1) // 8 + i + 1` 然后就可以计算所有数字对应的j和i了 脚本: ```python with open('instructions.txt') as f: data = [len(x) for x in f.read().strip()[:-1].split('.')] # x = 1 + j + (input_len - 1 - i) * 8 x = max(data) j = (x - 1) % 8 i = 0 input_len = (x - j - 1) // 8 + i + 1 output = [0] * input_len for x in data: j = (x - 1) % 8 i = -((x - j - 1) // 8 - input_len + 1) output[i] |= 1 << j print(bytes(output).decode()) ``` ![title](https://leanote.com/api/file/getImage?fileId=5bed8305ab64412530007ce1) 打赏还是打残,这是个问题 赏 Wechat Pay Alipay [Math] C8: captcha [Math] C3: shredded
没有帐号? 立即注册