Skip to content

Commit 40d250b

Browse files
committed
Updated README.md
1 parent 72d2137 commit 40d250b

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

README.md

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# 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)
32

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+
77

88
## What is a python programming puzzle?
99

@@ -13,40 +13,53 @@ This is called *satisfying* the puzzle, and that is why the puzzles are all name
1313

1414
```python
1515
def sat(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+
def sat(s: str):
24+
"""find a string with 1000 o's but no consecutive o's."""
25+
return s.count("o") == 1000 and s.count("oo") == 0
1726
```
1827

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+
def sat(x: List[int], s="Dynamic programming solves this classic job-interview puzzle!!!"):
35+
"""Find the indexes (possibly negative!) of the longest monotonic subsequence"""
36+
return all(s[x[i]] <= s[x[i+1]] and x[i+1] > x[i] for i in range(25))
37+
```
2038

39+
The classic [Towers of Hanoi](https://en.wikipedia.org/wiki/Tower_of_Hanoi) puzzle can be written as follows:
2140
```python
22-
def sat(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+
def sat(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+
return all(t[j].append(t[i].pop()) or t[j][-1] == min(t[j]) for i, j in moves) and t[0] == t[1]
2845

2946
```
3047

31-
## Puzzle sources
48+
# [Click here to browse the puzzles](/problems/README.md)
3249

33-
The problems in this repo draw inspiration from:
50+
The problems in this repo are based on:
3451
* Wikipedia articles about [algorithms](https://en.wikipedia.org/wiki/List_of_algorithms), [puzzles](https://en.wikipedia.org/wiki/Category:Logic_puzzles),
3552
and [math problems](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics).
3653
* 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).
3955

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
4458
* Classic puzzles like:
4559
* Towers of Hanoi
4660
* Verbal Arithmetic (solve digit-substitutions like SEND + MORE = MONEY)
4761
* 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)
5063
* Two-player games
5164
* Finding optimal strategies for Tic-Tac-Toe, Rock-Paper-Scissors, Mastermind (to add: connect four?)
5265
* Finding minimax strategies for zero-sum bimatrix games, which is equivalent to linear programming
@@ -66,11 +79,9 @@ and [math problems](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_m
6679
* Factoring numbers (easy for small factors, over $100k in prizes have been awarded and **open**
6780
for large numbers)
6881
* Discrete log (again **open** in general, easy for some)
69-
* (to add, bitcoin mining?)
7082
* Lattices
7183
* Learning parity (typically solved using Gaussian elimination)
7284
* Learning parity with noise (**open**)
73-
* (to add: random SAT?)
7485
* Compression
7586
* Compress a given string given the decompression algorithm (but not the compression algorithm), or decompress a given
7687
compressed string given only the compression algorithm
@@ -82,7 +93,12 @@ and [math problems](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_m
8293

8394
## Contributing
8495

85-
This project welcomes contributions and suggestions. Most contributions require you to agree to a
96+
This project welcomes contributions and suggestions. Use your creativity to help teach
97+
AI's to program! To allow for solutions
98+
in multiple languages, the answer to a puzzle has to be a single input that is a basic type
99+
such as `str`, `int`, `float`, `bool`, or a `List` or `Set` (or list of lists, etc.) of them.
100+
101+
Most contributions require you to agree to a
86102
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
87103
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
88104

0 commit comments

Comments
 (0)