-
Notifications
You must be signed in to change notification settings - Fork 0
Algorithms project submission #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4e1a90f
4706b18
50462ba
52a444a
6f85024
99e0e41
8c07c01
f2a77aa
9c9da48
c47a5f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,13 @@ | |
| import math | ||
|
|
||
| def recipe_batches(recipe, ingredients): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work completing the recipe batches exercises! Here is my solution for the recipe batches problem: |
||
| pass | ||
|
|
||
| min_batch_values = [] | ||
| if set(recipe.keys()).issubset(set(ingredients.keys())): | ||
| for ingredient in ingredients: | ||
| min_batch_values.append(ingredients[ingredient]//recipe[ingredient]) | ||
| else: | ||
| return 0 | ||
| return min(min_batch_values) | ||
|
|
||
| if __name__ == '__main__': | ||
| # Change the entries of these dictionaries to test | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,18 @@ | |
| import sys | ||
|
|
||
| def rock_paper_scissors(n): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work completing the rock, paper, and scissors exercise! Here is my solution: |
||
| pass | ||
|
|
||
| final_list = [] | ||
| options = [['rock'],['paper'],['scissors']] | ||
| if n == 0: | ||
| return [[]] | ||
| else: | ||
| previous_plays = rock_paper_scissors(n - 1) | ||
| for previous_play in previous_plays: | ||
| for option in options: | ||
| final_list.append(previous_play + option) | ||
| return final_list | ||
|
|
||
| print(rock_paper_scissors(2)) | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) > 1: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,19 @@ | |
| import argparse | ||
|
|
||
| def find_max_profit(prices): | ||
| pass | ||
|
|
||
| # sort prices to find difference between highest and lowest price | ||
| sorted_prices = sorted(prices) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the instructions, no sorting is allowed for this problem. |
||
| max_profit_so_far = sorted_prices[0] - sorted_prices[-1] | ||
| # find buy price | ||
| for i in range(len(prices)): | ||
| current_min_price_so_far = prices[i] | ||
| # find max profit by looping through each sell price in the array and subtract buy price from the sell price | ||
| for j in range(i + 1, len(prices)): | ||
| profit = prices[j] - current_min_price_so_far | ||
| # if profit is greater than current max profit, then update max profit value | ||
| if profit > max_profit_so_far: | ||
| max_profit_so_far = profit | ||
| return max_profit_so_far | ||
|
|
||
| if __name__ == '__main__': | ||
| # This is just some code to accept inputs from the command line | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work completing the making change exercise! Here is my solution: