Skip to content

Commit 44c09e7

Browse files
committed
Started adding tags
1 parent d8bf119 commit 44c09e7

21 files changed

+160
-26
lines changed

generators/ICPC.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Problems inspired by the [International Collegiate Programming Contest](https://icpc.global) (ICPC).
33
"""
44

5-
from puzzle_generator import PuzzleGenerator
5+
from puzzle_generator import PuzzleGenerator, Tags
66
from typing import List
77

88

generators/IMO.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad)
33
[problems](https://www.imo-official.org/problems.aspx)"""
44

5-
from puzzle_generator import PuzzleGenerator
5+
from puzzle_generator import PuzzleGenerator, Tags
66
from typing import List
77

88

generators/algebra.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Roots of polynomials"""
22

3-
from puzzle_generator import PuzzleGenerator
3+
from puzzle_generator import PuzzleGenerator, Tags
44
from typing import List
55

66

@@ -10,6 +10,8 @@
1010
class QuadraticRoot(PuzzleGenerator):
1111
"""See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)"""
1212

13+
tags = [Tags.math, Tags.famous]
14+
1315
@staticmethod
1416
def sat(x: float, coeffs=[2.5, 1.3, -0.5]):
1517
"""
@@ -47,6 +49,8 @@ def gen_random(self):
4749
class AllQuadraticRoots(PuzzleGenerator):
4850
"""See [quadratic equations](https://en.wikipedia.org/wiki/Quadratic_formula)."""
4951

52+
tags = [Tags.math, Tags.famous]
53+
5054
@staticmethod
5155
def sat(roots: List[float], coeffs=[1.3, -0.5]):
5256
"""Find all (real) solutions to: x^2 + b x + c (i.e., factor into roots), here coeffs = [b, c]"""
@@ -70,6 +74,8 @@ def gen_random(self):
7074
class CubicRoot(PuzzleGenerator):
7175
"""See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula)."""
7276

