Arithmetic Dictionaries-Using a “pantry” and

+44 222 444 1122

Give us a call

11 Vancouver St, London

Get direction

Arithmetic Dictionaries-Using a “pantry” and

Need help on problem 2 & 3 in the images shown below, specifically for the functions “individually_feasible” and “simul_feasible_nr”. I’m stuck on how to do those problems.

5 attachments

Slide 1 of 5

  • Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png

attachment_1

attachment_1

Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png
Description: https://www.studypool.com/uploads/questions/773524/preview_20200501025306screenshot__16_.png
  • Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png

attachment_2

attachment_2

Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png
Description: https://www.studypool.com/uploads/questions/773524/preview_20200501025310screenshot__17_.png
  • Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png

attachment_3

attachment_3

Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png
Description: https://www.studypool.com/uploads/questions/773524/preview_20200501025313screenshot__18_.png
  • Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png

attachment_4

attachment_4

Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png
Description: https://www.studypool.com/uploads/questions/773524/preview_20200501025317screenshot__23_.png
  • Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png

attachment_5

attachment_5

Description: https://www.studypool.com/img/icons/open_in_full-24px-min.png
Description: https://www.studypool.com/uploads/questions/773524/preview_20200501025320screenshot__21_.png

UNFORMATTED ATTACHMENT PREVIEW

Testing Make sure to run the following cell to make sure that the Python testing framework, nose, is installed. (It’s required for the rest of the notebook to work.) [22] try: from nose.tools import assert_equal, assert_almost_equal from nose. tools import assert_true, assert_false from nose. tools import assert_not_equal, assert_greater_equal except: !pip install nose from nose. tools import assert_equal, assert_almost_equal from nose.tools import assert_true, assert_false from nose. tools import assert_not_equal, assert_greater_equal [23] class AD (dict): def init__(self, *args, **kwargs): “” “This initializer simply passes all arguments to dict, so that we can create an AD with the same ease with which we can create a dict. There is no need, indeed, to repeat the initializer, but we leave it here in case we want to create attributes specific to an AD later.” super(). _init_(*args, **kwargs) def _add_(self, other): return AD._binary op(self, other, lambda x, y: x + y, 0) def_sub_(self, other): return AD._binary_op(self, other, lambda x, y: x – y, 0) r = @staticmethod def _binary op(left, right, op, neutral): AD) 1_keys = set(left.keys()) if isinstance(left, dict) else set() r_keys = set(right.keys()) if isinstance(right, dict) else set() for k in 1_keys | r_keys: # If the right (or left) element is a dictionary (or an AD), # we get the elements from the dictionary; else we use the right # or left value itself. This implements a sort of dictionary # broadcasting 1_val = left.get(k, neutral) if isinstance(left, dict) else left r_val = right.get(k, neutral) if isinstance(right, dict) else right r[k] = op(1_val, r_val) return r [49] class Pantry(AD): definit__(self, ingredients): “” “We initialize the Pantry class by passing the ingredients that were passed in to the initializer for the superclass, AD””” super(). _init_(ingredients) class Recipe: definit__(self, name, ingredients): “” “We initialize the Recipe class, which stores the name of a recipe as well as the needed ingredients in the form of an AD””” self.name = name self.ingredients = AD(ingredients) def _repr_(self): “””To have a better representation of the recipe” return f'{self.name}: {self.ingredients}’ def hash_(self): “””Allows us to use a Recipe object inside a set or as a dictionary key. We assume that each recipe will have a unique name, and therefore we can simply use the built-in hash function on the name and return it as the hash id.” return hash(self.name) def _eq_(self,other): “””For a recipe to equal another, their name and ingredients must match””” return self.name == other name and dict(self.ingredients) == dict(other.ingredients) Problem 2: Checking recipe feasibility It would also be nice to know which recipes we can make given the current contents of our pantry. Your next task is to implement a individually_feasible method for the Pantry class, which takes a list of recipes and returns a list of the recipes that can be mad individually using the ingredients in the pantry. For this problem, you do not need to worry about making multiple recipes at the same time. def individually_feasible(self, recipes): “””Returns a list of recipes that could be individually made using the ingredients in the pantry. Can be implemented in 9 lines of code.’ #YOUR CODE HERE Pantry.individually_feasible = individually_feasible Problem 3: Checking simultaneous recipe feasibility Similar to the previous problem, we want to know recipes we can make given the current contents of our pantry, but this time, for multiple recipes at once. For this problem, you will implement a simul_feasible_nr method for the Pantry class. This method takes a list of recipes and returns a list containing all of the different combinations of recipes that could be simultaneously made using the available ingredients in the pantry, without repeating any recipe in each combination. (The “nr” in the name stands for “non-repeating”.) simul_feasible_nr should return a list of lists. That is, the returned value should be a list, where each element in that list is itself a list representing a particular combination of recipes. Neither the order of the outer list nor the order of the inner list matters. A combination of recipes has a minimum of 1 recipe and has no maximum size, as long as the pantry has enough ingredients. Hints: • simul_feasible_nr may call the individually_feasible method defined above. • You may find it useful to define an inner function that calls itself recursively. [] def simul_feasible_nr(self, recipes): “””Returns a list containing different combinations of recipes that could be made simultaneously using the ingredients available in the pantry.” # YOUR CODE HERE raise NotImplementedError() Pantry.simul_feasible_nr = simul_feasible_nr If simul_feasible_nr is working correctly, then the below cell should print something like this:

Description: https://www.studypool.com/img/discuss/honorcode-new.png

User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.

Description: https://www.studypool.com/img/icons/no_answer.png

This question has not been answered.

Create a free account to get help with this and any other question!

VIEW ANSWER

24/7 Homework Help

Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!

POST QUESTION

Similar Content

Python Movie Genres Survey Program

Specification Age Group Consider only 4 groups as shown below Group Group name Age Elementary School Student…

CS 210 University of New Hampshire Programming Calculator Python Code Project

This urgent work won’t take you more than 1h. If you have ideas on that, you will solve it less than 1h. Please bid it kin…

Richland Community College Java Programming Code

Programming Assignment #5 Programming Fundamentals II – Fall 2021 Dallas College – Cedar Valley Campus Instructions W…

Massachusetts Institute of Technology Road Trip JAVA Programming Design Document

Java Programming. Design document and Road Trip Java ProgramI need the small design document in 1 day and code in about 2…

Java Console Program

I need to create a console program that prompts the user to enter the name and address of their employer and position they…

help with my iphone 4 please

so the other day my friend put all her music on my iphone 4 with her laptop and i want to put the rest of my music on my o…

H07

l o a d ( ” grap h s . s a g e ” ) n e i g h b o r s ( ghost , 6 )…

Arraylist.edited

In Java, an array list is a part of a collection that is contained in the java.util framework. It…

Complete The To Do Activities Create An Entity Relationship E R Diagram For The Scenario

Databases aid in navigation through institutional activities and data stored on all machines connected to its network. The…

OUR ORDER DATABASE

With over 10 years in the online academic market, we have accumulated thousands of previously completed questions and answers across the globe. You can gain access to them for a very small fee.

Want to complete your own work?