-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce count_sparse and format code
- Loading branch information
1 parent
dc35845
commit f25f62b
Showing
9 changed files
with
422 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Function HasAdjacentOnes(binNumber As String) As Integer | ||
Dim i As Integer | ||
Dim count As Integer | ||
count = 0 | ||
|
||
For i = 1 To Len(binNumber) | ||
If Mid(binNumber, i, 1) = "1" Then | ||
count = count + 1 | ||
If count >= 2 Then | ||
HasAdjacentOnes = 1 | ||
Exit Function | ||
End If | ||
Else | ||
count = 0 | ||
End If | ||
Next i | ||
|
||
HasAdjacentOnes = 0 | ||
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Function IsPowerOfTwo(number As Long) As Boolean | ||
If number <= 0 Then | ||
IsPowerOfTwo = False | ||
Else | ||
IsPowerOfTwo = (number And (number - 1)) = 0 | ||
End If | ||
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,300 @@ | ||
1,1 | ||
2,2 | ||
3,2 | ||
4,3 | ||
5,4 | ||
6,4 | ||
7,4 | ||
8,5 | ||
9,6 | ||
10,7 | ||
11,7 | ||
12,7 | ||
13,7 | ||
14,7 | ||
15,7 | ||
16,8 | ||
17,9 | ||
18,10 | ||
19,10 | ||
20,11 | ||
21,12 | ||
22,12 | ||
23,12 | ||
24,12 | ||
25,12 | ||
26,12 | ||
27,12 | ||
28,12 | ||
29,12 | ||
30,12 | ||
31,12 | ||
32,13 | ||
33,14 | ||
34,15 | ||
35,15 | ||
36,16 | ||
37,17 | ||
38,17 | ||
39,17 | ||
40,18 | ||
41,19 | ||
42,20 | ||
43,20 | ||
44,20 | ||
45,20 | ||
46,20 | ||
47,20 | ||
48,20 | ||
49,20 | ||
50,20 | ||
51,20 | ||
52,20 | ||
53,20 | ||
54,20 | ||
55,20 | ||
56,20 | ||
57,20 | ||
58,20 | ||
59,20 | ||
60,20 | ||
61,20 | ||
62,20 | ||
63,20 | ||
64,21 | ||
65,22 | ||
66,23 | ||
67,23 | ||
68,24 | ||
69,25 | ||
70,25 | ||
71,25 | ||
72,26 | ||
73,27 | ||
74,28 | ||
75,28 | ||
76,28 | ||
77,28 | ||
78,28 | ||
79,28 | ||
80,29 | ||
81,30 | ||
82,31 | ||
83,31 | ||
84,32 | ||
85,33 | ||
86,33 | ||
87,33 | ||
88,33 | ||
89,33 | ||
90,33 | ||
91,33 | ||
92,33 | ||
93,33 | ||
94,33 | ||
95,33 | ||
96,33 | ||
97,33 | ||
98,33 | ||
99,33 | ||
100,33 | ||
101,33 | ||
102,33 | ||
103,33 | ||
104,33 | ||
105,33 | ||
106,33 | ||
107,33 | ||
108,33 | ||
109,33 | ||
110,33 | ||
111,33 | ||
112,33 | ||
113,33 | ||
114,33 | ||
115,33 | ||
116,33 | ||
117,33 | ||
118,33 | ||
119,33 | ||
120,33 | ||
121,33 | ||
122,33 | ||
123,33 | ||
124,33 | ||
125,33 | ||
126,33 | ||
127,33 | ||
128,34 | ||
129,35 | ||
130,36 | ||
131,36 | ||
132,37 | ||
133,38 | ||
134,38 | ||
135,38 | ||
136,39 | ||
137,40 | ||
138,41 | ||
139,41 | ||
140,41 | ||
141,41 | ||
142,41 | ||
143,41 | ||
144,42 | ||
145,43 | ||
146,44 | ||
147,44 | ||
148,45 | ||
149,46 | ||
150,46 | ||
151,46 | ||
152,46 | ||
153,46 | ||
154,46 | ||
155,46 | ||
156,46 | ||
157,46 | ||
158,46 | ||
159,46 | ||
160,47 | ||
161,48 | ||
162,49 | ||
163,49 | ||
164,50 | ||
165,51 | ||
166,51 | ||
167,51 | ||
168,52 | ||
169,53 | ||
170,54 | ||
171,54 | ||
172,54 | ||
173,54 | ||
174,54 | ||
175,54 | ||
176,54 | ||
177,54 | ||
178,54 | ||
179,54 | ||
180,54 | ||
181,54 | ||
182,54 | ||
183,54 | ||
184,54 | ||
185,54 | ||
186,54 | ||
187,54 | ||
188,54 | ||
189,54 | ||
190,54 | ||
191,54 | ||
192,54 | ||
193,54 | ||
194,54 | ||
195,54 | ||
196,54 | ||
197,54 | ||
198,54 | ||
199,54 | ||
200,54 | ||
201,54 | ||
202,54 | ||
203,54 | ||
204,54 | ||
205,54 | ||
206,54 | ||
207,54 | ||
208,54 | ||
209,54 | ||
210,54 | ||
211,54 | ||
212,54 | ||
213,54 | ||
214,54 | ||
215,54 | ||
216,54 | ||
217,54 | ||
218,54 | ||
219,54 | ||
220,54 | ||
221,54 | ||
222,54 | ||
223,54 | ||
224,54 | ||
225,54 | ||
226,54 | ||
227,54 | ||
228,54 | ||
229,54 | ||
230,54 | ||
231,54 | ||
232,54 | ||
233,54 | ||
234,54 | ||
235,54 | ||
236,54 | ||
237,54 | ||
238,54 | ||
239,54 | ||
240,54 | ||
241,54 | ||
242,54 | ||
243,54 | ||
244,54 | ||
245,54 | ||
246,54 | ||
247,54 | ||
248,54 | ||
249,54 | ||
250,54 | ||
251,54 | ||
252,54 | ||
253,54 | ||
254,54 | ||
255,54 | ||
256,55 | ||
257,56 | ||
258,57 | ||
259,57 | ||
260,58 | ||
261,59 | ||
262,59 | ||
263,59 | ||
264,60 | ||
265,61 | ||
266,62 | ||
267,62 | ||
268,62 | ||
269,62 | ||
270,62 | ||
271,62 | ||
272,63 | ||
273,64 | ||
274,65 | ||
275,65 | ||
276,66 | ||
277,67 | ||
278,67 | ||
279,67 | ||
280,67 | ||
281,67 | ||
282,67 | ||
283,67 | ||
284,67 | ||
285,67 | ||
286,67 | ||
287,67 | ||
288,68 | ||
289,69 | ||
290,70 | ||
291,70 | ||
292,71 | ||
293,72 | ||
294,72 | ||
295,72 | ||
296,73 | ||
297,74 | ||
298,75 | ||
299,75 | ||
300,75 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 16:25 | ||
|
||
/* | ||
42dec = 101010bin | ||
nearest power of two (less than n): | ||
32dec = 100000bin | ||
100000 - jaka potęga dwójki, tyle zer na końcu | ||
10 0001 | ||
10 0010 | ||
10 0100 | ||
10 1000 | ||
1010 01 | ||
1010 10 | ||
10010 1 | ||
*/ | ||
|
||
int nearest_lower_pow_of_two(int n) {} | ||
|
||
int count_sparse_numbers(int n) {} | ||
|
||
int main() { return 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
bool is_sparse(int n) { | ||
while (n) { | ||
if ((n & 3) == 3) return false; | ||
|
||
n >>= 1; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int count_sparse_numbers_brute(int n) { | ||
int counter = 0; | ||
|
||
while (n > 0) { | ||
if (is_sparse(n)) counter++; | ||
n--; | ||
} | ||
|
||
return counter; | ||
} | ||
|
||
int main() { | ||
int n; | ||
if (!scanf("%d", &n)) printf("invalid value"); | ||
|
||
printf("%d", count_sparse_numbers_brute(n)); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.