77+
tags = [Tags.math, Tags.famous]
78+
7379
@staticmethod
7480
def sat(x: float, coeffs=[2.0, 1.0, 0.0, 8.0]):
7581
"""
@@ -104,6 +110,8 @@ def gen_random(self):
104110
class AllCubicRoots(PuzzleGenerator):
105111
"""See [cubic equation](https://en.wikipedia.org/wiki/Cubic_formula)."""
106112

113+
tags = [Tags.math, Tags.famous]
114+
107115
@staticmethod
108116
def sat(roots: List[float], coeffs=[1.0, -2.0, -1.0]):
109117
"""Find all 3 distinct real roots of x^3 + a x^2 + b x + c, i.e., factor into (x-r1)(x-r2)(x-r3).

generators/basic.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Problems testing basic knowledge -- easy to solve if you understand what is being asked"""
22

3-
from puzzle_generator import PuzzleGenerator
3+
from puzzle_generator import PuzzleGenerator, Tags
44
from typing import List
55

66

77
# See https://github.com/microsoft/PythonProgrammingPuzzles/wiki/How-to-add-a-puzzle to learn about adding puzzles
88

99
class SumOfDigits(PuzzleGenerator):
10+
11+
tags = [Tags.math]
12+
1013
@staticmethod
1114
def sat(x: str, s=679):
1215
"""Find a number that its digits sum to a specific value."""
@@ -22,6 +25,9 @@ def gen_random(self):
2225

2326

2427
class FloatWithDecimalValue(PuzzleGenerator):
28+
29+
tags = [Tags.math]
30+
2531
@staticmethod
2632
def sat(z: float, v=9, d=0.0001):
2733
"""Create a float with a specific decimal."""
@@ -44,6 +50,9 @@ def gen_random(self):
4450

4551

4652
class ArithmeticSequence(PuzzleGenerator):
53+
54+
tags = [Tags.math]
55+
4756
@staticmethod
4857
def sat(x: List[int], a=7, s=5, e=200):
4958
"""Create a list that is a subrange of an arithmetic sequence."""
@@ -61,6 +70,9 @@ def gen_random(self):
6170

6271

6372
class GeometricSequence(PuzzleGenerator):
73+
74+
tags = [Tags.math]
75+
6476
@staticmethod
6577
def sat(x: List[int], a=8, r=2, l=50):
6678
"""Create a list that is a subrange of an gemoetric sequence."""
@@ -78,6 +90,9 @@ def gen_random(self):
7890

7991

8092
class LineIntersection(PuzzleGenerator):
93+
94+
tags = [Tags.math]
95+
8196
@staticmethod
8297
def sat(e: List[int], a=2, b=-1, c=1, d=2021):
8398
"""
@@ -103,6 +118,9 @@ def gen_random(self):
103118

104119

105120
class IfProblem(PuzzleGenerator):
121+
122+
tags = [Tags.trivial]
123+
106124
@staticmethod
107125
def sat(x: int, a=324554, b=1345345):
108126
"""Satisfy a simple if statement"""
@@ -125,6 +143,9 @@ def gen_random(self):
125143

126144

127145
class IfProblemWithAnd(PuzzleGenerator):
146+
147+
tags = [Tags.trivial]
148+
128149
@staticmethod
129150
def sat(x: int, a=9384594, b=1343663):
130151
"""Satisfy a simple if statement with an and clause"""
@@ -148,6 +169,8 @@ def gen_random(self):
148169

149170
class IfProblemWithOr(PuzzleGenerator):
150171

172+
tags = [Tags.trivial]
173+
151174
@staticmethod
152175
def sat(x: int, a=253532, b=1230200):
153176
"""Satisfy a simple if statement with an or clause"""
@@ -171,6 +194,8 @@ def gen_random(self):
171194

172195
class IfCases(PuzzleGenerator):
173196

197+
tags = [Tags.trivial]
198+
174199
@staticmethod
175200
def sat(x: int, a=4, b=54368639):
176201
"""Satisfy a simple if statement with multiple cases"""
@@ -198,6 +223,9 @@ def gen_random(self):
198223

199224

200225
class ListPosSum(PuzzleGenerator):
226+
227+
tags = [Tags.trivial]
228+
201229
@staticmethod
202230
def sat(x: List[int], n=5, s=19):
203231
"""Find a list of n non-negative integers that sum up to s"""
@@ -216,6 +244,9 @@ def gen_random(self):
216244

217245

218246
class ListDistinctSum(PuzzleGenerator):
247+
248+
tags = [Tags.math]
249+
219250
@staticmethod
220251
def sat(x: List[int], n=4, s=2021):
221252
"""Construct a list of n distinct integers that sum up to s"""
@@ -244,6 +275,9 @@ def gen_random(self):
244275

245276

246277
class ConcatStrings(PuzzleGenerator):
278+
279+
tags = [Tags.trivial, Tags.strings]
280+
247281
@staticmethod
248282
def sat(x: str, s=["a", "b", "c", "d", "e", "f"], n=4):
249283
"""Concatenate the list of characters in s"""
@@ -262,6 +296,8 @@ def gen_random(self):
262296

263297
class SublistSum(PuzzleGenerator):
264298

299+
tags = [Tags.math]
300+
265301
@staticmethod
266302
def sat(x: List[int], t=677, a=43, e=125, s=10):
267303
"""Sum values of sublist by range specifications"""
@@ -292,6 +328,8 @@ def gen_random(self):
292328

293329
class CumulativeSum(PuzzleGenerator):
294330

331+
tags = [Tags.math, Tags.trivial]
332+
295333
@staticmethod
296334
def sat(x: List[int], t=50, n=10):
297335
"""Find how many values have cumulative sum less than target"""
@@ -316,6 +354,9 @@ def gen_random(self):
316354

317355

318356
class BasicStrCounts(PuzzleGenerator):
357+
358+
tags = [Tags.strings]
359+
319360
@staticmethod
320361
def sat(s: str, s1='a', s2='b', count1=50, count2=30):
321362
"""
@@ -347,6 +388,9 @@ def gen_random(self):
347388

348389

349390
class ZipStr(PuzzleGenerator):
391+
392+
tags = [Tags.strings, Tags.trivial]
393+
350394
@staticmethod
351395
def sat(s: str, substrings=["foo", "bar", "baz", "oddball"]):
352396
"""
@@ -365,6 +409,9 @@ def gen_random(self):
365409

366410

367411
class ReverseCat(PuzzleGenerator):
412+
413+
tags = [Tags.trivial, Tags.strings]
414+
368415
@staticmethod
369416
def sat(s: str, substrings=["foo", "bar", "baz"]):
370417
"""
@@ -382,6 +429,9 @@ def gen_random(self):
382429

383430

384431
class EngineerNumbers(PuzzleGenerator):
432+
433+
tags = [Tags.trivial, Tags.strings]
434+
385435
@staticmethod
386436
def sat(ls: List[str], n=100, a='bar', b='foo'):
387437
"""
@@ -401,6 +451,9 @@ def gen_random(self):
401451

402452

403453
class PenultimateString(PuzzleGenerator):
454+
455+
tags = [Tags.trivial, Tags.strings]
456+
404457
@staticmethod
405458
def sat(s: str, strings=["cat", "dog", "bird", "fly", "moose"]):
406459
"""Find the alphabetically second to last last string in a list."""
@@ -417,6 +470,9 @@ def gen_random(self):
417470

418471

419472
class PenultimateRevString(PuzzleGenerator):
473+
474+
tags = [Tags.trivial, Tags.strings]
475+
420476
@staticmethod
421477
def sat(s: str, strings=["cat", "dog", "bird", "fly", "moose"]):
422478
"""Find the reversed version of the alphabetically second string in a list."""
@@ -433,6 +489,9 @@ def gen_random(self):
433489

434490

435491
class CenteredString(PuzzleGenerator):
492+
493+
tags = [Tags.trivial, Tags.strings]
494+
436495
@staticmethod
437496
def sat(s: str, target="foobarbazwow", length=6):
438497
"""Find a substring of the given length centered within the target string."""
@@ -449,6 +508,9 @@ def gen_random(self):
449508

450509

451510
class SubstrCount(PuzzleGenerator):
511+
512+
tags = [Tags.brute_force, Tags.strings]
513+
452514
@staticmethod
453515
def sat(substring: str, string="moooboooofasd", count=2):
454516
"""Find a substring with a certain count in a given string"""
@@ -478,6 +540,9 @@ def gen_random(self):
478540

479541

480542
class CompleteParens(PuzzleGenerator):
543+
544+
tags = []
545+
481546
@staticmethod
482547
def sat(t: str, s="))(Add)some))parens()to()(balance(()(()(me!)(((("):
483548
"""Add parentheses to the beginning and end of s to make all parentheses balanced"""

generators/chess.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Classic chess puzzles"""
22

3-
from puzzle_generator import PuzzleGenerator
3+
from puzzle_generator import PuzzleGenerator, Tags
44
from typing import List
55

66

@@ -18,6 +18,8 @@ class EightQueensOrFewer(PuzzleGenerator):
1818
Hint: a brute force approach works on this puzzle.
1919
"""
2020

21+
tags = [Tags.games, Tags.brute_force, Tags.famous]
22+
2123
@staticmethod
2224
def sat(squares: List[List[int]], m=8, n=8):
2325
"""Position min(m, n) <= 8 queens on an m x n chess board so that no pair is attacking each other."""
@@ -49,6 +51,8 @@ class MoreQueens(PuzzleGenerator):
4951
A brute force approach will not work on many of these problems.
5052
"""
5153

54+
tags = [Tags.games, Tags.graphs, Tags.famous]
55+
5256
@staticmethod
5357
def sat(squares: List[List[int]], m=9, n=9):
5458
"""
@@ -89,6 +93,8 @@ class KnightsTour(PuzzleGenerator):
8993
See Wikipedia entry on [Knight's tour](https://en.wikipedia.org/w/index.php?title=Knight%27s_tour)
9094
"""
9195

96+
tags = [Tags.games, Tags.graphs, Tags.hard, Tags.famous]
97+
9298
@staticmethod
9399
def sat(tour: List[List[int]], m=8, n=8):
94100
"""Find an (open) tour of knight moves on an m x n chess-board that visits each square once."""
@@ -140,6 +146,8 @@ class UncrossedKnightsPath(PuzzleGenerator):
140146
A more precise description is in this
141147
[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path)."""
142148

149+
tags = [Tags.games, Tags.hard, Tags.famous]
150+
143151
nxn_records = {3: 2, 4: 5, 5: 10, 6: 17, 7: 24, 8: 35, 9: 47, 10: 61, 11: 76, 12: 94, 13: 113, 14: 135, 15: 158,
144152
16: 183, 17: 211, 18: 238, 19: 268, 20: 302, 21: 337, 22: 375, 23: 414}
145153

@@ -192,6 +200,8 @@ class UNSOLVED_UncrossedKnightsPath(PuzzleGenerator):
192200
A more precise description is in this
193201
[Wikipedia article](https://en.wikipedia.org/w/index.php?title=Longest_uncrossed_knight%27s_path)."""
194202

203+
tags = [Tags.unsolved, Tags.games, Tags.famous]
204+
195205
unsolved_nxn_records = {10: 61, 11: 76, 12: 94, 13: 113, 14: 135, 15: 158,
196206
16: 183, 17: 211, 18: 238, 19: 268, 20: 302, 21: 337, 22: 375, 23: 414}
197207

generators/classic_puzzles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Classic puzzles"""
2+
# TODO: add tags
23

3-
from puzzle_generator import PuzzleGenerator
4+
from puzzle_generator import PuzzleGenerator, Tags
45
from typing import List
56

67

@@ -938,6 +939,7 @@ def sat(li: List[int], words=["SEND", "MORE", "MONEY"]):
938939

939940
@staticmethod
940941
def sol(words):
942+
print("solving", words)
941943
pi = list(range(10)) # permutation
942944
letters = []
943945
order = {}

generators/codeforces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Problems inspired by the popular programming competition site [codeforces.com](https://codeforces.com)"""
2+
# TODO: add tags
23

3-
from puzzle_generator import PuzzleGenerator
4+
from puzzle_generator import PuzzleGenerator, Tags
45
from typing import List
56

67

0 commit comments

Comments
 (0)