JSFiddle - React, Tailwind, and code Playground
by Sam88
JavaScript
n=["3L jug","5L jug","tank"];l=[0,0,0];t=[3,5,0];h=0;c=console;function x(j){l[j]=t[j];c.log(++h+") Fill "+n[j]);r();}function y(j){l[j]=0;c.log(++h+") Empty "+n[j]);r()}function w(j,k){s=l[j],f=l[k];b=(s+f)>t[k];l[k]=b?t[k]:f+s;l[j]=b?s-(t[k]-f):0;c.log(++h+") Pour from "+n[j]+" into "+n[k]);r()}function r(){c.log("5L: "+l[1]+", 3L: "+l[0]+", T: "+l[2])}function z(j){x(j);w(j,2)}a=prompt();t[2]=a;while(a>4){z(1);a-=5}if(a>2){z(0);a-=3}if(a>1){x(1);w(1,0);w(1,2);a=0}if(a>0){x(0);w(0,1);x(0);w(0,1);w(0,2)}c.log("Volume measured out in "+h+" turns");