Skip to main content

HOW TO CODE FOR ARTIFICIAL INTELLIGENCE ? | BLOG |





ARTIFICIAL INTELLIGENCE





The first problem is called 3-4 gallon water jug problem as described in the book by Elaine Rich. We begin with two empty jugs of the capacity of 3 and 4 gallons respectively. We have an infinite supply of water available and we want the 4-gallon jug to be filled with exactly 2 gallons of water.

Another problem is called 8-5-3 milk jug problem which begins with 8-gallon milk jug completely full while other two are empty. We want exactly 4 gallons of milk in the 8-gallon jug.
In either case, there are no other measuring devices available to us.

ANS:-

          I will answer the second problem here and I will give the code which you can run yourself and improve it if you want.

One solution to the second problem is

8-0-0, 3-5-0, 3-2-3, 6-2-0, 6-0-2, 1-5-2, 1-4-3, 4-4-0.

let us consider X-Y-Z as 8-5-3 jugs

The code is :-


#include<iostream>
using namespace std;

int main()
{
int limX = 8, limY = 5, limZ = 3;
int x = 8, y = 0, z = 0;
int a,b,c;
for(int i = 0; i < 2; i++)
{
// Minus water from x
if((x - (limY - y)) >= 0)
{
a = x - (x - (limY - y));
y += a; // Add Required water
x -= a;
}
else
{
y += x;
x = 0;
}

if((y - (limZ - z)) >= 0)
{
b = y - (y - (limZ - z));
z += b;
y -= b;
}
else
{
z += y;
y = 0;
}

if((z - (limX - x)) >= 0)
{
c = z - (z - (limX - x));
x += c;
z -= c;
}
else
{
x += z;
z = 0;
}
if(i>0)
{
break;
}
else
{

z = y;
y = 0;
}

}

cout<<x<<y<<z;
}





Comments

Popular posts from this blog

Rinku privacy policy

Privacy Policy krg built the Rinku app as a Free app. This SERVICE is provided by krg at no cost and is intended for use as is. This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at Rinku unless otherwise defined in this Privacy Policy. Information Collection and Use For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not

Privacy Policy For Bounce It game

  Privacy Policy Krishna Ghate built the Bounce It app as a Free app. This SERVICE is provided by Krishna Ghate at no cost and is intended for use as is. This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at Bounce It unless otherwise defined in this Privacy Policy. Information Collection and Use For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information, including but not limited to nothing. The i

RunandJump Privacy Policy

  Privacy Policy KRG built the RunandJump app as a Free app. This SERVICE is provided by KRG at no cost and is intended for use as is. This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible at RunandJump unless otherwise defined in this Privacy Policy. Information Collection and Use For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your devic