1
1
"""Problems testing basic knowledge -- easy to solve if you understand what is being asked"""
2
2
3
- from puzzle_generator import PuzzleGenerator
3
+ from puzzle_generator import PuzzleGenerator , Tags
4
4
from typing import List
5
5
6
6
7
7
# See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles
8
8
9
9
class SumOfDigits (PuzzleGenerator ):
10
+
11
+ tags = [Tags .math ]
12
+
10
13
@staticmethod
11
14
def sat (x : str , s = 679 ):
12
15
"""Find a number that its digits sum to a specific value."""
@@ -22,6 +25,9 @@ def gen_random(self):
22
25
23
26
24
27
class FloatWithDecimalValue (PuzzleGenerator ):
28
+
29
+ tags = [Tags .math ]
30
+
25
31
@staticmethod
26
32
def sat (z : float , v = 9 , d = 0.0001 ):
27
33
"""Create a float with a specific decimal."""
@@ -44,6 +50,9 @@ def gen_random(self):
44
50
45
51
46
52
class ArithmeticSequence (PuzzleGenerator ):
53
+
54
+ tags = [Tags .math ]
55
+
47
56
@staticmethod
48
57
def sat (x : List [int ], a = 7 , s = 5 , e = 200 ):
49
58
"""Create a list that is a subrange of an arithmetic sequence."""
@@ -61,6 +70,9 @@ def gen_random(self):
61
70
62
71
63
72
class GeometricSequence (PuzzleGenerator ):
73
+
74
+ tags = [Tags .math ]
75
+
64
76
@staticmethod
65
77
def sat (x : List [int ], a = 8 , r = 2 , l = 50 ):
66
78
"""Create a list that is a subrange of an gemoetric sequence."""
@@ -78,6 +90,9 @@ def gen_random(self):
78
90
79
91
80
92
class LineIntersection (PuzzleGenerator ):
93
+
94
+ tags = [Tags .math ]
95
+
81
96
@staticmethod
82
97
def sat (e : List [int ], a = 2 , b = - 1 , c = 1 , d = 2021 ):
83
98
"""
@@ -103,6 +118,9 @@ def gen_random(self):
103
118
104
119
105
120
class IfProblem (PuzzleGenerator ):
121
+
122
+ tags = [Tags .trivial ]
123
+
106
124
@staticmethod
107
125
def sat (x : int , a = 324554 , b = 1345345 ):
108
126
"""Satisfy a simple if statement"""
@@ -125,6 +143,9 @@ def gen_random(self):
125
143
126
144
127
145
class IfProblemWithAnd (PuzzleGenerator ):
146
+
147
+ tags = [Tags .trivial ]
148
+
128
149
@staticmethod
129
150
def sat (x : int , a = 9384594 , b = 1343663 ):
130
151
"""Satisfy a simple if statement with an and clause"""
@@ -148,6 +169,8 @@ def gen_random(self):
148
169
149
170
class IfProblemWithOr (PuzzleGenerator ):
150
171
172
+ tags = [Tags .trivial ]
173
+
151
174
@staticmethod
152
175
def sat (x : int , a = 253532 , b = 1230200 ):
153
176
"""Satisfy a simple if statement with an or clause"""
@@ -171,6 +194,8 @@ def gen_random(self):
171
194
172
195
class IfCases (PuzzleGenerator ):
173
196
197
+ tags = [Tags .trivial ]
198
+
174
199
@staticmethod
175
200
def sat (x : int , a = 4 , b = 54368639 ):
176
201
"""Satisfy a simple if statement with multiple cases"""
@@ -198,6 +223,9 @@ def gen_random(self):
198
223
199
224
200
225
class ListPosSum (PuzzleGenerator ):
226
+
227
+ tags = [Tags .trivial ]
228
+
201
229
@staticmethod
202
230
def sat (x : List [int ], n = 5 , s = 19 ):
203
231
"""Find a list of n non-negative integers that sum up to s"""
@@ -216,6 +244,9 @@ def gen_random(self):
216
244
217
245
218
246
class ListDistinctSum (PuzzleGenerator ):
247
+
248
+ tags = [Tags .math ]
249
+
219
250
@staticmethod
220
251
def sat (x : List [int ], n = 4 , s = 2021 ):
221
252
"""Construct a list of n distinct integers that sum up to s"""
@@ -244,6 +275,9 @@ def gen_random(self):
244
275
245
276
246
277
class ConcatStrings (PuzzleGenerator ):
278
+
279
+ tags = [Tags .trivial , Tags .strings ]
280
+
247
281
@staticmethod
248
282
def sat (x : str , s = ["a" , "b" , "c" , "d" , "e" , "f" ], n = 4 ):
249
283
"""Concatenate the list of characters in s"""
@@ -262,6 +296,8 @@ def gen_random(self):
262
296
263
297
class SublistSum (PuzzleGenerator ):
264
298
299
+ tags = [Tags .math ]
300
+
265
301
@staticmethod
266
302
def sat (x : List [int ], t = 677 , a = 43 , e = 125 , s = 10 ):
267
303
"""Sum values of sublist by range specifications"""
@@ -292,6 +328,8 @@ def gen_random(self):
292
328
293
329
class CumulativeSum (PuzzleGenerator ):
294
330
331
+ tags = [Tags .math , Tags .trivial ]
332
+
295
333
@staticmethod
296
334
def sat (x : List [int ], t = 50 , n = 10 ):
297
335
"""Find how many values have cumulative sum less than target"""
@@ -316,6 +354,9 @@ def gen_random(self):
316
354
317
355
318
356
class BasicStrCounts (PuzzleGenerator ):
357
+
358
+ tags = [Tags .strings ]
359
+
319
360
@staticmethod
320
361
def sat (s : str , s1 = 'a' , s2 = 'b' , count1 = 50 , count2 = 30 ):
321
362
"""
@@ -347,6 +388,9 @@ def gen_random(self):
347
388
348
389
349
390
class ZipStr (PuzzleGenerator ):
391
+
392
+ tags = [Tags .strings , Tags .trivial ]
393
+
350
394
@staticmethod
351
395
def sat (s : str , substrings = ["foo" , "bar" , "baz" , "oddball" ]):
352
396
"""
@@ -365,6 +409,9 @@ def gen_random(self):
365
409
366
410
367
411
class ReverseCat (PuzzleGenerator ):
412
+
413
+ tags = [Tags .trivial , Tags .strings ]
414
+
368
415
@staticmethod
369
416
def sat (s : str , substrings = ["foo" , "bar" , "baz" ]):
370
417
"""
@@ -382,6 +429,9 @@ def gen_random(self):
382
429
383
430
384
431
class EngineerNumbers (PuzzleGenerator ):
432
+
433
+ tags = [Tags .trivial , Tags .strings ]
434
+
385
435
@staticmethod
386
436
def sat (ls : List [str ], n = 100 , a = 'bar' , b = 'foo' ):
387
437
"""
@@ -401,6 +451,9 @@ def gen_random(self):
401
451
402
452
403
453
class PenultimateString (PuzzleGenerator ):
454
+
455
+ tags = [Tags .trivial , Tags .strings ]
456
+
404
457
@staticmethod
405
458
def sat (s : str , strings = ["cat" , "dog" , "bird" , "fly" , "moose" ]):
406
459
"""Find the alphabetically second to last last string in a list."""
@@ -417,6 +470,9 @@ def gen_random(self):
417
470
418
471
419
472
class PenultimateRevString (PuzzleGenerator ):
473
+
474
+ tags = [Tags .trivial , Tags .strings ]
475
+
420
476
@staticmethod
421
477
def sat (s : str , strings = ["cat" , "dog" , "bird" , "fly" , "moose" ]):
422
478
"""Find the reversed version of the alphabetically second string in a list."""
@@ -433,6 +489,9 @@ def gen_random(self):
433
489
434
490
435
491
class CenteredString (PuzzleGenerator ):
492
+
493
+ tags = [Tags .trivial , Tags .strings ]
494
+
436
495
@staticmethod
437
496
def sat (s : str , target = "foobarbazwow" , length = 6 ):
438
497
"""Find a substring of the given length centered within the target string."""
@@ -449,6 +508,9 @@ def gen_random(self):
449
508
450
509
451
510
class SubstrCount (PuzzleGenerator ):
511
+
512
+ tags = [Tags .brute_force , Tags .strings ]
513
+
452
514
@staticmethod
453
515
def sat (substring : str , string = "moooboooofasd" , count = 2 ):
454
516
"""Find a substring with a certain count in a given string"""
@@ -478,6 +540,9 @@ def gen_random(self):
478
540
479
541
480
542
class CompleteParens (PuzzleGenerator ):
543
+
544
+ tags = []
545
+
481
546
@staticmethod
482
547
def sat (t : str , s = "))(Add)some))parens()to()(balance(()(()(me!)((((" ):
483
548
"""Add parentheses to the beginning and end of s to make all parentheses balanced"""
0 commit comments