Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Holiday Challenge Time :)

CentinulDec 29 2009 — edited Nov 2 2010
I have a daily puzzle calendar on my desk and I found a puzzle that I thought may be fun to solve using SQL.

Sample Data
WITH    matrix AS
(
        SELECT  'A' AS ID, 1 AS A,1 AS B,1 AS C,0 AS D,0 AS E,0 AS F,1 AS G,0 AS H,1 AS I,0 AS J FROM DUAL UNION ALL
        SELECT  'B' AS ID, 0,0,0,0,1,1,1,0,1,0 FROM DUAL UNION ALL
        SELECT  'C' AS ID, 0,1,1,1,1,0,0,0,0,1 FROM DUAL UNION ALL
        SELECT  'D' AS ID, 1,0,0,0,1,0,1,0,0,0 FROM DUAL UNION ALL
        SELECT  'E' AS ID, 1,1,0,0,0,0,0,0,0,1 FROM DUAL UNION ALL
        SELECT  'F' AS ID, 0,1,1,0,1,1,0,0,0,0 FROM DUAL UNION ALL
        SELECT  'G' AS ID, 0,1,0,1,1,1,0,1,0,1 FROM DUAL UNION ALL
        SELECT  'H' AS ID, 1,1,0,1,0,0,0,1,0,0 FROM DUAL UNION ALL
        SELECT  'I' AS ID, 0,1,1,1,0,1,1,1,0,1 FROM DUAL UNION ALL
        SELECT  'J' AS ID, 1,0,0,0,0,0,0,1,0,1 FROM DUAL UNION ALL
        SELECT  'K' AS ID, 1,0,0,1,1,1,0,1,1,0 FROM DUAL UNION ALL
        SELECT  'L' AS ID, 0,0,1,0,1,1,0,0,1,0 FROM DUAL UNION ALL
        SELECT  'M' AS ID, 0,0,1,0,0,0,0,1,1,1 FROM DUAL UNION ALL
        SELECT  'N' AS ID, 1,0,1,0,0,0,1,1,1,0 FROM DUAL UNION ALL
        SELECT  'O' AS ID, 1,0,0,1,1,0,1,0,0,0 FROM DUAL
)
SELECT  *
FROM    MATRIX
ORDER BY 1
Problem Statement

Suppose we have a matrix of one's and zero's like the following:
ID  A  B  C  D  E  F  G  H  I  J
-- -- -- -- -- -- -- -- -- -- --
A   1  1  1  0  0  0  1  0  1  0
B   0  0  0  0  1  1  1  0  1  0
C   0  1  1  1  1  0  0  0  0  1
D   1  0  0  0  1  0  1  0  0  0
E   1  1  0  0  0  0  0  0  0  1
F   0  1  1  0  1  1  0  0  0  0
G   0  1  0  1  1  1  0  1  0  1
H   1  1  0  1  0  0  0  1  0  0
I   0  1  1  1  0  1  1  1  0  1
J   1  0  0  0  0  0  0  1  0  1
K   1  0  0  1  1  1  0  1  1  0
L   0  0  1  0  1  1  0  0  1  0
M   0  0  1  0  0  0  0  1  1  1
N   1  0  1  0  0  0  1  1  1  0
O   1  0  0  1  1  0  1  0  0  0
Positions in this matrix are defined using (ROW,COLUMN) throughout the problem statement.

Challenge

Our goal is from a start position identified as (A,E), First Row, Fifth column, traverse DOWN the matrix to reach a valid point on row "O."

Restrictions

1. You can only move UP, DOWN, LEFT, or RIGHT (not diagonally) by one unit.
2. The path must be a repeating pattern of 0 1 0 1 0 1 ... etc For example a move from (A,E) to (B,E) is valid while a move from (A,E) to (A,F) is not.

Correct Solution

The correct solution has the following requirements:

1. Identifies the path from start to finish using an identifiable way to determine the ROW,COLUMN for each entry point in the path while abiding by the restrictions above.
2. PL/SQL and SQL are acceptable.
3. Solution must be perform well and be elegant as judged (loosely, since we don't have any voting functionality) by your peers. This solution will be marked as "Correct." Helpful points will be given to runner ups as determined by your peers.

Enjoy :D
This post has been answered by Rob van Wijk on Dec 29 2009
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 2 2010
Added on Dec 29 2009
10 comments
4,049 views