Problem 2026. Skyscrapers - Puzzle
The Skyscraper puzzle challenge comes from Logic Masters India and Games' Concept is Puzzles.
Create an NxN matrix where each row and column contains 1:N given the constraints of View_Right, View_Left, View_Down, and View_Up. A View is the number of Skyscrapers visible the given edge location. A Zero value is No Information provided.
Input: [vr,vL,vd,vu] vectors of sizes (N,1),(N,1),(1,N),(1,N)
Output: M an NxN matrix
Example:
vr=[0 0 3 0 0]'; vL=[3 0 0 1 0]'; vd=[0 0 0 0 0]; vu=[5 2 0 0 0];
M 5 4 2 1 3 4 5 1 3 2 3 2 4 5 1 2 1 3 4 5 1 3 5 2 4
Algorithm Discussion:
1) Create permutations H and V vectors of length N of values 1:N. (N=5) [12345;12354;...54321] 2) Calc Skyscraper count from Left and Right 3) Determine subset of SkyVectors possible for each Row and Column 4) Sort the Qty of 2*N possible solutions 5) Recursion from least to most valid SkyVectors 6) In recursion verify valid overlay or return
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
129 Solvers
-
How long is the longest prime diagonal?
391 Solvers
-
Calculate the probability that at least two people in a group share the same birthday.
83 Solvers
-
LASER Tracker - Mirror Distance and Angle
31 Solvers
-
GJam 2014 China Rd A: Library Sorting (Small)
25 Solvers
More from this Author294
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!