-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes.txt
More file actions
224 lines (186 loc) · 5.2 KB
/
Notes.txt
File metadata and controls
224 lines (186 loc) · 5.2 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
root
left right
0 (1 + max(1, 2)) = 1 + 2 = 3
1 (1) 2 (1 + max(1, 0) = 2)
3 (1)
0 (1 + min(1, 1)) = 1 + 1= 2
1 (1) 2 (1 + min(1, 0) = 1)
3 (1)
Binary Tree:
50
-100 60
0 100
-50 10 75 150
Binary Search Tree:
50
0 100
-50 10 75 150
-100 60
MinHeap: (-100, -50, 0, 10, 50, 60 75, 100, 150)
-100
-50 0
50 10 60 100
75 150
10
null 50
60 100
0 - 99: 10 + 10 = 20
100 - 199: 2 * 20
200 - 299: 3 * 20 + 100 = 160
300 - 345: 5 + 10 = 15
total: 160 + 15 = 175
S: Single Responsibility
O: Open-Close
L: Liskov Substitution (Polymorphism)
I: Interface Segregation (Cohesive Interface)
D: Dependency Inversion (Abstraction/Interface. Not details)
0: N
1: N-1
2: N-2
0 - 4
0 - 1, 3 - 4
1 2 9
4 5 6
2 8 9
1 2 9 7
4 5 6 8
2 8 9 9
1(path1:6; path2: 7) 2 (path1=Long.Min; path2=[n][n](4)
returns 1 + 7 returns 2 + 4
3 (path1:[n][n](4); path2: Long.Min) 4 returns 4 (value of this location)
returns 3 + 4
1 3 5
2 4 6
7 8 9
22 (1,2,4,6,9)
23 (1,3,4,6,9)
24 (1,3,5,6,9) (1,2,4,8,9)
25 (1,3,4,8,9)
27 (1,2,7,8,9)
N: sum
N-1: sum - f(N)
N-2: sum - f(N-1)
1
2 4
9 5 2
6 8
9
1
2 4
9 5 2
7 6 8
8 9
9
Minute arm:
min /60 * 360
Hours arm:
hour / 12 * 360 + n
n: 60 min -> 1/12 * 360
m -> m/60 * 1/12 * 360
Angle between minute and hour hands:
h/12 * 360 + m/60 * 1/12 * 360 - m/60 * 360
= 360 * (h/12 + m/60 * 1/12 - m/60)
= 360 * (h/12 + m/60( 1/12 - 1))
= 360 * (h/12 - m/60 * 11/12)
1 2 3 4 5 6 7 8 9 10
(n + 1) * (n / 2) = n(n + 1) / 2
1 2 3 4 5 6 7 8 9
(n + 1) * (n / 2) - n = n(n+1) / 2 - n
= (n^2 + n)/2 - n
= (n^2 + n - 2n) / 2
= (n^2 - n) / 2
= n(n - 1) / 2
pairs #:
a b c
2 1 => 2 + 1 => (n - 1) + 1
a b c d
3 2 1 0 => 3 + 2 + 1 => (n - 1) + 2 + 1
= n(n+1) / 2 - n
= (n^2 + n)/2 - n
= (n^2 + n - 2n) / 2
= (n^2 - n) / 2
= n(n - 1) / 2
a b c d e
4 3 2 1 0 => 4 + 3 + 2 + 1 = 10
a b c d e f
5 4 3 2 1 0 => 5 + 4 + 3 + 2 + 1 = 15
345 (n2)
x 76 (n1)
----
2070 result: 0(3) 7(2) 0(2) 2(carry) i_n1: 0, i_n2: 3
2415 result: 2(4) 2(3) 6(2) 2(carry) n1: 1, n2: 3
-----
26220
Alignment:
Align 4: alignment - 1 = 3; ~(alignment - 1) = ~3 = 1100
1: 1 + 3 = 4 / 4 = 1 0100 & 1100 = 0100
2: 2 + 3 = 5 / 4 = 1 0101 & 1100 = 0100
3: 3 + 3 = 6 / 4 = 1 0110 & 1100 = 0100
4: 4 + 3 = 7 / 4 = 1 0111 & 1100 = 0100
5: 5 + 3 = 8 / 4 = 2 1000 & 1100 = 1000
6: 6 + 3 = 9 / 4 = 2 1001 & 1100 = 1000
7: 7 + 3 = 10 / 4 = 2 1010 & 1100 = 1000
8: 8 + 3 = 11 / 4 = 2 1011 & 1100 = 1000
9: 9 + 3 = 12 / 4 = 3 1100 & 1100 = 1100
10:10 + 3 = 13 / 4 = 3 1101 & 1100 = 1100
--------------- GoogleTest with variable template parameters -----------------------------
https://stackoverflow.com/questions/78494481/c-invoke-member-function-which-expects-input-params-passed-by-reference#78494481
Impediment: Not able to use mixture of input parameters by value and reference
template <typename R, typename... Args>
class SUTTestFixture : public testing::TestWithParam<tuple<R, Args...>>
{
public:
void SetUp() override
{
return get<1>(this->GetParam());
}
R Expected()
{
return get<0>(this->GetParam());
}
template <typename Method>
R Actual(Method &&method)
{
// Peel Expected off the front, and then call _rangeObj.Method(args...)
return apply([&](auto &&, auto &&...args)
{ return invoke(forward<Method>(method), _rangeObj, forward<decltype(args)>(args)...); }, this->GetParam());
}
protected:
Range _rangeObj;
};
class TestFixture1 : public SUTTestFixture<long, vector<long>>
{
};
class TestFixture2 : public SUTTestFixture<size_t, size_t, vector<size_t>>
{
};
TEST_P(TestFixture2, SumPairsTests)
{
EXPECT_EQ(Expected(), Actual(&Range::SumPairs));
}
// INSTANTIATE_TEST_SUITE_P(TestFunction1, TestFixture1, testing::Combine(testing::Values(1L), testing::Values(std::vector{1L})));
INSTANTIATE_TEST_SUITE_P(SumPairsTests, TestFixture2, ::testing::Values(make_tuple(2, 8, vector<size_t>{1, 2, 3, 4, 5, 6, 5}), make_tuple(3, 12, vector<size_t>{5, 7, 9, 13, 11, 6, 6, 3, 3}), make_tuple(4, 10, vector<size_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})));
#if 0
INSTANTIATE_TEST_SUITE_P(TestFunction2, TestFixture2, testing::Combine(testing::Values(1uz), testing::Values(1uz), testing::Values(std::vector{1uz})));
TEST_P(TestFixture2, Foo)
{
EXPECT_EQ(Expected(), Actual(&SUT::Function2));
}
#endif
-----------------------------------------------------------
--------------- GoogleTest with auto-generated number range -----------------------------
https://stackoverflow.com/questions/78489208/c-googletest-instantiate-test-suite-p-combine-values-and-valuesin
INSTANTIATE_TEST_SUITE_P(
SumPairsTests,
SumPairsTestFixture,
::testing::Combine(
::testing::Values(make_tuple(2, 8, vector<size_t>{1, 2, 3, 4, 5, 6, 5}),
make_tuple(3, 12, vector<size_t>{5, 7, 9, 13, 11, 6, 6, 3, 3}),
//make_tuple(4, 10, vector<size_t>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
::testing::ValuesIn([]() -> generator<const size_t>
{
co_yield 4;
co_yield 10;
co_yield ranges::elements_of(ranges::iota_view(0, 10)); }()))
);
-----------------------------------------------------------