The Programming Olympiad is a prestigious event where thousands of programmers from South Africa compete to be placed among the top 15 programming students in the country. The first round was written on 1 August 2014 and the paper consisted of five thought-provoking programming problems.

Unfortunately, I was unable to solve the last question and I need your help.

**PROBLEM #5: Transformation**

Some doors can be unlocked using a key card - a plastic card with holes in it. A key card may be square like this :(O means a hole, X means no hole); but it may also be a rectangle or triangle.

```
XXXO
XXOX
XOXX
XXOX
```

However in order to work, these specific key cards have to be rotated or flipped according to one or more of these transformation instructions:

R = Rotate 90 degrees to the right

T = Top to bottom flip: you see the back - upside down

L = Left to right flip; you see the back - mirrored

**Task**

Write a program that will take the given key card, rotate, and/or flip it as instructed, and print out the resulting key card. No card will be more than 40 by 40 spaces.

Example:

Input:

```
XXXO
XXOX
XOXX
XXOX
```

Transformation: R, L

Output:

```
XXXX
XXOX
XOXO
OXXX
```

Explanation:

After rotating by 90 degrees:

```
XXXX
XOXX
OXOX
XXXO
```

After a left to right flip:

```
XXXX
XXOX
XOXO
OXXX
```

Credit: Allan Smithee

## Comments

Sort by:

TopNewestTest your program with:

a)

Transformation: T

b)

Transformation: T, L, R

c)

Transformation: R, T, L – Mark Mottian · 2 years, 5 months ago

Log in to reply

– Daniel Liu · 2 years, 5 months ago

I think using a two-dimensional array and then creating methods for each transformation works for the first two cases. I'm clueless how to do the triangle case though...Log in to reply

– Mark Mottian · 2 years, 5 months ago

Hi Daniel. First off, I'm a big fan. Davis Sparinskis suggested that you can use a space 'character' to get the correct shape for the triangle. My initial thought was to also use a two dimensional array, however, I encountered some problems. Please HELP!Log in to reply

– Dāvis Sparinskis · 2 years, 5 months ago

Couldn't it be assumed that in the triangular case there is a third symbol - space? Then the triangular case would be the same as the others since the symbol itself doesn't matter as long as it's there. Unless that's against the rules or I've misunderstood the input.Log in to reply

– Mark Mottian · 2 years, 5 months ago

That is a legitimate approach. Do you know how to implement this in a program?Log in to reply

This is my solution using a 2-D array and treating each of the cards as a square, with symbols ' o ' ,' x ' and ' '. The downside with this approach is that all of the symbols have to be entered manually.

Log in to reply

:/ – Rohan Gupta · 2 years, 5 months ago

Log in to reply