-
Notifications
You must be signed in to change notification settings - Fork 0
/
races.go
139 lines (120 loc) · 3.6 KB
/
races.go
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package testing
import (
"fmt"
. "github.com/gabetucker2/gostack"//lint:ignore ST1001, ignore warning
)
func RaceNative() {
fmt.Println("- BEGINNING NATIVE GO RACE")
// INIT
startKeys := []any {"Key A", "Bad Key", "Key A", 2.5, "Michael Keaton"} // must separate maps like so since native Go maps are unordered
startVals := []any {40, "Bad Value", "Hello", 40, "520"}
searchKeys := []any {"Key A", 2.5, "Michael Keaton"}
keysToInsert := []any {"I", "To"}
valsToInsert := []any {"Am new", "This set"}
// TASK A
var taskA []any
for i := 0; i < len(startKeys); i++ {
k := startKeys[i]
v := startVals[i]
cont := false
for _, searchKey := range searchKeys {
if k == searchKey {
cont = true
break
}
}
if cont {
for _, otherV := range taskA {
if otherV == v {
cont = false
break
}
}
if cont {
taskA = append(taskA, v)
}
}
}
// TASK B
var taskBKeys, taskBVals []any
for _, taskAVal := range taskA {
for i := 0; i < len(startVals); i++ {
v := startVals[i]
if taskAVal == v {
taskBKeys = append(taskBKeys, v)
taskBVals = append(taskBVals, i)
break
}
}
}
// TASK C
var taskCKeys, taskCVals []any
for i := 0; i < len(taskBKeys); i++ {
k := taskBKeys[i]
v := taskBVals[i]
if 1 < v.(int) && v.(int) < 3 {
for j := 0; j < len(keysToInsert); j++ {
inK := keysToInsert[j]
inV := valsToInsert[j]
taskCKeys = append(taskCKeys, inK)
taskCVals = append(taskCVals, inV)
}
} else {
taskCKeys = append(taskCKeys, k)
taskCVals = append(taskCVals, v)
}
}
// TASK D
taskCKeys2 := append(taskCKeys, taskCKeys...)
taskCKeys2 = append(taskCKeys2, taskCKeys2...)
taskCVals2 := append(taskCVals, taskCVals...)
taskCVals2 = append(taskCVals2, taskCVals2...)
taskDKeys := [][][][]any{{{{nil, nil}, {nil, nil}}, {{nil, nil}, {nil, nil}}}, {{{nil, nil}, {nil, nil}}, {{nil, nil}, {nil, nil}}}}
taskDVals := [][][][]any{{{{nil, nil}, {nil, nil}}, {{nil, nil}, {nil, nil}}}, {{{nil, nil}, {nil, nil}}, {{nil, nil}, {nil, nil}}}}
for i := 0; i < 16; i++ { // recursion would be unnecessarily complicated for this data structure
var a, b, c, d int // convert i into 2x2x2x2 sequence: ([0][0][0][0], [0][0][0][1], [0][0][1][0], ..., [1][1][1][1])
if i%2 == 1 {d = 1}
if ((i-d)/2)%2 == 1 {c = 1}
if (4 <= i && i < 8) || (12 <= i && i < 16) {b = 1}
if 8 <= i {a = 1}
taskDKeys[a][b][c][d] = taskCKeys2[i]
taskDVals[a][b][c][d] = taskCVals2[i]
}
// PRINTS
fmt.Print("A: ")
fmt.Println(taskA)
fmt.Print("B Keys: ")
fmt.Println(taskBKeys)
fmt.Print("B Vals: ")
fmt.Println(taskBVals)
fmt.Print("C Keys: ")
fmt.Println(taskCKeys)
fmt.Print("C Vals: ")
fmt.Println(taskCVals)
fmt.Print("D Keys: ")
fmt.Println(taskDKeys)
fmt.Print("D Vals: ")
fmt.Println(taskDVals)
}
func RaceGostack() {
fmt.Println("- BEGINNING GOSTACK RACE")
// INIT
start := MakeStack([]any {"Key A", "Bad Key", "Key A", 2.5, "Michael Keaton"}, []any {40, "Bad Value", "Hello", 40, "520"})
searchKeys := MakeStack([]any {"Key A", 2.5, "Michael Keaton"})
pairsToInsert := MakeStack([]any {"I", "To"}, []any {"Am new", "This set"})
// TASK A
taskA := start.GetMany(FIND_Key, searchKeys).Unique()
// TASK B
taskB := MakeStack(taskA, start.GetMany(FIND_KeyVal, taskA, RETURN_Idxs))
// TASK C
taskC := taskB.Clone().Update(REPLACE_Card, pairsToInsert, FIND_Lambda, func(card *Card) bool {
return 1 < card.Val.(int) && card.Val.(int) < 3
})
// TASK D
taskD := MakeStackMatrix(taskC.Clone().Duplicate(4), taskC.Clone().Duplicate(4).SwitchKeysVals(), []int{2, 2, 2, 2})
// PRINTS
taskA.Print("A")
taskB.Print("B")
taskC.Print("C")
taskD.Print("D")
}