forked from turing-machines/mentals-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_structure.gen
98 lines (85 loc) · 2.36 KB
/
tree_structure.gen
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
# root
## use: tree, evaluate
The 24 puzzle is an arithmetical puzzle in which the objective is to find a way
to manipulate four integers so that the end result is 24. Use 4 integers and basic
arithmetic operations: sum, sub, mul, div and brackets to obtain 24 in 1 equation.
Example: """
Input: 2 8 8 14
Possible next steps (nodes):
1. 2 + 8 = 10 (left: 8 10 14)
2. 8 / 2 = 4 (left: 4 8 14)
3. 14 + 2 = 16 (left: 8 8 16)
4. 2 * 8 = 16 (left: 8 14 16)
5. 8 - 2 = 6 (left: 6 8 14)
6. 14 - 8 = 6 (left: 2 6 8)
7. 14 / 2 = 7 (left: 7 8 8)
8. 14 - 2 = 12 (left: 8 8 12)
"""
Input: 4 5 8 2
Generate 8 possible next steps.
Store all steps in the tree as nodes e.g.
Node value 1: "2 + 8 = 10 (left: 8 10 14)"
Node value 2: "8 / 2 = 4 (left: 4 8 14)"
etc.
Then call evaluate with each available node values from the tree.
Using resoning paths from tree output final equation.
All given numbers from the input must be used in the final equation, e.g.
7 * (3 + 1) − 2 = 24
6 * 5 - 8 + 2 = 24
8 * 2 + 9 - 1 = 24
etc.
# tree
## input: e.g. "add to node `A` child nodes `B` and `C`", "remove node `D` with all branches", etc.
## use: memory
## keep_context: false
Build/update tree structure in formatted text.
Update the tree structure within the specified action;
Memorize final tree structure.
# evaluate
## input: { current_node: curent node value, input: numbers to evaluate e.g. 2 5 7 }
## use: tree
## keep_context: false
Example: """
Input: 10 14
10 + 14 = 24
sure
Input: 11 12
11 + 12 = 23
12 - 11 = 1
11 * 12 = 132
11 / 12 = 0.91
impossible
Input: 4 4 10
4 + 4 + 10 = 8 + 10 = 18
4 * 10 - 4 = 40 - 4 = 36
(10 - 4) * 4 = 6 * 4 = 24
sure
Input: 4 9 11
9 + 11 + 4 = 20 + 4 = 24
sure
Input: 5 7 8
5 + 7 + 8 = 12 + 8 = 20
(8 - 5) * 7 = 3 * 7 = 21
I cannot obtain 24 now, but numbers are within a reasonable range
likely
Input: 5 6 6
5 + 6 + 6 = 17
(6 - 5) * 6 = 1 * 6 = 6
I cannot obtain 24 now, but numbers are within a reasonable range
likely
Input: 10 10 11
10 + 10 + 11 = 31
(11 - 10) * 10 = 10
10 10 10 are all too big
impossible
Input: 1 3 3
1 * 3 * 3 = 9
(1 + 3) * 3 = 12
1 3 3 are all too small
impossible
"""
Strictly follow below actions in this sequence:
1. Evaluate if given numbers can reach 24 (sure/likely/impossible).
All given numbers must be used in each expression;
2. Call tree only ONE TIME to add child node:
with the `sure` equation OR `discard` as a value to the `current_node`;