«« «» »» |
The solutionFit the motors with a gas tank.The fuel
The reasoningPer segment 13 liters are used, over 30 segments: 30 * 13 liters.30 * 13 = 13 * 30. How many times do we need to refuel? Right, 13 times. And how many steps were we supposed to make? ... So here's the solution:If we run out of fuel in a segment, do a refuel and perform PLOP. The other (17) segments are PILI. Now remove those fuel tanks and just remember the reasoning, because that's what we'll use in the following code.The Forth codeForth file: ec207.frt \ ROBOT ARM (Albert Nijhof) FORTH DEFINITIONS DECIMAL : VARIABLES CREATE ( n -- ) CELLS ALLOT DOES> ( index body -- addres ) SWAP CELLS + ; 5 DUP CONSTANT #MOTORS DUP VARIABLES WHERE \ List of motor positions DUP VARIABLES THERE \ List of target positions DUP VARIABLES STEP \ -1 or +1 (directions) DUP VARIABLES TANK \ Amount of fuel DUP VARIABLES USAGE \ Amount of fuel used per segment CELLS 0 WHERE SWAP 0 FILL 20 VALUE WAIT \ Physical motor limitation 0 VALUE #SEGMENTS \ Longest segment : TARGET ( m0 m1 m2 m3 m4 -- ) \ Set target #MOTORS BEGIN 1- TUCK THERE ! ?DUP 0= UNTIL ; |