Water-Bucket problem This challenge is to calculate how to measure 4 liters of water with just two unevenly sized buckets, one of 3 liters and another of 5 liters, in minimum number of steps. To extend and generalize this, write a program to evaluate the minimum number of steps to measure “X” liters of water, with “Y” buckets each having a separate denomination.  

Assumptions: 


Each bucket used for measuring water should be unique in denomination and the number of buckets will be &lt;= 3 
The target amount to be reached has to finally reside in a single bucket (at the end of the measuring activity). 
The bucket capacities and target amount will be &lt;= 99 
If there are multiple ways to measure the same amount, only one single way, having the minimum number of steps is required. 
Ties will be broken by the smallest program.


Examples:  


  2,3,5,4
  Implies that there are 2 buckets of capacity 3 and 5 each and the target amount desired is 4.
  
  3,4,6,9,7
  Implies that there are 3 buckets of capacity 4, 6 and 9 each and the target amount desired is 7.


Answers:  


  2,3,5,4
  Fill 5
  Move 5 to 3
  Empty 3
  Move 5 to 3
  Fill 5
  Move 5 to 3  
  
  3,4,6,9,7
  Fill 4
  Move 4 to 6
  Fill 9
  Move 9 to 6
Python, 363 chars

Golfed it, not sure if it is golf or not.  The map P maps a reachable state to the instructions used to get to that state.  Keeps enumerating reachable states until it finds one with the target amount of water in it.

I=input()
B=I[1:-1]
R=range(I[0])
P={(0,)*I[0]:""}
while P:
 Q={}
 for s in P:
  if I[-1]in s:print P[s];P=Q={};break
  for i in R:
   Q[s[:i]+(0,)+s[i+1:]]=P[s]+"Empty %d "%B[i];Q[s[:i]+(B[i],)+s[i+1:]]=P[s]+"Fill %d "%B[i]
   for d in R:m=min(s[i],B[d]-s[d]);Q[tuple(s[j]-[0,m][j==i]+[0,m][j==d]for j in R)]=P[s]+"Move %d to\
 %d "%(B[i],B[d])
 Q.update(P);P=Q