The Game − สมมติ n × n array of squares บางส่วนว่าง บางส่วน solid บาง non-solid squares มี integers 1, 2, 3,... แต่ละ integer อยู่ที่ 2 squares ที่ต่างกันพอดี งานของ player คือ connect 2 occurrences ของแต่ละ integer ด้วย simple path ใช้ horizontal และ vertical movements เท่านั้น ไม่มี path 2 ทาง intersect กัน ไม่มี path ผ่าน solid squares ท้ายที่สุด non-solid squares ทั้งหมดต้องถูกเติมโดย paths
The Algorithm − เพื่อสร้าง valid random puzzle ขนาด n × n เรา produce random simple mutually non-intersecting paths บน board ก่อน ถ้ามี isolated squares เหลืออยู่นอก paths ทั้งหมด mark ว่า solid (forbidden) ต่อมา เราให้ endpoints ของ paths และ list ของ solid squares เป็น puzzle
ดังนั้นเราผลิต solution ก่อน แล้วค่อย derive puzzle จาก solution Paths และ solid squares partition n × n board เราใช้ union-find data structure เพื่อ produce partition Data structure จัดการ subsets ของ set of n^2 squares บน board
PseudoCode
Locate squares (a, b) และ (c, d) แบบสุ่มบน board โดยที่ −
(a, b) และ (c, d) เป็น neighbors กัน
ไม่มี (a, b) หรือ (c, d) 属于 any path ที่สร้างมาแล้ว ถ้าไม่เจอคู่ดังกล่าวบน board ทั้งหมด return FAILURE /* (a, b) และ (c, d) คือ 2 squares แรกของ new path */
Make union ของ 2 union-find trees ที่มี (a, b) และ (c, d)
Repeat ตราบใดที่ current path ยังขยายได้ −
Rename (a, b) = (c, d)
Locate random neighboring square (c, d) ของ (a, b) โดยที่ −
(c, d) ไม่อยู่ใน path ใดๆ ที่สร้างมาแล้ว (รวม current)
neighbor (c, d) มีเพียง (a, b) อยู่บน partially constructed current path
ถ้าไม่เจอ neighbor (c, d) path ไม่ขยายได้ break loop
มิฉะนั้น make union ของ 2 union-find trees ที่ (a, b) และ (c, d) 属于
Set endpoint flags ของ 2 squares ที่ start และ end ของ new path
Return SUCCESS