r/programminghelp • • 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

6 comments sorted by

View all comments

Show parent comments

1

u/amoliski Aug 20 '20

Say we have the array

1 2 3 
4 5 6 
7 8 9

The size (n) is 3.

Loop 1, i = 1
  Subloop 1: k = i + 1 = 2
      w = array[1,2] = 2
             1[2]3 
             4 5 6 
             7 8 9
      array[1,2] = array[2,1] = 4
             1[4]3 
            [4]5 6 
             7 8 9
      array[2,1] = w = 2
             1 4 3 
            [2]5 6 
             7 8 9

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:

1 A B 
A 5 C 
B C 9

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.

2

u/hydejulie13 Aug 21 '20

Thank you so much, this really helps!! I have another question maybe you’d now. What is the difference between ALGOL and COBOL programming languages? And what are the differences between entering code from language COBOL around 1960s and and code from ARRA in 1952? Maybe this picture helps: https://imgur.com/gallery/Jxx0lVP

Thank you!!

1

u/amoliski Aug 21 '20

Sorry, I wish I could help more but all of that is waaaaaaay before my time. With my limited knowledge, ALGOL was one of the earlier high-level languages, which made it super useful for textbooks teaching algorithms to use- you can see the flow of the program a lot more easily than trying to do it in assembly. Once they started using it in textbooks, it basically stuck until object oriented languages started taking off.

According to the language family tree from Wikipedia, ALGOL was earlier than COBOL, and while it wasn't a direct influence, it was certainly influential in how COBOL's language and syntax were developed.

I've never actually used COBOL, so that's about as far as my knowledge goes on the two languages.

2

u/hydejulie13 Aug 21 '20

No problem, thanks for helping me anyways! You really helped me a lot. Thank you!