# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import argparse
import sys

LOCAL = False
if LOCAL:
    k = 16
    t = 4
    m = 12
else:
    parser = argparse.ArgumentParser()
    parser.add_argument('-k', nargs=1)
    parser.add_argument('-t', nargs=1)
    parser.add_argument('-m', nargs=1)
    parser.add_argument('-d', nargs=1)
    args = parser.parse_args()
    #print args.k, args.t, args.m
    k = int(args.k[0])
    t = int(args.t[0])
    m = int(args.m[0])
    d = args.d[0]
np.random.seed(42)    
w = m * t // k

H_basic = np.zeros((m//w, k), dtype=np.bool)
for i in range(m//w):
    for j in range(i * t, (i + 1) * t):
        H_basic[i, j] = 1

H = H_basic.copy()
for p in range(w - 1):
    perm_idx = np.random.permutation(k)
    H = np.vstack((H, H_basic[:, perm_idx]))

if LOCAL:
    for i in range(m):
        for j in range(k):
            sys.stdout.write('%d'%(H[i,j]))
        sys.stdout.write('\n')

with open(d, 'w') as fout:    
    fout.write('%d %d\n'%(m, t))
    for i in range(m):
        #sys.stdout.write('%d: '%(i))
        for j in range(k):
            if H[i, j] == 1:
                fout.write('%d '%(j))
        fout.write('\n')

