First part was very easy but for the second part, I took little help from here.

## Solution

```
def permutation(li: list):
all_ps = set()
psl = np.prod(np.linspace(1,len(li), len(li)).astype(int))
while len(all_ps)!=psl:
curr_ps = np.random.choice(range(len(li)), len(li), replace=False)
curr_ps = "".join([li[i] for i in curr_ps])
all_ps.add(curr_ps)
return all_ps
all_ps = permutation("abcdefg")
d = {
"abcefg": 0,
"cf": 1,
"acdeg": 2,
"acdfg": 3,
"bcdf": 4,
"abdfg": 5,
"abdefg": 6,
"acf": 7,
"abcdefg": 8,
"abcdfg": 9,
}
cnts = {2:1, 4:4, 3:7, 7:8}
sol1 = 0
sol2 = 0
for row in data1:
signals, output = row.split("|")
signals = [s.strip() for s in signals.strip().split(" ")]
output = [s.strip() for s in output.strip().split(" ")]
for o in output:
l = len(o)
if ls.get(l):
sol1+=1
for pr in all_ps:
to = str.maketrans("abcdefg", pr)
ts = ["".join(sorted(sig.translate(to))) for sig in signals]
top = ["".join(sorted(op.translate(to))) for op in output]
if all(code in d for code in ts):
sol2 += int("".join(str(d[code]) for code in top))
break
sol1, sol2
```

Later I knew there is actually a python generator `permutation`

inside `itertools`

.

## Why not read more?

- Gesture Based Visually Writing System Using OpenCV and Python
- Gesture Based Visually Writing System: Adding Visual User Interface
- Gesture Based Visually Writing System: Adding Virtual Animationn, New Mode and New VUI
- Gesture Based Visually Writing System: Add Slider, More Colors and Optimized OOP code
- Gesture Based Visually Writing System: A Web App
- Contour Based Game: Break The Bricks
- Linear Regression from Scratch
- Writing Popular ML Optimizers from Scratch
- Feed Forward Neural Network from Scratch
- Convolutional Neural Networks from Scratch
- Writing a Simple Image Processing Class from Scratch
- Deploying a RASA Chatbot on Android using Unity3d
- Naive Bayes for text classifications: Scratch to Framework
- Simple OCR for Devanagari Handwritten Text

## Top comments (0)