Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions rock_paper_scissors/.ipynb_checkpoints/README-checkpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rock Paper Scissors

Write a function `rock_paper_scissors` to generate all of the possible plays that can be made in a game of "Rock Paper Scissors", given some input `n`, which represents the number of plays per round.

For example, given n = 2, your function should output the following:

```python
[['rock', 'rock'], ['rock', 'paper'], ['rock', 'scissors'], ['paper', 'rock'], ['paper', 'paper'], ['paper', 'scissors'], ['scissors', 'rock'], ['scissors', 'paper'], ['scissors', 'scissors']]
```

Your output should be a list of lists containing strings. Each inner list should have length equal to the input n.

## Testing

Run the test file by executing `python test_rps.py`.

You can also test your implementation manually by executing `python rps.py [n]`.

## Hints

* You'll want to define a list with all of the possible Rock Paper Scissors plays.
* Another problem that asks you to generate a bunch of permutations, so we're probably going to want to opt for using recursion again. Since we're building up a list of results, we'll have to pass the list we're constructing around to multiple recursive calls so that each recursive call can add to the overall result. However, the tests only give our function `n` as input. To get around this, we could define an inner recursive helper function that will perform the recursion for us, while allowing us to preserve the outer function's function signature.
* In Python, you can concatenate two lists with the `+` operator. However, you'll want to make sure that both operands are lists!
* If you opt to define an inner recursive helper function, don't forget to make an initial call to the recursive helper function to kick off the recursion.
24 changes: 24 additions & 0 deletions rock_paper_scissors/.ipynb_checkpoints/rps-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python

import sys

def rock_paper_scissors(n):
options = ['rock', 'paper', 'scissors']
perms = []
def inner_rps(rounds_left, result=[]):
if (rounds_left == 0):
perms.append(result)
return
for i in options:
inner_rps(rounds_left - 1, result + [i])
inner_rps(n, result=[])
return perms



if __name__ == "__main__":
if len(sys.argv) > 1:
num_plays = int(sys.argv[1])
print(rock_paper_scissors(num_plays))
else:
print('Usage: rps.py [num_plays]')
12 changes: 11 additions & 1 deletion rock_paper_scissors/rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
import sys

def rock_paper_scissors(n):
pass
options = ['rock', 'paper', 'scissors']
perms = []
def inner_rps(rounds_left, result=[]):
if (rounds_left == 0):
perms.append(result)
return
for i in options:
inner_rps(rounds_left - 1, result + [i])
inner_rps(n, result=[])
return perms



if __name__ == "__main__":
Expand Down
15 changes: 15 additions & 0 deletions stock_prices/.ipynb_checkpoints/stock_prices-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python

import argparse

def find_max_profit(prices):
pass


if __name__ == '__main__':
# This is just some code to accept inputs from the command line
parser = argparse.ArgumentParser(description='Find max profit from prices.')
parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer price')
args = parser.parse_args()

print("A profit of ${profit} can be made from the stock prices {prices}.".format(profit=find_max_profit(args.integers), prices=args.integers))
2 changes: 1 addition & 1 deletion stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python.

import argparse

Expand Down