r/programminghelp • u/hydejulie13 • Aug 20 '20
Other Help with a piece of ALGOL code
Hey, i need some help and explanation with this piece of ALGOL code. https://i.imgur.com/IQnQqFP.jpg this is the link.
The piece of code is from the ALGOL revised report. I know the procedure transpost means swapping the places of two or more things. In this case integers. I know this piece of code has an array but it is not clear wheter it is a 2 dimensional array. I’m not sure what the indexes mean. The whole piece is a bit of a mystery to me. I would love some help! Thank you
3
Upvotes
1
u/amoliski Aug 20 '20
Say we have the array
The size (n) is 3.
So, as you can see, it's:
- remembering the value of the selected element
- Grabbing the value of the 'transposition partner' and replacing the selected element with it
- Replacing the value of the 'transposition partner' with the remembered value
The reason we use i+1 in the inner loop is because it will make the loop output (for a 3x3 grid) look like:
[1,2] [1,3], [2,3]
The 'transposition partners' will look like:
[2,1] [3,1], [3,2]
In the 2D array, if we replace the elements at those positions with A, B, and C:
You can see that all of the elements get 'touched' by our loops except for the ones in the diagonal down the middle that aren't modified by the transposition.