no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | tech:others:color_coordination_puzzle_solution_by_sql [2014/11/15 15:13] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Found an interesting way to solve [[tech: | ||
+ | |||
+ | 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): \\ | ||
+ | |||
+ | < | ||
+ | Create a table called circles: | ||
+ | create table circles | ||
+ | ( | ||
+ | blk_num number not null, | ||
+ | color_position number not null, | ||
+ | color_cd char(1) not null | ||
+ | ); | ||
+ | </ | ||
+ | |||
+ | Although Primary key needs to be only the 1st two columns I made all three as Primary Key for efficiency. \\ | ||
+ | |||
+ | Create the data with: \\ | ||
+ | |||
+ | < | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | Insert into CIRCLES (BLK_NUM, COLOR_POSITION, | ||
+ | COMMIT; | ||
+ | </ | ||
+ | |||
+ | |||
+ | And finally run the SQL: \\ | ||
+ | < | ||
+ | select c11.*, | ||
+ | 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, | ||
+ | c12.blk_num not in (c11.blk_num, | ||
+ | c13.blk_num not in (c11.blk_num, | ||
+ | c14.blk_num not in (c11.blk_num, | ||
+ | c15.blk_num not in (c11.blk_num, | ||
+ | c16.blk_num not in (c11.blk_num, | ||
+ | cc1.blk_num not in (c11.blk_num, | ||
+ | -- | ||
+ | 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, | ||
+ | mod(c12.color_position+1, | ||
+ | mod(c13.color_position+1, | ||
+ | mod(c14.color_position+1, | ||
+ | mod(c15.color_position+1, | ||
+ | mod(c16.color_position+1, | ||
+ | -- | ||
+ | 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 | ||
+ | ; | ||
+ | ----------- | ||
+ | </ | ||
+ | |||
+ | |||
+ | [[http:// | ||
+ | \\ | ||
+ | [[tech: | ||