Folding a Note
Statement
Goal
You are stuck in detention again and your friend wants to send you a note from across the room. However, the detention supervisor is clever and knows that if he intercepts a folded note, he can intercept and decode the message it contains by unfolding the paper. To thwart his ingenuity, you have both agreed on a procedure beforehand: she will send you an unfolded note, and to decode it, you will need to fold it up until there is only one character on each ply, and then read the plies from top to bottom in order to recover the intended message.In the physical world, some folds will have the effect of reversing the side of the paper on which some characters appear when reading the final message, as well as their orientation. We ignore this and read the characters on each ply, regardless of which side of the paper they are on or how they are rotated.
The folds will occur in a specific order, until only one character is on each ply:
The first fold will be from right to left, that is, the right half of the note is folded on top of the left half
The second fold (if it occurs) will be from bottom to top
The third fold (if it occurs) will be from left to right
The fourth fold (if it occurs) will be from top to bottom
Subsequent folds, if they occur, will continue to cycle in this order.
Example
You receive the unfolded note:
12
34
After the first fold, from right to left, the note now has two plies,which are, from top to bottom:
2
4
and
1
3
After the second and final fold from bottom to top, the note has 4 plies each containing one character, and thus the final message is obtained by reading the plies from top to bottom:
3421
Input
Line 1: An integer N, the number of lines in the note.
Next N lines: A string L of N characters representing a line of the note
Next N lines: A string L of N characters representing a line of the note
Output
A string of N×N characters representing the folded note as read ply by ply from top to bottom.
Constraints
0 < N ≤16
N is always a power of 2.
N is always a power of 2.
Example
Input
1 A
Output
A
Tags
2D array, Loops, Cryptography
Difficulty
Medium
Test cases
Easy Test
Input
1
A
Output
A
Validator 1 Validator
Input
1
*
Output
*
LOL Test
Input
2
OA
LM
Output
LMAO
Validator 2 Validator
Input
2
-7
m.
Output
m.7-
Brooo... Test
Input
4
uDuu
u!eu
uudu
uuuu
Output
Duuuuuuuuuuuude!
Validator 4 Validator
Input
4
z&-M
1}{'
nWF{
C|W2
Output
&-W|C2Mz1'{nWF{}
Piggy Test
Input
8
krloo vi
nmw Iaok
ie. On o
eeT!ghp
s hoeua
kacniob
. t. ns.
soskril
Output
The supervisor looks like a hog! Oink oink... I want some bacon.
Validator 8 Validator
Input
8
QHMICVXO
BXBVWFPY
LMJXFBVF
YJKUSUTQ
ZTHDNR[O
MSAQKKEV
TBBETIJU
NASCHRXG
Output
KURHT[TJHXXASRVMICHCNGOQYQOZDNSUXFKQMVFLBYUTETWVBFIBBJPXMVESAKBJ
I really like detention. Test
Input
16
onssoe rnynmw
i c i f eodnsres
lis .eann ,a ke
sfwienw irt uae
I rhaAp w eoet
lomr. ahsyta t
xb shifrmocwpsle
foo ekognsi eui
ps,eh erisltslss
fswt, so h oai
elaI pu cop. hsh
ckne oeihnwhldah
j m syoytehylhn
f aon m diIelmee
etahtt ncre ieht
gfreti nimt eeos
Output
A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy.
Validator 16 Validator
Input
16
fWT2omQ1eMt9:5T8
8TBzJ_OovyBe!2gP
INdoXf1QIyKBbwC5
cLafrL!uV5BZjkpU
q4t-5gTh2qnK5I3E
5PZE5PYMIKWR-_v8
HqlSB7tDwZUnIY-A
sJC0NqklDk6iwO-c
VNUKbe5Mudy5Ojpp
7YSBbba!?Py:G1bV
33jOVl8EPb7Bz_Kl
H4cCkMYE93fChRJH
5TKf!E4xNFvoEjqM
6iEsNIKdxeo0eiUL
O?HUr7FV924HdYfW
U5KKvxhcRzWzCjtI
Output
gnfMcRItakjKEvBL!5F4TqpL43J4Y3qTkkd5Np-JWTt5hzMQmtWxKj5TCOjUey6qNi5bKOw02:CKvz9o1eRcUI8fscpVMuDlh29EHHEqcUM5xNVurZo!fEjf-5hCkCK55RBVOz-EobesN0BXQIxd6L5I58l3EPIMDw?!7VAH8PWOV9voJeHrUd!zSIGBb:nB7UybS1YlB2YH74B_Oy2F?fgTq-bYaPZtYKb83KvPNCUiKey1fKoIEiwdZ__jl7WP
Solution language
Solution
Stub generator input