Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:others:color_coordination_puzzle_solution_by_sql [2014/11/15 09:13] (current)
Line 1: Line 1:
 +Found an interesting way to solve [[tech:​others:​color_coordination_puzzle|the color coordination puzzle]]. This puzzle, like most other, can be solved with a computer program, and I did just that. However, with an approach, that I doubt if anyone has ever taken to solving puzzles. \\
 +
 +Without any more rhetoric here goes: I solved this puzzle using a database SQL, and here are the steps leading up to it (the solution took only milliseconds to process): \\
 +
 +<​code>​
 +Create a table called circles: ​
 +create table circles ​
 +
 +blk_num number not null, 
 +color_position number not null, 
 +color_cd char(1) not null 
 +); 
 +</​code>​
 +
 +Although Primary key needs to be only the 1st two columns I made all three as Primary Key for efficiency. \\
 +
 +Create the data with: \\
 +
 +<​code>​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 1, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 2, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 3, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 4, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (1, 5, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 1, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 2, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 3, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 4, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (2, 5, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 1, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 2, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 3, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 4, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (3, 5, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 1, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 2, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 3, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 4, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (4, 5, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 1, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 2, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 3, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 4, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (5, 5, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 1, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 2, '​X'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 3, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 4, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (6, 5, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 0, '​Y'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 1, '​W'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 2, '​B'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 3, '​G'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 4, '​R'​); ​
 +Insert into CIRCLES (BLK_NUM, COLOR_POSITION,​ COLOR_CD) Values (0, 5, '​X'​); ​
 +COMMIT; ​
 +</​code>​
 +
 +
 +And finally run the SQL: \\
 +<​code>​
 +select c11.*,​c12.*,​c13.*,​c14.*,​c15.*,​c16.*,​cc1.* ​
 +from 
 +circles c11, circles c12, circles c13, circles c14, circles c15, circles c16, 
 +circles c21, circles c22, circles c23, circles c24, circles c25, circles c26, 
 +circles c31, circles c32, circles c33, circles c34, circles c35, circles c36, 
 +circles cc1, circles cc2, circles cc3, circles cc4, circles cc5, circles cc6 
 +where 
 +c11.blk_num not in (c12.blk_num,​ c13.blk_num,​ c14.blk_num,​ c15.blk_num,​ c16.blk_num,​ cc1.blk_num) and 
 +c12.blk_num not in (c11.blk_num,​ c13.blk_num,​ c14.blk_num,​ c15.blk_num,​ c16.blk_num,​ cc1.blk_num) and 
 +c13.blk_num not in (c11.blk_num,​ c12.blk_num,​ c14.blk_num,​ c15.blk_num,​ c16.blk_num,​ cc1.blk_num) and 
 +c14.blk_num not in (c11.blk_num,​ c12.blk_num,​ c13.blk_num,​ c15.blk_num,​ c16.blk_num,​ cc1.blk_num) and 
 +c15.blk_num not in (c11.blk_num,​ c12.blk_num,​ c13.blk_num,​ c14.blk_num,​ c16.blk_num,​ cc1.blk_num) and 
 +c16.blk_num not in (c11.blk_num,​ c12.blk_num,​ c13.blk_num,​ c14.blk_num,​ c15.blk_num,​ cc1.blk_num) and 
 +cc1.blk_num not in (c11.blk_num,​ c12.blk_num,​ c13.blk_num,​ c14.blk_num,​ c15.blk_num,​ c16.blk_num) and 
 +-- 
 +c11.blk_num = c21.blk_num and c11.blk_num = c31.blk_num and 
 +c12.blk_num = c22.blk_num and c12.blk_num = c32.blk_num and 
 +c13.blk_num = c23.blk_num and c13.blk_num = c33.blk_num and 
 +c14.blk_num = c24.blk_num and c14.blk_num = c34.blk_num and 
 +c15.blk_num = c25.blk_num and c15.blk_num = c35.blk_num and 
 +c16.blk_num = c26.blk_num and c16.blk_num = c36.blk_num and 
 +-- 
 +cc1.blk_num = cc2.blk_num and 
 +cc1.blk_num = cc3.blk_num and 
 +cc1.blk_num = cc4.blk_num and 
 +cc1.blk_num = cc5.blk_num and 
 +cc1.blk_num = cc6.blk_num and 
 +-- 
 +mod(c11.color_position+1,​6) = c21.color_position and mod(c11.color_position+5,​6) = c31.color_position and 
 +mod(c12.color_position+1,​6) = c22.color_position and mod(c12.color_position+5,​6) = c32.color_position and 
 +mod(c13.color_position+1,​6) = c23.color_position and mod(c13.color_position+5,​6) = c33.color_position and 
 +mod(c14.color_position+1,​6) = c24.color_position and mod(c14.color_position+5,​6) = c34.color_position and 
 +mod(c15.color_position+1,​6) = c25.color_position and mod(c15.color_position+5,​6) = c35.color_position and 
 +mod(c16.color_position+1,​6) = c26.color_position and mod(c16.color_position+5,​6) = c36.color_position and 
 +-- 
 +cc1.color_cd = c11.color_cd and cc1.color_position < cc2.color_position and 
 +cc2.color_cd = c12.color_cd and cc2.color_position < cc3.color_position and 
 +cc3.color_cd = c13.color_cd and cc3.color_position < cc4.color_position and 
 +cc4.color_cd = c14.color_cd and cc4.color_position < cc5.color_position and 
 +cc5.color_cd = c15.color_cd and cc5.color_position < cc6.color_position and 
 +cc6.color_cd = c16.color_cd and 
 +-- 
 +c21.color_cd = c36.color_cd and 
 +c22.color_cd = c31.color_cd and 
 +c23.color_cd = c32.color_cd and 
 +c24.color_cd = c33.color_cd and 
 +c25.color_cd = c34.color_cd and 
 +c26.color_cd = c35.color_cd ​
 +;
 +-----------
 +</​code>​
 +
 +
 +[[http://​www.greylabyrinth.com/​discussion/​viewtopic.php?​p=297857 | Solution posted in forum, search for cmsenthil]]\\
 +\\
 +[[tech:​others:​color_coordination_puzzle_solution_explanation|Puzzle Solution Explanation]]
  

QR Code
QR Code tech:others:color_coordination_puzzle_solution_by_sql (generated for current page)