-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbruteForceFindFunction.py
49 lines (40 loc) · 1.67 KB
/
bruteForceFindFunction.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
from itertools import product
def OR(a, b):
return max(a, b)
def AND(a, b):
return min(a, b)
# Corrected SHIFT operation using a dictionary for transitions
def SHIFT(a):
SHIFT_map = {0: 0.5, 0.5: 1, 1: 0}
return SHIFT_map[a]
# Apply a sequence of operations to an input value
def apply_operations(sequence, input_value):
result = input_value
for op in sequence:
if op == 'SHIFT':
result = SHIFT(result)
elif op == 'OR':
result = OR(result, result)
elif op == 'AND':
result = AND(result, result)
return result
# Inputs and their desired NOT outputs
inputs = [0, 0.5, 1]
desired_outputs_NOT = [1, 0.5, 0]
operations = ['SHIFT', 'OR', 'AND']
def find_successful_sequences():
current_depth = 1
while True: # Loop indefinitely until a solution is found or a break condition is met
possible_sequences = [p for p in product(operations, repeat=current_depth)]
for sequence in possible_sequences:
results = [apply_operations(sequence, input_value) for input_value in inputs]
if results == desired_outputs_NOT:
return sequence, current_depth # Return the successful sequence and its depth
current_depth += 1
print(f"trying depth {current_depth}")
successful_sequence, successful_depth = find_successful_sequences()
# If a successful sequence is found, print it and the depth. Otherwise, indicate failure.
if successful_sequence:
print(f"Successful sequence for NOT operation found at depth {successful_depth}:", successful_sequence)
else:
print("No sequence found that performs the NOT operation, stopped at depth 10 for practicality.")