You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-25Lines changed: 41 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# Python Programming Puzzles
2
-
# (Name Approvers: We would like to rename the repo to Python Programming Puzzles but we can keep it at Python Reasoning Challenges if you prefer)
3
2
4
-
5
-
6
-
This repo contains a dataset of python reasoning challenges which can be used to teach an AI python and evaluate an AI's ability to understand and write python programs.
3
+
This repo contains a dataset of python programming puzzles which can be used to teach and evaluate
4
+
an AI's programming proficiency. The dataset is comprehensive in terms of problem difficult, domain,
5
+
and algorithmic tools needed to solve the problems.
6
+
7
7
8
8
## What is a python programming puzzle?
9
9
@@ -13,40 +13,53 @@ This is called *satisfying* the puzzle, and that is why the puzzles are all name
13
13
14
14
```python
15
15
defsat(s: str):
16
-
return s +"world"=="Hello world"
16
+
return"Hello "+ s =="Hello world"
17
+
```
18
+
19
+
The answer to the above puzzle is the string `"world"` because `sat("world")` returns `True`. The puzzles range from trivial problems like this, to classic puzzles,
20
+
to programming competition problems, all the way through open problems in algorithms and mathematics.
21
+
A slightly harder example is:
22
+
```python
23
+
defsat(s: str):
24
+
"""find a string with 1000 o's but no consecutive o's."""
25
+
return s.count("o") ==1000and s.count("oo") ==0
17
26
```
18
27
19
-
The answer to the above puzzle is the string `"Hello "` because `sat("Hell ")` returns `True`. The puzzles range from trivial problems like this, to classic puzzles, to algorithms problems and problems from the [International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) and open problems in mathematics. For instance, the classic [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle can be written as follows:
28
+
A more challenging puzzle that requires [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) is the
29
+
[longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) problem
30
+
which we can also describe with strings:
31
+
```python
32
+
from typing import List
33
+
34
+
defsat(x: List[int], s="Dynamic programming solves this classic job-interview puzzle!!!"):
35
+
"""Find the indexes (possibly negative!) of the longest monotonic subsequence"""
36
+
returnall(s[x[i]] <= s[x[i+1]] and x[i+1] > x[i] for i inrange(25))
37
+
```
20
38
39
+
The classic [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle can be written as follows:
21
40
```python
22
-
defsat(moves: List[List[int]], num_disks=8): # moves is list of [from, to] pairs
23
-
state = (list(range(num_disks)), [], [])
24
-
for [i, j] in moves:
25
-
state[j].append(state[i].pop())
26
-
assert state[j] ==sorted(state[j]), "larger disk on top of smaller disk"
27
-
return state[0] == state[1] == []
41
+
defsat(moves: List[List[int]]):
42
+
"""moves is list of [from, to] pairs"""
43
+
t = ([8, 7, 6, 5, 4, 3, 2, 1], [], []) # towers state
44
+
returnall(t[j].append(t[i].pop()) or t[j][-1] ==min(t[j]) for i, j in moves) and t[0] == t[1]
28
45
29
46
```
30
47
31
-
## Puzzle sources
48
+
#[Click here to browse the puzzles](/problems/README.md)
32
49
33
-
The problems in this repo draw inspiration from:
50
+
The problems in this repo are based on:
34
51
* Wikipedia articles about [algorithms](https://en.wikipedia.org/wiki/List_of_algorithms), [puzzles](https://en.wikipedia.org/wiki/Category:Logic_puzzles),
35
52
and [math problems](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics).
36
53
* The website [codeforces.com](https://codeforces.com), a popular website for programming competition problems
37
-
* The [International Collegiate Programming Contest](https://icpc.global) (ICPC)
38
-
* The [International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad) (IMO)
54
+
* Olympiad problems from the [International Collegiate Programming Contest](https://icpc.global) and [International Mathematical Olympiad](https://en.wikipedia.org/wiki/International_Mathematical_Olympiad).
39
55
40
-
# [Click here to browse the puzzles](/problems/README.md)
41
-
42
-
## Summary of the dataset
43
-
* Numerous trivial puzzles like `hello world` and reversing a list, useful for learning to program
56
+
## Highlights
57
+
* Numerous trivial puzzles like reversing a list, useful for learning to program
44
58
* Classic puzzles like:
45
59
* Towers of Hanoi
46
60
* Verbal Arithmetic (solve digit-substitutions like SEND + MORE = MONEY)
47
61
* The Game of Life (e.g., finding oscillators of a given period, some **open**)
48
-
* Chess puzzles (e.g., knight's tour and n-queen problem variants)
49
-
* (to add: Sliding puzzles, Sudoku?)
62
+
* Chess puzzles (e.g., knight's tour and n-queen problem variants)
0 commit comments