Java, 610
class X{int n,c=0,t=0;public void static main(String[]a){n=Integer.parseInt(a[0]);String s,b,f,k,m,u;b="5L";s="3L";k="tank";u="Fill %s jug\n5L: %d, 3L: %d, T: %d";m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";f=u+m;for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);while(n!=0){if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t)}z("Volume measured out in %d turns",0,0,c)}void z(String s,int o,int w,Object...a){c+=o;n-=w;System.out.println(String.format(s,a))}}
Sumedh'in çözümünü aldım ve golf oynadım. Yorumlara koymak istedim ama itibarım yeterli değil :(.% 40 daha az, en azından paylaşılması gerektiğini düşünüyorum.
İşte ungolfed:
class X{
int n,c=0,t=0;
public void static main(String[] a){
n=Integer.parseInt(a[0]);
String s,b,f,k,m,u;
b="5L";
s="3L";
k="tank";
u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
f=u+m;
for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
while(n!=0)
{
if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
}
z("Volume measured out in %d turns",0,0,c);
}
void z(String s,int o, int w,Object... a){
c+=o;
n-=w;
System.out.println(String.format(s,a));
}
}
Not: sadece ilk çalıştırmada çalışır. Tekrar çalıştırın ve sonuç yanlış olacaktır (global bir değişken nedeniyle).
Aşağıdaki sürüm güvenlidir, ancak 610'dan 612'ye kadar 2 karakter kaybediyoruz:
class X{
int n,c,t;
public void static main(String[] a){
n=Integer.parseInt(a[0]);
String s,b,f,k,m,u;
t=c=0;
b="5L";
s="3L";
k="tank";
u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
f=u+m;
for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
while(n!=0)
{
if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
}
z("Volume measured out in %d turns",0,0,c);
}
void z(String s,int o, int w,Object... a){
c+=o;
n-=w;
System.out.println(String.format(s,a));
}
}
N = 69 için örnek çıktı:
Fill 5L jug
5L: 5, 3L: 0, T: 0
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
Fill 5L jug
5L: 5, 3L: 0, T: 5
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
Fill 5L jug
5L: 5, 3L: 0, T: 10
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 15
Fill 5L jug
5L: 5, 3L: 0, T: 15
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 20
Fill 5L jug
5L: 5, 3L: 0, T: 20
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 25
Fill 5L jug
5L: 5, 3L: 0, T: 25
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 30
Fill 5L jug
5L: 5, 3L: 0, T: 30
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 35
Fill 5L jug
5L: 5, 3L: 0, T: 35
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 40
Fill 5L jug
5L: 5, 3L: 0, T: 40
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 45
Fill 5L jug
5L: 5, 3L: 0, T: 45
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 50
Fill 5L jug
5L: 5, 3L: 0, T: 50
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 55
Fill 5L jug
5L: 5, 3L: 0, T: 55
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 60
Fill 5L jug
5L: 5, 3L: 0, T: 60
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 65
Fill 5L jug
5L: 5, 3L: 0, T: 65
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 65
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 67
Empty 3L jug
5L: 0, 3L: 0,T: 67
Fill 5L jug
5L: 5, 3L: 0, T: 67
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 67
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 69
Volume measured out in 33 turns