The calculation of the values within the Pascal trianlge, that is, the placing of the cloverleafs by Kara, is quite simple: Kara calculates the Pascal trianlge line by line, from left to right. When Kara reaches the end of a line, marked by a tree, he walks back to the beginning of the next row in the state "next row".


How can Kara calculate the value of a single field within the Pascal triangle? Kara uses the sensor "leaf on the ground?" to determine whether he stands on a field with a cloverleaf or on a field without a cloverleaf (field b in the above image). He now only needs to know if there is cloverleaf on the field to the right behind him (field a in the above image; the circled fields in the two images to the right) or not. Kara saves this information using two states:

If Kara is in the state "carry0" and on a field with a cloverleaf, the field to the right of Kara must stay empty, and Kara simply takes a step forward. If there is a cloverleaf on Karas field, the result for the field to his right is an odd number. Kara lays down a cloverleaf on the field to the right and then take a step forward. The state "carry1" works in the same manner. The following image shows the whole program: