3 ms·
You're probably getting hung up on the "converting to base-128" part. Here's my solution. I wouldn't normally post it publicly, but I've emailed OP multiple t
by andrewbecker 6y ago
You're probably getting hung up on the "converting to base-128" part.
Here's my solution. I wouldn't normally post it publicly, but I've emailed OP multiple times over the last couple months to apply for this position and have received no response, so maybe this is actually the best way to get around the spam filter:
from z3 import *
s = Solver()
x = Int('x')
divisor1 = x / 611939
divisor2 = x / 598463
modconstraint1 = (x - (611939 * divisor1)) == 145767
modconstraint2 = (x - (598463 * divisor2)) == 109572
s.add(modconstraint1, modconstraint2, x > 0)
s.check()
email_bin = '{0:b}'.format(s.model()[x].as_long())
email_b128 = []
for i in xrange(0, len(email_bin), 7):
email_b128.append('0' + email_bin[i : i+7])
email_bytearr = map(lambda c: str(unichr(int(c, 2))), email_b128)
print(reduce(lambda x, y: x + y, email_bytearr, '') + '@inpher.io')
- saagarjha 6y agoOh, I didn't realize that x had to simultaneously satisfy both; I just though they were two parts of the email or something. Thanks for the explanation!
- Recursing 6y agoBtw, python-z3 supports the % operator from z3 import Int, solve x = Int('x') solve([x % 611939 == 145767, x % 598463 == 109572]) [x = 243085550] Also: please use python3, it's 2020 :( And a simpler conversion to base128 would be: print(''.join(chr((x // 128**i) % 128) for i in range(3, -1, -1)))
- throwaway765e6 6y agoFor anyone wishing to try this without having to install z3, or just to see a more rudimentary way of doing this, here is a self-contained (hopefully just as readable) solution in JS: const num = findNum(); const bin = num.toString(2); const byteStrings = toChunks(bin, 7).map(chunk => chunk.join('')); const bytes = byteStrings.map(str => parseInt(str, 2)); const str = bytes.map(String.fromCharCode).join(''); console.log(num, bin, byteStrings, bytes, str); function findNum(i=0, lim=1e1000000000) { while (i < lim) { if (i % 611939 === 145767 && i % 598463 === 109572) return i; i += 1; } } function toChunks(iterable, chunkSize) { const chunks = []; for (const el of iterable) { let buf = chunks[chunks.length - 1]; if (!buf || buf.length >= chunkSize) { buf = []; chunks.push(buf); } buf.push(el); } return chunks; } 243085550 1110011111010011000011101110 [ '1110011', '1110100', '1100001', '1101110' ] [ 115, 116, 97, 110 ] <xxx> Sorry about not getting a response from the poster of the job, by the way. It's a very unhealthy attitude and it's sad to see this on HN of all places.
- throwaway235092 6y agox = 145767 while x % 598463 != 109572: x += 611939 s = '' while x: s = chr(x % 128) + s x //= 128 print(s)