diff --git a/0x0A-primegame/0-prime_game.py b/0x0A-primegame/0-prime_game.py new file mode 100755 index 0000000..e69de29 diff --git a/0x0A-primegame/README.md b/0x0A-primegame/README.md new file mode 100644 index 0000000..394b228 --- /dev/null +++ b/0x0A-primegame/README.md @@ -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). \ No newline at end of file diff --git a/README.md b/README.md index 5ca1c24..d6cf335 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ This project focuses on implementing a function `rotate_2d_matrix(matrix)` that This project focuses on implementing a function `island_perimeter(grid)` that returns the perimeter of the island described in `grid`. +### Prime Game + +This project focuses on implementing a function `isWinner(x, nums)` that determines who the winner of each game is. + ## Usage To use any project in this repository, follow the instructions provided in each respective directory.