Skip to content

Instantly share code, notes, and snippets.

@hc0d3r
Created November 13, 2018 15:42
Show Gist options
  • Save hc0d3r/97dd1316682d2df09bc722b6fe54437c to your computer and use it in GitHub Desktop.
Save hc0d3r/97dd1316682d2df09bc722b6fe54437c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
def getinfo(buf):
i = buf.index(' ')
return int(buf[2:i]), int(buf[i+3:])
sockfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockfd.connect(('0', 9007))
print 'waiting ...'
buf = sockfd.recv(10000)
for i in range(0, 100):
buf = sockfd.recv(100)
ncoins, ntries = getinfo(buf)
arr = [str(c) for c in range(0, ncoins)]
while ntries:
lsize = len(arr)/2+len(arr)%2
print 'total = {} | ntries = {}'.format(lsize, ntries)
ntries -= 1
sockfd.send(' '.join(arr[:lsize])+'\n')
buf = sockfd.recv(100)
arr = arr[lsize:] if int(buf) == lsize*10 else arr[:lsize]
sockfd.send(arr[0] + '\n')
buf = sockfd.recv(100)
print 'correct => {}'.format(arr[0])
buf = sockfd.recv(1000)
print buf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment