In Stereo
Statement
Goal
A time machine with an empty gas tank leaves you stranded in a 1990s shopping mall, with nothing the locals recognize as money. The only commodity you can release without ruining the timeline are those stereogram posters sometimes known by the trade name "Magic Eye". Can you sell enough 3D art to top up the tank and get back to modern life?https://en.wikipedia.org/wiki/Autostereogram
Start with a base pattern (which wraps around), a stock of extra symbols to fill in when the pattern needs to grow, and a depth map.
For each line in the depth map, start at the beginning of the original pattern with the original stock and at a depth of
For each character in the depth map:
1. If the depth is higher, decrease the pattern by removing characters at the current position.
If the depth is lower, increase the pattern by moving characters from the stock into the current position.
2. Output the pattern character at the current position.
3. Advance to the next pattern position, wrapping around if you reach the end.
For example, if the pattern is
| Current | New | Change | | New | |
Pattern | Depth | Depth | in Depth | Action | pattern | Stock | Output
--------+---------+-------+----------+----------+---------+-------+-------
ABCD | 0 | 2 | +2 | Remove 2 | CD | UVWX | C
CD | 2 | 3 | +1 | Remove 1 | C | UVWX | C
C | 3 | 2 | -1 | Add 1 | UC | VWX | U
UC | 2 | 0 | -2 | Add 2 | UVWC | X | V
UVWC | 0 | 0 | 0 | Nothing | UVWC | X | W
bold indicates current position in pattern
Because of length limitations for test cases, the examples below are too narrow to see easily.
Here's a wider depth map: https://pastebin.com/raw/ZBffbNTy
The stereogram it produces: https://pastebin.com/raw/UZbLA2CE
(Zoom out until the lines do not wrap. Use the parallel "wall-eyed" viewing technique, not cross-eyed.)
Input
Line 1: An integer P for the length of the pattern
Line 2: A string pattern
Line 3: An integer S for the length of the stock
Line 4: A string stock
Line 5: Two integers H W for the height and width of the depth map
Next H lines: A string of length W for each line of the depth map
Line 2: A string pattern
Line 3: An integer S for the length of the stock
Line 4: A string stock
Line 5: Two integers H W for the height and width of the depth map
Next H lines: A string of length W for each line of the depth map
Output
H lines of width W: The stereogram
Constraints
P < 20
S < 20
H < 30
W < 200
S < 20
H < 30
W < 200
Example
Input
4 ABCD 3 UVW 4 10 0000000000 0001111000 0200000001 1232000222
Output
ABCDABCDAB ABCABCAUBC ADUVADUVAU BDDUVWDWDW
Tags
Strings, String manipulation, Reading the statement
Difficulty
Easy
Test cases
Example Test
Input
4
ABCD
3
UVW
4 10
0000000000
0001111000
0200000001
1232000222
Output
ABCDABCDAB
ABCABCAUBC
ADUVADUVAU
BDDUVWDWDW
Example Validator
Input
5
edcba
5
zyxwv
4 10
0000000000
0001111000
0100000002
1232000333
Output
edcbaedcba
edcaedczae
eczbaeczbc
dbdzyxbxbx
Lattice Test
Input
8
|-+_!=\/
8
-/|!+_\=
9 33
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
Output
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
-+_!=\/-+_!=\/-+_!=\/-+_!=\/-+_!=
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
-+_!=\/-+_!=\/-+_!=\/-+_!=\/-+_!=
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
|-+!=-\/-+/!=\/|-+!=!\/-++!=\/_-+
-+_!=\/-+_!=\/-+_!=\/-+_!=\/-+_!=
Lattice Validator
Input
8
|+-_=!/\
8
-!/|_+\=
10 33
111111111111111111111111111111111
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
000110001100011000110001100011000
000110001100011000110001100011000
111111111111111111111111111111111
Output
+-_=!/\+-_=!/\+-_=!/\+-_=!/\+-_=!
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
+-_=!/\+-_=!/\+-_=!/\+-_=!/\+-_=!
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
+-_=!/\+-_=!/\+-_=!/\+-_=!/\+-_=!
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
|+-=!-/\+-!=!/\/+-=!|/\+-_=!/\++-
+-_=!/\+-_=!/\+-_=!/\+-_=!/\+-_=!
Diamond Test
Input
10
8 8 88
10
8 8 88 8
21 40
0000000000000000000000000000000000000000
0000000000000000010000000000002220000000
0000000000000000111000000000222222200000
0000000000000001121100000002222222220000
0000000000000011222110000002222222220000
0000000000000112232211000000222222200000
0000000000001122333221100000002220000000
0000000000011223343322110000000000000000
0000000000112233444332211000000000000000
0000000001122334444433221100000000000000
0000000011223344444443322110000000000000
0000000001122334444433221100000000000000
0000000000112233444332211000000000000000
0000000000011223343322110000001110000000
0000000000001122333221100000022222000000
0000000000000112232211000000333333300000
0000000000000011222110000004444444440000
0000000000000001121100000000000000000000
0000000000000000111000000000000000000000
0000000000000000010000000000000000000000
0000000000000000000000000000000000000000
Output
8 8 88 8 8 88 8 8 88 8 8 88
8 8 88 8 8 8 8 8 8 8 8 8
8 8 88 8 8 88 8 8 888 8 88 88
8 8 88 8 8 8 88 8 888 8 88 88
8 8 88 8 8 8 8 88 8 88 8 8 8
8 8 88 8 8 888 88 88888 888 888
8 8 88 8 8 8 8 8 8 8 8 8
8 8 88 88 8 8 8 88 8 8 88 8
8 8 88 8 88 8 88 88 8 88 88 8
8 8 888 88 888 8 888 8
8 8 8 88 88 888 8 888 8
8 8 888 88 888 8 888 8
8 8 88 8 88 8 88 88 8 88 88 8
8 8 88 88 8 8 8 88 8 88 8
8 8 88 8 8 8 8 8 8 8 88 8 8
8 8 88 8 8 888 88 8888 8888 8
8 8 88 8 8 8 8 88 888 888 8
8 8 88 8 8 8 88 8 8 88 8 8 8
8 8 88 8 8 88 8 8 88 8 8 88
8 8 88 8 8 8 8 8 8 8 8 8
8 8 88 8 8 88 8 8 88 8 8 88
Diamond Validator
Input
10
# # ##
10
# # ## #
21 44
00000000000000000000000000000000000000000000
00000000000000000010000000000001110000000000
00000000000000000111000000000111111100000000
00000000000000001121100000001111111110000000
00000000000000011222110000001111111110000000
00000000000000112232211000000111111100000000
00000000000001122333221100000001110000000000
00000000000011223343322110000000000000000000
00000000000112233444332211000000000000000000
00000000001122334444433221100000000000000000
00000000011223344444443322110000000000000000
00000000001122334444433221100000000000000000
00000000000112233444332211000000000000000000
00000000000011223343322110000001110000000000
00000000000001122333221100000022222000000000
00000000000000112232211000000333333300000000
00000000000000011222110000004444444440000000
00000000000000001121100000000000000000000000
00000000000000000111000000000000000000000000
00000000000000000010000000000000000000000000
00000000000000000000000000000000000000000000
Output
# # ## # # ## # # ## # # ## # #
# # ## # # # # # # ## # # ##
# # ## # # # # # # # ## #
# # ## # # ### ## ## ## ## ##
# # ## # # # # ## # ## # ##
# # ## # # # ## # ## ## ##
# # ## # # ### # # ### # # #### # #
# # ## # # # # ## # # ## # #
# # ## ## # # ## ## ## ## ##
# # ## # ## # # ## ## # ## ## # ##
# # ### ## ## # # ## # # ##
# # ## # ## # # ## ## # ## ## # ##
# # ## ## # # ## ## ## ## ##
# # ## # # # # ## # # # # #
# # ## # # ### # # ### ## ### # ## #
# # ## # # # ## # # # #
# # ## # # # # ## # # # # # #
# # ## # # ### ## ### ## ### ##
# # ## # # # # # # # # # # #
# # ## # # # # # # # # # # #
# # ## # # ## # # ## # # ## # #
ViewFullscreen Test
Input
12
`'"'`*"`"`*"
13
"`*".*"""'*'.
18 53
00000000000000000000000000000000000000000000000000000
00000000000000011111111111110000000011111111111110000
00000000000011111111111111110000011111111111111110000
00000000001111111111111111110001111111111111111110000
00000000011111111111111111110011111111111111111110000
00000000111111100000001111110111111100000001111110000
00000001111111000000000000001111111000000000000000000
00000001111111000000000000001111111000000000000000000
00000001111111000000000000001111111000011111111110000
00000001111111000000000000001111111000011111111110000
00000001111111000000000000001111111000011111111110000
00000001111111000000000000001111111000000001111110000
00000000111111100000001111110111111100000001111110000
00000000011111111111111111110011111111111111111110000
00000000001111111111111111110001111111111111111110000
00000000000011111111111111110000011111111111111110000
00000000000000011111111111110000000011111100011110000
00000000000000000000000000000000000000000000000000000
Output
`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`
`'"'`*"`"`*"`'"`*"`"`*"`'"`*""`"`*"`"`*""`"`*"`"``*""
`'"'`*"`"`*"'"'`*"`"`*"'"'`*""`"`"'"'`*""`"`"'"'``*""
`'"'`*"`"`"`'"'`*"`"`"`'"'`*""``"`'"'`*""``"`'"'``*""
`'"'`*"`"*"`'"'`*"`"*"`'"'`*"""*"`'"'`*"""*"`'"'``*""
`'"'`*"``*"`'"'"`*"``*`'"'"``"``*`'"*'"``"`*`'"*'""``
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""'*""`*"``'""'*
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""'*""`*"``'""'*
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""*""`*"``'"*"*"
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""*""`*"``'"*"*"
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""*""`*"``'"*"*"
`'"'`*""`*"`'""'`*""`*"`'""'*""`*"``'""'*""*"``'"*"'*
`'"'`*"``*"`'"'"`*"``*`'"'"``"``*`'"*'"``"`*`'"*'""``
`'"'`*"`"*"`'"'`*"`"*"`'"'`*"""*"`'"'`*"""*"`'"'``*""
`'"'`*"`"`"`'"'`*"`"`"`'"'`*""``"`'"'`*""``"`'"'``*""
`'"'`*"`"`*"'"'`*"`"`*"'"'`*""`"`"'"'`*""`"`"'"'``*""
`'"'`*"`"`*"`'"`*"`"`*"`'"`*""`"`*"`"`*""``"`"`"`**""
`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`
ViewFullscreen Validator
Input
12
`'"'`*"`"`*"
15
"`*".*"`""'*'`*
18 46
0000000000000000000000000000000000000000000000
0000000000011111111100011111111111111100000000
0000000000111111111100111111111111111111000000
0000000001111111111100111111111111111111100000
0000000011111111111100111111100000111111100000
0000000111111011111100000000000000111111100000
0000001111110011111100000000000000111111100000
0000011111100011111100000000000111111111000000
0000111111111111111111000011111111111110000000
0000111111111111111111001111111111111000000000
0000111111111111111111011111111111000000000000
0000000000000011111100111111100000000000000000
0000000000000011111100111111100000000000000000
0000000000000011111100111111100000001111110000
0000000000001111111111111111111111111111110000
0000000000001111111111111111111111111111110000
0000000000001111111111111111111111111111110000
0000000000000000000000000000000000000000000000
Output
`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`
`'"'`*"`"`*`'"'`*"`""`*'"'`*"`""`*'"'``*"`""`*
`'"'`*"`"`"`'"'`*"`""``'"'`*"`""``'"'`*"``""``
`'"'`*"`"*"`'"'`*"`""*`'"'`*"`""*`'"'`*"``""*`
`'"'`*"``*"`'"'`*"``"*`'"'`*"```"*'"'`*"`*``"*
`'"'`*""`*"`'"'`*""``*"`'"'`*""``*`'"'`*"*"``*
`'"'`*`"`*"`"''`*`"``*"`"''`*`"``*`"''`*`*"``*
`'"'`"`"`*""`''`"`"``*""`''`"`"`*""`''`"*`"`*"
`'"'*"`"`*"`'"'*"`"`*""`'"*"`"`*""`'"*"``"`*""
`'"'*"`"`*"`'"'*"`"`*""`"'*"`"`*""`"'`*"`"`*""
`'"'*"`"`*"`'"'*"`"`*""'"'*"`"`*""`'"'*"`"`*""
`'"'`*"`"`*"`''`*"`""`"`''`*"``""`"`''`*"``""`
`'"'`*"`"`*"`''`*"`""`"`''`*"``""`"`''`*"``""`
`'"'`*"`"`*"`''`*"`""`"`''`*"``""`"`'`*"``*""`
`'"'`*"`"`*"'"'`*"`"`*"'"'`*"`"`*"'"'`*"`""`*"
`'"'`*"`"`*"'"'`*"`"`*"'"'`*"`"`*"'"'`*"`""`*"
`'"'`*"`"`*"'"'`*"`"`*"'"'`*"`"`*"'"'`*"`""`*"
`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`*"`'"'`*"`"`
Solution language
Solution
Stub generator input