-2

I play to HackNet game and i have to guess a word to bypass a firewall.

The key makes 6 characters long and contains the letters K,K,K,U,A,N.

What is the simplest way to generate all possible combinations either in bash or in python ? (bonus point for bash)

Chapelle
  • 1
  • 1

2 Answers2

0

Here is a backtracking-based solution in Python:

db = {"K" : 3, "U" : 1, "A" : 1, "N" : 1}
N = 6
def possibilities(v):
  l = []
  for k in db.keys():
    if v.count(k) < db[k]:
      l.append(k)
  return l

def generateImpl(a):
  if len(a) < N:
    lst = []
    for c in possibilities(a):
      lst += generateImpl(a+[c])
    return lst
  else:
    return [''.join(a)]

def generate():
  return generateImpl([])

Just run generate() to obtain a list of possible words.

0

You have 6 letters and need to find a combination of 6 letters. If you are not using the same character in ['K','K','K','U','A','N'] again and again, then there is only 1 permutation.

If you can use the same character again and again, you can use the following code to generate all possible combinations.

import itertools

y = itertools.combinations_with_replacement(['K','U','A','N'],6)

for i in list(y):
    print(i)