4 2 -1 -1 3 1 -1
"Peg %d : %d to %d", peg, fromTower, toTower
Tower number 0 : Tower number 1 : 3 2 1 Tower number 2 : Peg 1 : 1 to 0 Peg 2 : 1 to 2 Peg 1 : 0 to 2 Peg 3 : 1 to 0 Peg 1 : 2 to 1 Peg 2 : 2 to 0 Peg 1 : 1 to 0 Tower number 0 : 3 2 1 Tower number 1 : Tower number 2 :
Grading: The submission with the least number of moves (moves_min) is found. If moves_min is smaller than 4000 the following grading will be applied to all students with less than 4076 moves:
score = (1 + (4076 - your_moves) / (4076 - moves_min)) * 100
So the student with the best score gets 100% bonus points.
Formula for students with more than 4076 moves (should not happen if you implement the algorithm below):
score = max(0, (8152 - your_moves) / 4076 )
The key to getting less than 4076 moves is a better algorithm - not better assembler programming!
movePegs(fromTower, toTower, unusedTower, numberOfPegs) if numberOfPegs == 1 move one peg from 'fromTower' to 'toTower' else movePegs(fromTower, unusedTower, toTower, numberOfPegs-1) // move all pegs except the lowest to the side movePegs(fromTower, toTower, unusedTower, 1) // move lowest of our pegs to the goal movePegs(unusedTower, toTower, fromTower, numberOfPegs-1) // move all those pegs to the goal
while not finished: find tower having peg 1 on top count how many consecutive pegs are on that tower starting from the top (e.g. 7 5 3 2 1 => 3 ) find the tower that has the next peg on top (e.g. 3 from above - find tower with 4 on top) movePegs(towerWithOne, towerWithNextPeg, unusedTower, numberOfConsecutivePegsOnOne)So basically this algorithm looks for the tower with peg 1 and then moves all pegs that are consecutive below 1 to the tower with the next peg. Thus afterwards the size of your consecutive stack will have grown by (at least) one. If you finish this algorithm and do not end up at tower 0 you have to move your stack to tower 0.