print("hello word")

hash_dict = {
    '0000': '1111',
    '1000': '0111',
    '0001': '0010',
    '1001': '1100',
    '0010': '0000',
    '1010': '0110',
    '0011': '0101',
    '1011': '1001',
    '0100': '1010',
    '1100': '0011',
    '0101': '1101',
    '1101': '1110',
    '0110': '1000',
    '1110': '0001',
    '0111': '1011',
    '1111': '0100'
}

import random
def get_strings(usr_input, nonce_len):
    strarr = []

    #generate all input + nonce combinations
    def generate(n, s=usr_input):
        if len(s) == n:
            strarr.append(s)
        else:
            generate(n, s + '0')
            generate(n, s + '1')

    generate(len(usr_input) + nonce_len)
    random.shuffle(strarr)
    return strarr

def proof_of_work(usr_input, level, nonce_len):
  strarr = get_strings(usr_input, nonce_len)
  count = 1
  for i in strarr:
    if hash_dict[i].startswith('0'*level):
      # print("found hash", i, "in", count, " tries")
      random.shuffle(strarr)
      break;
    else: 
      count += 1
    
  return count
 

def getAvgTries(tries, level=2, nonce_len=3):
  sum = 0
  usr_input = '1'
  for i in range(tries):
    sum += proof_of_work(usr_input, level, nonce_len)
  return sum/tries

getAvgTries(100)

