public class Main {
private static final int RESULT = 4;
private static Bucket a = new Bucket("A", 0, 8);
private static Bucket b = new Bucket("B", 5, 5);
private static Bucket c = new Bucket("C", 3, 3);
public static void recurse(Bucket a, Bucket b, Bucket c) {
moveWaterFromXtoY(c,b);
if (b.current == RESULT){
print();
System.exit(0);
}
if (b.capacity == b.current){
moveWaterFromXtoY(b,a);
}else{
moveWaterFromXtoY(a,c);
}
recurse (a,b,c);
}
public static boolean moveWaterFromXtoY(Bucket X, Bucket Y) {
print();
// y is full.
if (Y.current == Y.capacity) {
return false;
}
if (X.current == 0) {
return false;
}
int totalWaterCanBeMoved= (Y.capacity-Y.current);
if (totalWaterCanBeMoved > X.current){
totalWaterCanBeMoved = X.current;
}
Y.current += totalWaterCanBeMoved;
X.current -=totalWaterCanBeMoved;
return true;
}
public static void main(String[] args) {
moveWaterFromXtoY(b,a);
moveWaterFromXtoY(c,a);
recurse(a, b, c);
}
public static void print(){
System.out.format("%2d %2d %2d\n", a.current, b.current , c.current);
}
}
class Bucket {
public int capacity;
public int current;
public String name;
public Bucket(String name, int current, int capacity) {
this.name = name;
this.current = current;
this.capacity = capacity;
}
public void print(){
System.out.println ("Bucket "+name + " has = " + current + " of " + capacity);
}
}
Monday, May 19, 2008
Tuesday, April 01, 2008
Pay less when eating out !!
www.DinnerBroker.com
www.OpenTable.com
www.Restaurant.com
www.Swapagift.com
www.OpenTable.com
www.Restaurant.com
www.Swapagift.com
Sunday, March 23, 2008
Sunday, March 02, 2008
Thursday, February 28, 2008
Tuesday, February 19, 2008
Tuesday, February 05, 2008
Saturday, January 19, 2008
Thursday, January 03, 2008
Thursday, December 27, 2007
USCIS Customer service combination
Dial: 1-800-375-5283
1
2
6
1
Enter Receipt Number
1 <Confirm>
USCIS Tells you the status of your case
3
1
In about 5 minutes you should hear voice of a real person.
P.S. : This is the combination to reach USCIS in case if you think that your application is out of 60 days since last update.
Thursday, December 20, 2007
Sunday, December 09, 2007
Tuesday, December 04, 2007
Saturday, December 01, 2007
open source softwares - favourites..
Personal
-----------------
Thunderbird
Eraser
VLC Media player
Media portal
GANTT
Art
-----------------
Gimp
blender
-----------------
Thunderbird
Eraser
VLC Media player
Media portal
GANTT
Art
-----------------
Gimp
blender
Wednesday, November 28, 2007
Tuesday, November 20, 2007
Friday, November 02, 2007
Subscribe to:
Posts (Atom)