Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created November 2, 2015 13:04
Show Gist options
  • Select an option

  • Save avamsi/2c74e28e6a08c75ae31b to your computer and use it in GitHub Desktop.

Select an option

Save avamsi/2c74e28e6a08c75ae31b to your computer and use it in GitHub Desktop.
Python code to generate HackerRank compatible zip file for test cases.
import os
import random
import sys
import zipfile
try:
os.mkdir('input')
os.mkdir('output')
except OSError:
pass
tf = 10 # number of test files
for i in xrange(1, tf + 1):
print >>sys.stderr, 'Generating:', i
sys.stdout = open('input/input%02d.txt' % i, 'wb')
#
# print test case(s) to input.txt
#
sys.stdout.close()
# replace name by actual name in below block
with zipfile.ZipFile('name.zip', 'w', zipfile.ZIP_DEFLATED) as zf:
for i in xrange(1, tf + 1):
print >>sys.stderr, 'Zipping:', i
os.system('name < input/input%02d.txt > output/output%02d.txt' % (i, i))
zf.write('input/input%02d.txt' % i)
zf.write('output/output%02d.txt' % i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment