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
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Test your program with:
a)
Transformation: T
b)
Transformation: T, L, R
c)
Transformation: R, T, L
Log in to reply
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
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
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!
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.
:/