#!/usr/bin/python3

import sys
import re
from fractions import Fraction
from solver.integer import IntegerTchisla
from solver.rational import RationalTchisla

integer_re = re.compile("^\\d+")
rational_re = re.compile("^\\d+(/\\d+)?$")
number_re = rational_re

solvers = {
    "integer": [
        {"regex": integer_re, "constructor": int, "solver": IntegerTchisla}
    ],
    "rational": [
        {"regex": rational_re, "constructor": Fraction, "solver": RationalTchisla}
    ],
    "incremental": [
        {"regex": integer_re, "constructor": int, "solver": IntegerTchisla},
        {"regex": rational_re, "constructor": Fraction, "solver": RationalTchisla}
    ]
}

def general_solver(n, target, solver_type):
    depth = None
    solution = None
    for solver in solvers[solver_type]:
        if not solver["regex"].match(target):
            continue
        current_target = solver["constructor"](target)
        tchisla = solver["solver"](n, current_target)
        max_depth = depth
        original_solution = solution
        depth = tchisla.solve(max_depth)
        solution = tchisla.solution_prettyprint(current_target, True)
        if not solution:
            depth = max_depth
            solution = original_solution
            continue
        if original_solution:
            print("=" * 20)
        for string in solution:
            print(string)

def solve(string, solver_type):
    if "#" in string:
        array = string.split("#")
        target = array[0]
        n = array[1]
        if integer_re.match(n) and number_re.match(target):
            n = int(n)
            print(str(target) + " # " + str(n))
            general_solver(n, target, solver_type)
    elif number_re.match(string):
        for n in range(1, 10):
            print(str(string) + " # " + str(n))
            general_solver(n, string, solver_type)

def main(argv):
    if argv[0][:2] == "--":
        for string in argv[1:]:
            solve(string, argv[0][2:])
    else:
        for string in argv:
            solve(string, "incremental")

if __name__ == "__main__":
    if len(sys.argv) > 1:
        main(sys.argv[1:])

@@ -182,16 +182,17 @@
 e(%22%5E%5C%5Cd+
+$
 %22)%0Aratio
@@ -1457,16 +1457,48 @@
 it(%22#%22)%0A
+        if len(array) == 2:%0A    
         
@@ -1519,24 +1519,28 @@
 %5B0%5D%0A        
+    
 n = array%5B1%5D
@@ -1548,16 +1548,20 @@
         
+   
+ 
 if integ
@@ -1612,24 +1612,28 @@
             
+    
 n = int(n)%0A 
@@ -1635,32 +1635,36 @@
 (n)%0A            
+  
+  
 print(str(target
@@ -1675,32 +1675,36 @@
 %22 # %22 + str(n))%0A
+    
             gene

fix wrong regex