Skip to content

Commit

Permalink
initial project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagidza committed Sep 5, 2023
1 parent f124c4c commit f83d1d2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Empty file added 0x0A-primegame/0-prime_game.py
Empty file.
67 changes: 67 additions & 0 deletions 0x0A-primegame/README.md
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).
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f83d1d2

Please sign in to comment.