-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaneshjoyan_bikar.py
111 lines (109 loc) · 4.86 KB
/
daneshjoyan_bikar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import re
def solve(arr):
array = arr
arr_splited_by_equal = array.split("=")
#print(arr_splited_by_equal)
arr_splited_by_plus = arr_splited_by_equal[0].split("+")
number_one = arr_splited_by_plus[0].strip()
number_two = arr_splited_by_plus[1].strip()
number_three = arr_splited_by_equal[1].strip()
#print(number_one, number_two, number_three)
pattern = '#'
match_one = (re.search(pattern, number_one))
match_two = (re.search(pattern, number_two))
match_three = (re.search(pattern, number_three))
if(match_one):
real_number = int(number_three) - int(number_two)
position = match_one.start()
if(position == 0):
new_replace = number_one.replace("#" , "")
if((re.search(new_replace, str(real_number)))):
match_number= (re.search(new_replace, str(real_number)))
start_index = match_number.start()
else:
return("-1")
start_index = match_number.start()
new_real_number = str(real_number)[:start_index] + str(new_replace)
#print(new_real_number)
#print(real_number)
if(new_real_number == str(real_number)):
return(f"{real_number} + {number_two} = {number_three}")
else:
return("-1")
new_replace = number_one.replace("#" , "")
if(int(new_replace) + int(number_two) == int(number_three)):
return(f"{real_number} + {number_two} = {number_three}")
new_string = number_one.replace("#",str(real_number)[position])
#print(new_string)
if re.match(str(new_string), str(real_number)):
return(f"{real_number} + {number_two} = {number_three}")
else:
return("-1")
if(match_two):
real_number = int(number_three) - int(number_one)
position = match_two.start()
if(position == 0):
new_replace = number_two.replace("#" , "")
len_number_one = len(new_replace)
#print(len_number_one)
if((re.search(new_replace, str(real_number)))):
match_number= (re.search(new_replace, str(real_number)))
#print(match_number)
start_index = match_number.start()
else:
return("-1")
start_index = match_number.start()
new_real_number = str(real_number)[:start_index+1] + str(new_replace)
#print(new_real_number)
#print(real_number)
if(new_real_number == str(real_number)):
return(f"{number_one} + {real_number} = {number_three}")
else:
return("-1")
else:
position = match_two.start()
sliced_number_two = number_two.split('#')
if any(x in sliced_number_two[0] for x in str(real_number)) and str(real_number).endswith(sliced_number_two[1]):
return(f"{number_one} + {real_number} = {number_three}")
new_replace = number_two.replace("#" , "")
if(int(number_one) + int(new_replace) == int(number_three)):
return(f"{number_one} + {real_number} = {number_three}")
new_string = number_two.replace("#",str(real_number)[position])
#print(new_string)
if re.match(str(new_string), str(real_number)):
return(f"{number_one} + {real_number} = {number_three}")
else:
return("-1")
if(match_three):
real_number = int(number_one) + int(number_two)
#print(real_number)
position = match_three.start()
if(position == 0):
if number_three == '#':
return(f"{number_one} + {number_two} = {real_number}")
new_replace = number_three.replace("#" , "")
if((re.search(new_replace, str(real_number)))):
match_number= (re.search(new_replace, str(real_number)))
start_index = match_number.start()
else:
return("-1")
start_index = match_number.start()
new_real_number = str(real_number)[:start_index+1] + str(new_replace)
#print(new_real_number)
#print(real_number)
if(new_real_number == str(real_number)):
return(f"{number_one} + {number_two} = {real_number}")
else:
return("-1")
print(match_number)
new_replace = number_three.replace("#" , "")
if(int(number_one) + int(number_two) == int(new_replace)):
return(f"{number_one} + {number_two} = {real_number}")
new_string = number_three.replace("#",str(real_number)[position])
print(new_string)
print(real_number)
if re.match(str(new_string), str(real_number)):
return(f"{number_one} + {number_two} = {real_number}")
else:
return("-1")
print(solve("1003 + 35#7 = 35353300"))