# [Community Puzzle] Folding a Note

Coding Games and Programming Challenges to Code Better

Created by @P4V3L14K0V,validated by @irmo322,@fungi_star and @adila.
If you have any issues, feel free to ping them.

1 Like

Cool puzzle! For some reason, though, at first, my brain couldnât wrap around what the word âfoldâ meant. It wasnât until after I reread the description a couple times that I connected the dots to folding a physical piece of paper. Seems obvious in retrospect. Must just have been having a brain fartâŚ

1 Like

You can also say: âmy brain foldedâ (ie. as in card games)

2 Likes

Good puzzle, 5 stars!

I saw how the people solve the problem. Lists, stacks, queuesâŚ I did a dumb simulation on 3D arrays - passed.

1 Like

Nothing dumb about using a 3D array. I essentially did that, myself. Itâs all about how you use it that matters.

2 Likes

I made a dumb hardcoded solution.
We have few options for this task, the sizes of the original note are 1, 2, 4, 8, 16.

1. I solved the problem in a ânormalâ way
2. I made testcases - notes with unique symbols for each of the five cases (really 4 cases - 2, 4, 8, 16)
3. I traced in the process of solving which coordinates are viewed and in what order. More precisely, I looked through the answer and for each character in the answer found its coordinates in the original note. I made all symbols unique for this.
4. I hardcoded the list of coordinates from point 3 into an array and made a stupid second solution that does not fold any notes, but simply view the note according to the predefined instructions from point 3.

But if you make a cryptographic chip, then you probably need to follow this way

1 Like

I tried using an in-place 2D array that keeps track of which letter ends up in which ply after each fold. For example, when N = 4 in case 3:

`8. 15 14 9.`
`7. 0. 1. 6.`
`4. 3. 2. 5.`
`11 12 13 10`

It worked for the first few folds, and then I realized that it was not at all obvious how to figure out which ply ends up on top of which. For example, my answer for case #4 (N=8) is missing a flip somewhere:

Found: Oink oinkâŚ I want some bacon.The supervisor looks like a hog!
Expected: The supervisor looks like a hog! Oink oinkâŚ I want some bacon.

I also canât physically fold a paper 8 times and check the answer without losing my brain, so I donât know what Iâm missing. I guess Iâll have to scrap this idea and manually fold 3D matricesâŚ

Incidentally, if you tile the above 4x4 matrix, youâll see that that the path that you trace going from 0 to 15 is continuous and makes pretty patterns. I have no idea how this pattern is defined, but I guess it must be a fractal of some sort.

Post-success edit:
Turns out that the continuous path for 4x4 doesnât exist for higher dimensions. The same path is followed in a recursive manner: when moving from the 0th ply to the 1st ply, which looks like moving right one cell in the above matrix, youâre actually stepping right one cell and jumping right one 4x4 mega-cell at the same time. Kind of like ultimate tic-tac-toe.

Anyway, since my solution gave close to the right answer, I printed the ply matrix and manually shifted blocks of cells around in excel a few times to get the right answer. Then I reverse engineered the solution. I first did this for N=8, but the resulting solution failed for N=16 in the same manner as above. I made an assumption in the pattern that ended up false. After repeating this task for N=16, I believe I now have an extrapolatable rule for higher N, and apparently the first two flips are an exception to the rule that initially threw me off.

2 Likes

Hi guys,

Is there any visual representation I can see on the internet of this matter ? English is not my first language and Iâm struggling to understand how it is possible to read letters on a folded paper

Thank you

1 Like

Hi, Iâm also stuck on test cases #4 and #5; also for me test case #4 ends with
`Oink oink... I want some bacon.The supervisor looks like a hog!`

Probably Iâm missing something in understanding how folding works, here are my intermediate folds, can somebody tell me whatâs wrong? Thank you.

Iâm using a 2D array of strings, chars in the string must interpreted as stacked, first char at the top, last char at bottom.

``````Puzzle input
krloo vi
nmw Iaok
ie. On o
eeT!ghp
s hoeua
kacniob
. t. ns.
soskril

Unfolded note
k|r|l|o|o| |v|i
n|m|w| |I|a|o|k
i|e|.| |O|n| |o
e|e|T|!|g|h|p|
|s| |h|o|e|u|a
k|a|c|n|i|o|b|
.| |t|.| |n|s|.
|s|o|s|k|r|i|l

After Folding ToLeft
ik|vr| l|oo
kn|om|aw|I
oi| e|n.|O
e|pe|hT|g!
a |us|e |oh
k|ba|oc|in
..|s |nt| .
l |is|ro|ks

After Folding ToTop
lik|sivr|or l|skoo
..kn| som|tnaw|. I
k oi|ab e|con.|niO
a e|supe| ehT|hog!

After Folding ToRight
kil skoo|rvisor l
nk... I |mos tnaw
io kniO |e bacon.
e a hog!|epus ehT

After Folding ToBottom
ooks like a hog!|l rosivrepus ehT
I ...knio kniO |want some bacon.

After Folding ToLeft
The supervisor looks like a hog!
.nocab emos tnaw I ...knio kniO

After Folding ToTop
Oink oink... I want some bacon.The supervisor looks like a hog!

Result
Oink oink... I want some bacon.The supervisor looks like a hog!

Expected:
The supervisor looks like a hog! Oink oink... I want some bacon.
``````
1 Like

This seems off to me. Think about what should be in the top left corner when you fold the note from left to right.

3 Likes

Absolutely right, thank you.

1 Like