From 1c7ed78e2e4c94b883477e16bc03f9da9211ccb8 Mon Sep 17 00:00:00 2001 From: Hot Stuff Date: Wed, 15 Apr 2020 13:03:03 -0700 Subject: [PATCH 1/2] started assignment --- .../.ipynb_checkpoints/stock_prices-checkpoint.py | 15 +++++++++++++++ stock_prices/stock_prices.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 stock_prices/.ipynb_checkpoints/stock_prices-checkpoint.py diff --git a/stock_prices/.ipynb_checkpoints/stock_prices-checkpoint.py b/stock_prices/.ipynb_checkpoints/stock_prices-checkpoint.py new file mode 100644 index 000000000..9de20bc94 --- /dev/null +++ b/stock_prices/.ipynb_checkpoints/stock_prices-checkpoint.py @@ -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)) \ No newline at end of file diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..632f7dbd2 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python. import argparse From b62899c82f6a83c219efdc4d029878d13c0a8c13 Mon Sep 17 00:00:00 2001 From: Hot Stuff Date: Thu, 16 Apr 2020 15:36:33 -0700 Subject: [PATCH 2/2] assignment done --- .../.ipynb_checkpoints/README-checkpoint.md | 24 +++++++++++++++++++ .../.ipynb_checkpoints/rps-checkpoint.py | 24 +++++++++++++++++++ rock_paper_scissors/rps.py | 12 +++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 rock_paper_scissors/.ipynb_checkpoints/README-checkpoint.md create mode 100644 rock_paper_scissors/.ipynb_checkpoints/rps-checkpoint.py diff --git a/rock_paper_scissors/.ipynb_checkpoints/README-checkpoint.md b/rock_paper_scissors/.ipynb_checkpoints/README-checkpoint.md new file mode 100644 index 000000000..5104b9fd2 --- /dev/null +++ b/rock_paper_scissors/.ipynb_checkpoints/README-checkpoint.md @@ -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. \ No newline at end of file diff --git a/rock_paper_scissors/.ipynb_checkpoints/rps-checkpoint.py b/rock_paper_scissors/.ipynb_checkpoints/rps-checkpoint.py new file mode 100644 index 000000000..5049355a0 --- /dev/null +++ b/rock_paper_scissors/.ipynb_checkpoints/rps-checkpoint.py @@ -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]') \ No newline at end of file diff --git a/rock_paper_scissors/rps.py b/rock_paper_scissors/rps.py index 0fc53356e..5049355a0 100644 --- a/rock_paper_scissors/rps.py +++ b/rock_paper_scissors/rps.py @@ -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__":