Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the purposes of this assignment, we will be representing each state as a list of two ints. Please also maintain a separate list of

image text in transcribed

For the purposes of this assignment, we will be representing each state as a list of two ints. Please also maintain a separate list of two ints with the respective capacities of the jugs. There are three operations you can perform on a jug: Fill jug to capacity from faucet Empty jug onto ground Pour into another jug until that jug is full or this jug is empty For this component of implementation, please implement four (4) Python functions: 1. fill(state, max, which) - return a copy of state which fills the jug corresponding to the index in which (0 or 1) to its maximum capacity. Do not modify state 2. empty(state, max, which) - return a copy of state which empties the jug corresponding to the index in which (0 or 1). Do not modify state 3. xfer(state, max, source, dest) - return a copy of state which pours the contents of the jug at index source into the jug at index dest), until source is empty or dest is full. Do not modify state. 4. succ(state, max) - display the list of unique successor states of the current state in any order. Each of these functions should take as an argument the current state of the two water jugs as a list of two ints, as well as the maximum capacities of each jug as a list of two ints. These functions should work as follows (though be sure to test them more thoroughly yourself): >>> max = [5,7] >>> so = [0,0] >>> fill(s0,max, 1) => [0,7] >>> 50 => [0,0] >>> sl = fill(s0,max, 1) >>> xfer(s1, max, 1,0) => [5,2] >>> succ(50,max) [0,0] [5,] [0,7] You may assume our states and capacities will be valid, non-negative integers presented in a valid, two-element list, and indexes will be valid. Error-check if you want the practice. but it will not be part of your Be sure to test your functions with capacities other than 5 and 7! We will :)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions