| |
|
|
p.specht
| inspired of "Simon-says"-puzzel from the film "Stirb langsam", supply that nachstehende Program possible Umleer-Abfolgen to Erzielung bestimmter Zielmengen - though not always The kürzeste Variante: turn one the two Gefäßkapazitäten circa, yield itself often kürzere ways to that success.
Info: only if a the Gefäßkapazitäten a Primzahl is, or the two mental capacity "relativ prim" zueinander are (GgT=1), go (in both directions) guaranteeing any at all possible Results supplied.
so can too The undertow. two-Sanduhren-puzzel solve. in the Program becomes then determined, How one whom missing Restwert on Time produce can.
Window Title "Umleer-puzzel for 2 box lösen"
declare Ziel&, LMax&,RMax&,L&,R&,n&,kann&,ist&
Beginn:
CLS:Font 2:Print " target = ";:Input Ziel&
' Ziel&=2
LMax&=7
RMax&=11
Case Ziel&<0:ziel&=abs(ziel&)
Ziel&=Ziel& mod if(LMax&>RMax&,LMax&,RMax&)
n&=0:L&=0:R&=0
Repeat
'If target access:
if (LMax&=Ziel&) or (RMax&=Ziel&):inc n&:break:endif
if (L&=Ziel&) or (R&=Ziel&):show:break:endif
'If something there's to that transport and no capacity spare is: make spare!
if (L&>0) and (R&=RMax&):R&=0:inc n&: show :Endif
'If nothing more there's to that transport, schöpfe new!
if (L&=0):L&=LMax&:inc n&: show :endif
'If something there's to that transport and yet capacity spare is: vain circa!
if (L&>0) and (R&<RMax&): Umleeren :inc n&: show :Endif
Until (L&=Ziel&) or (R&=Ziel&)
print " ";n&;" steps."
Waitinput
Goto "Beginn"
Proc Umleeren
kann&=RMax&-R& : ist&=if(kann&<L&,kann&,L&)
L&=L&-ist& : R&=R&+ist&
Endproc
Proc show
print tab(3);n&;". ";tab(12);L&,tab(20);R&
if %csrlin>20:waitinput 2000:cls:endif
Endproc
END
|
|
|
| Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/30/21 ▲ |
|
|
|