-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f124c4c
commit f83d1d2
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,67 @@ | ||
# Prime Game | ||
This project introduces the concept of algorithms and complexity. In this project, we will be playing a game of prime numbers. | ||
|
||
## Requirements | ||
[![Ubuntu](https://img.shields.io/badge/Ubuntu-14.04_LTS-orange)](https://www.ubuntu.com/download/desktop) | ||
[![Python](https://img.shields.io/badge/Python-3.4.3-blue)](https://www.python.org/downloads/release/python-343/) | ||
[![Style](https://img.shields.io/badge/Style-Pep8-lightgrey)](https://www.python.org/dev/peps/pep-0008/) | ||
|
||
## Tasks | ||
### 0. Prime Game | ||
Maria and Ben are playing a game. Given a set of consecutive integers starting from `1` up to and including `n`, they take turns choosing a prime number from the set and removing that number and its multiples from the set. The player that cannot make a move loses the game. | ||
|
||
They play `x` rounds of the game, where `n` may be different for each round. Assuming Maria always goes first and both players play optimally, determine who the winner of each game is. | ||
|
||
- Prototype: `def isWinner(x, nums)` | ||
- where `x` is the number of rounds and `nums` is an array of `n` | ||
- Return: name of the player that won the most rounds | ||
- If the winner cannot be determined, return `None` | ||
- You can assume `n` and `x` will not be larger than 10000 | ||
- You cannot import any packages in this task | ||
|
||
Example: | ||
|
||
- `x` = `3`, `nums` = `[4, 5, 1]` | ||
|
||
First round: `4` | ||
|
||
- Maria picks 2 and removes 2, 4, leaving 1, 3 | ||
- Ben picks 3 and removes 3, leaving 1 | ||
- Ben wins because there are no prime numbers left for Maria to choose | ||
|
||
Second round: `5` | ||
|
||
- Maria picks 2 and removes 2, 4, leaving 1, 3, 5 | ||
- Ben picks 3 and removes 3, leaving 1, 5 | ||
- Maria picks 5 and removes 5, leaving 1 | ||
- Maria wins because there are no prime numbers left for Ben to choose | ||
|
||
Third round: `1` | ||
|
||
- Ben wins because there are no prime numbers for Maria to choose | ||
|
||
**Result: Ben has the most wins** | ||
|
||
## Example Usage | ||
- Create a file called `0-main.py` | ||
- Copy the following code nto `0-main.py` (ensure your file is executable): | ||
```python | ||
#!/usr/bin/python3 | ||
|
||
isWinner = __import__('0-prime_game').isWinner | ||
|
||
|
||
print("Winner: {}".format(isWinner(5, [2, 5, 1, 4, 3]))) | ||
|
||
``` | ||
- Run the file from your terminal: | ||
```bash | ||
./0-main.py | ||
``` | ||
- If your output looks like this, then you are on the right track! | ||
```bash | ||
Winner: Ben | ||
``` | ||
|
||
## License | ||
This project is licensed under the [MIT License](../LICENSE). |
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