This is more of a math/programming question.
I'm trying to rewrite a certain legacy system we have that I don't have access to the source code. It's an OLD COBOL program (20+ years old) that calculates building information. The floor area of the building was specified in a weird way though.
For rectangular shapes, it was simple: 50x25 would naturally calculate to 1250 square feet. However, for irregular shapes it took in input in a strange fashion. You told it the up and down movements on how to draw the shape, and it then calculated the area. U for up, D for down, R for right, L for left, followed by a digit. So for example you could have:
U10R5D5R10U10R5D15L8U1L4D1L8
This draws a fairly odd shape. Now, by hand, finding the area of this thing is easy. I draw it out, it breaks down into 5 rectangles of different size, and I calculate the area of each and add them all together (the above example is 171 square feet). Problem is, for the life of me I can't figure out any way to solve that problem algorithmically without drawing out the shape.
Am I missing some obviously simple solution here, or is it as complex as it looks?
Thanks.
I'm trying to rewrite a certain legacy system we have that I don't have access to the source code. It's an OLD COBOL program (20+ years old) that calculates building information. The floor area of the building was specified in a weird way though.
For rectangular shapes, it was simple: 50x25 would naturally calculate to 1250 square feet. However, for irregular shapes it took in input in a strange fashion. You told it the up and down movements on how to draw the shape, and it then calculated the area. U for up, D for down, R for right, L for left, followed by a digit. So for example you could have:
U10R5D5R10U10R5D15L8U1L4D1L8
This draws a fairly odd shape. Now, by hand, finding the area of this thing is easy. I draw it out, it breaks down into 5 rectangles of different size, and I calculate the area of each and add them all together (the above example is 171 square feet). Problem is, for the life of me I can't figure out any way to solve that problem algorithmically without drawing out the shape.
Am I missing some obviously simple solution here, or is it as complex as it looks?
Thanks.