Created
November 8, 2015 08:34
-
-
Save theoremoon/0b0c577c4d1cd2e10f64 to your computer and use it in GitHub Desktop.
SECCON福島大会 サイバー甲子園の Programming 300pt問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scount = 0 | |
bcount = 0 | |
fcount = 0 | |
ocount = 0 | |
runners = [0, 0, 0, 0] | |
pts = [0, 0] | |
turn = 0 | |
def out(): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
scount = 0 | |
bcount = 0 | |
fcount = 0 | |
ocount += 1 | |
if ocount >= 3: | |
turn += 1 | |
runners = [0, 0, 0, 0] | |
ocount = 0 | |
def homerun(): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
scount = 0 | |
bcount = 0 | |
fcount = 0 | |
for i in [3,2,1]: | |
if runners[i] != 0: | |
pts[turn%2] += 1 | |
pts[turn%2] += 1 | |
runners = [0, 0, 0, 0] | |
def adjust(a): | |
if a >= 4: | |
return 0 | |
else: | |
return a | |
def dead(): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
scount = 0 | |
bcount = 0 | |
fcount = 0 | |
runners[1] += 1 | |
for i in [1,2,3]: | |
if runners[i] > 1: | |
runners[i] -= 1 | |
runners[adjust(i+1)] += 1 | |
if runners[0] > 0: | |
pts[turn%2] += runners[0] | |
runners[0] = 0 | |
def hit(n): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
scount = 0 | |
bcount = 0 | |
fcount = 0 | |
for i in [3,2,1]: | |
if runners[i] != 0: | |
runners[i] -= 1 | |
runners[adjust(i+n)] += 1 | |
print("ADDED:" + str(adjust(i+n))) | |
runners[n] += 1 | |
if runners[0] > 0: | |
pts[turn%2] += runners[0] | |
runners[0] = 0 | |
def succ(cmd): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
if cmd is 'S': | |
scount += 1 | |
if scount >= 3: | |
out() | |
elif cmd is 'B': | |
bcount += 1 | |
if bcount >= 4: | |
dead() | |
elif cmd is 'F': | |
if scount < 2: | |
scount += 1 | |
elif cmd is 'O': | |
out() | |
elif cmd is 'D': | |
dead() | |
elif cmd is 'H': | |
homerun() | |
else: | |
hit(int(cmd)) | |
def status(): | |
global scount | |
global bcount | |
global fcount | |
global ocount | |
global runners | |
global pts | |
global turn | |
return "{}{}{},{},{}".format(bcount, scount, ocount, pts[0], pts[1]) | |
from pwn import * | |
if __name__ == '__main__': | |
sock = remote("10.100.1.1", 43329) | |
sock.recvuntil("000,0,0\n") | |
while True: | |
g = sock.recv() | |
if g[0] is 'C': | |
break | |
print(g) | |
succ(g[0]) | |
sock.send(status()) | |
print("status:" + status()) | |
print(runners) | |
while True: | |
print(sock.recv()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment