{"product_id":"one-way-or-another-move-the-disc-corner-to-corner","title":"One Way or Another | Move the Disc Corner to Corner","description":"\u003cdiv class=\"gpow\"\u003e\n\u003cstyle\u003e\n.gpow{--fg:rgb(var(--color-foreground,18,18,18));\n --line:rgba(var(--color-foreground,18,18,18),.14);\n --muted:rgba(var(--color-foreground,18,18,18),.64);--accent:#02A9F7;\n font-family:var(--font-body-family,inherit);margin:2.4rem 0;max-width:46rem}\n.gpow *{box-sizing:border-box}\n.gpow h3{font-family:var(--font-heading-family,inherit);font-size:1.9rem;\n line-height:1.3;margin:0 0 .5rem;color:var(--fg)}\n.gpow p{font-size:1.45rem;line-height:1.65;margin:0 0 1.1rem;color:var(--muted);max-width:60ch}\n.gpow #owPhase{font-size:1.15rem;letter-spacing:.04em;color:var(--muted);margin-bottom:.4rem}\n.gpow #owBoard{width:100%;max-width:34rem}\n.gpow #owBoard svg{display:block;width:100%;height:auto;\n \/* The player sets touch-action:none inline because a dedicated page wants\n    full control. On a product page a finger landing here must still scroll,\n    so this overrides it: horizontal drags work, vertical ones scroll past,\n    and the whole puzzle is playable by tapping either way. *\/\n touch-action:pan-y !important}\n\/* iOS: no grey flash on every tap, no text selection while dragging a piece,\n   and no callout menu when a finger rests on the board *\/\n.gpow #owBoard,.gpow #owTray,.gpow .ctl button{-webkit-tap-highlight-color:transparent;\n -webkit-touch-callout:none;-webkit-user-select:none;user-select:none}\n.gpow .row{display:flex;gap:1.2rem;align-items:flex-start;flex-wrap:wrap;margin-top:.9rem}\n.gpow #owTray{display:flex;gap:.7rem;align-items:center;flex-wrap:wrap;padding:.7rem .8rem;\n border:1px solid var(--line);border-radius:7px;min-height:3.6rem;min-width:12rem}\n.gpow #owTray .empty{font-size:1.2rem;color:var(--muted)}\n.gpow .ctl{display:flex;gap:.5rem;flex-wrap:wrap}\n.gpow .ctl button{appearance:none;border:1px solid var(--line);background:transparent;\n color:var(--muted);font-family:inherit;font-size:1.2rem;padding:.55rem 1.1rem;\n border-radius:5px;cursor:pointer}\n.gpow .ctl button:hover{border-color:var(--accent);color:var(--fg)}\n.gpow .ctl button:disabled{opacity:.38;cursor:default}\n.gpow .ctl button:disabled:hover{border-color:var(--line);color:var(--muted)}\n.gpow #owSay{font-size:1.3rem;color:var(--muted);min-height:2rem;margin-top:.7rem}\n\u003c\/style\u003e\n\u003ch3\u003eTry it before you buy it\u003c\/h3\u003e\n\u003cp\u003ePack the four pieces in so the disc keeps its corner, then move the disc to the far\ncorner. Pieces push each other, so sliding one can shove the next along. Plenty of packings\nfit the tray. Far fewer leave the disc anywhere to go, and that is the whole puzzle.\u003c\/p\u003e\n\u003cp\u003eTap a piece to pick it up, then tap a square to nudge it that way. Dragging works too,\nand so do the arrow keys.\u003c\/p\u003e\n\u003cdiv id=\"owPhase\"\u003e\u003c\/div\u003e\n\u003cdiv id=\"owBoard\"\u003e\u003c\/div\u003e\n\u003cdiv class=\"row\"\u003e\n  \u003cdiv id=\"owTray\"\u003e\u003c\/div\u003e\n  \u003cdiv class=\"ctl\"\u003e\n    \u003cbutton type=\"button\" id=\"owRotate\"\u003eRotate\u003c\/button\u003e\n    \u003cbutton type=\"button\" id=\"owFlip\"\u003eFlip\u003c\/button\u003e\n    \u003cbutton type=\"button\" id=\"owTake\"\u003eTake out\u003c\/button\u003e\n    \u003cbutton type=\"button\" id=\"owUnpack\"\u003eEmpty the tray\u003c\/button\u003e\n    \u003cbutton type=\"button\" id=\"owReset\"\u003eStart over\u003c\/button\u003e\n  \u003c\/div\u003e\n\u003c\/div\u003e\n\u003cdiv id=\"owSay\"\u003e\u003c\/div\u003e\n\u003c\/div\u003e\n\u003cscript\u003e\n(function(){\nvar D={\"w\":5,\"h\":4,\"order\":[\"tromino\",\"square\",\"tee\",\"ell\"],\"shapes\":{\"tromino\":[[0,0],[0,1],[1,0]],\"square\":[[0,0],[0,1],[1,0],[1,1]],\"tee\":[[0,0],[0,1],[0,2],[1,1]],\"ell\":[[0,0],[1,0],[2,0],[2,1]]},\"start\":[0,0],\"goal\":[3,4]};\n\/* ---------- One Way or Another: pack, then slide ---------- *\/\n(function(){\nvar W=D.w, H=D.h, ORDER=D.order, SHAPES=D.shapes;\nvar START=D.start, GOAL=D.goal, S=10;\nvar slideFrom=null;         \/* where the disc stood when the last piece went in *\/\nvar $=function(i){return document.getElementById(i);};\nvar NS=\"http:\/\/www.w3.org\/2000\/svg\";\nvar phase=\"pack\", placed={}, shapeOf={}, tray={}, disc=null, msg=\"\";\nvar drag=null, svgEl=null, picked=null;\nvar COL={tromino:\"#2E93C4\",square:\"#17678F\",tee:\"#4FAAD0\",ell:\"#0F4D69\"};\nvar LIGHT={tromino:\"#58B3DD\",square:\"#2E88B2\",tee:\"#78C6E4\",ell:\"#2A6E8E\"};\n\nfunction norm(cs){\n  var r0=Math.min.apply(null,cs.map(function(c){return c[0];}));\n  var c0=Math.min.apply(null,cs.map(function(c){return c[1];}));\n  return cs.map(function(c){return [c[0]-r0,c[1]-c0];});\n}\nfunction rotate(cs){ return norm(cs.map(function(c){ return [c[1],-c[0]]; })); }\nfunction flipped(cs){ return norm(cs.map(function(c){ return [c[0],-c[1]]; })); }\nfunction occupied(skip){\n  var o={};\n  for(var k in placed){\n    if(k===skip) continue;\n    placed[k].forEach(function(c){ o[c[0]+\",\"+c[1]]=k; });\n  }\n  if(disc \u0026\u0026 skip!==\"disc\") o[disc[0]+\",\"+disc[1]]=\"disc\";\n  return o;\n}\nfunction inside(cs){\n  return cs.every(function(c){ return c[0]\u003e=0\u0026\u0026c[0]\u003cH\u0026\u0026c[1]\u003e=0\u0026\u0026c[1]\u003cW; });\n}\nfunction fits(name,cells){\n  if(!inside(cells)) return false;\n  var occ=occupied(name);\n  for(var i=0;i\u003ccells.length;i++) if(occ[cells[i][0]+\",\"+cells[i][1]]) return false;\n  return true;\n}\nfunction reset(){\n  phase=\"pack\"; placed={}; shapeOf={}; disc=START.slice(); drag=null; picked=null;\n  slideFrom=null;\n  tray={}; ORDER.forEach(function(n){ tray[n]=SHAPES[n].map(function(c){return c.slice();}); });\n  msg=\"Click a piece then click the tray, or just drag it in. The disc moves too - drag it, or click it and click where it should go.\";\n  draw();\n}\nfunction packed(){ return ORDER.every(function(n){ return !!placed[n]; }); }\nfunction atGoal(p){ return p[0]===GOAL[0] \u0026\u0026 p[1]===GOAL[1]; }\nfunction setDisc(p){\n  disc=[p[0],p[1]];\n  \/* leaving the target square gives the disc a run to make, so a player who\n     packed with it already home only has to move it off and bring it back *\/\n  if(phase===\"slide\" \u0026\u0026 !atGoal(disc)) slideFrom=disc.slice();\n}\n\/* The disc roams while you pack, so parking it on the far square and then\n   packing around it is not a solved puzzle - it still has to make the trip. *\/\nfunction won(){ return phase===\"slide\" \u0026\u0026 atGoal(disc) \u0026\u0026 !atGoal(slideFrom||START); }\n\n\/* ---------- solid outlines ---------- *\/\nfunction outline(cells){\n  \/* Draw the piece as one shape. Rendering cell by cell left seams across the\n     middle of every piece, which made them hard to read as single objects. *\/\n  var has={}; cells.forEach(function(c){ has[c[0]+\",\"+c[1]]=1; });\n  var seg=[];\n  cells.forEach(function(c){\n    var r=c[0], k=c[1];\n    if(!has[(r-1)+\",\"+k]) seg.push([[k,r],[k+1,r]]);\n    if(!has[(r+1)+\",\"+k]) seg.push([[k,r+1],[k+1,r+1]]);\n    if(!has[r+\",\"+(k-1)]) seg.push([[k,r],[k,r+1]]);\n    if(!has[r+\",\"+(k+1)]) seg.push([[k+1,r],[k+1,r+1]]);\n  });\n  return seg;\n}\nfunction loops(cells){\n  \/* Chain the boundary segments into closed rings. A single path per piece is\n     what lets the corners round and the shadow sit under the whole shape,\n     instead of each cell being its own little square. *\/\n  var segs=outline(cells).map(function(e){ return [e[0].slice(),e[1].slice()]; });\n  var out=[];\n  while(segs.length){\n    var ring=[segs[0][0],segs[0][1]]; segs.splice(0,1);\n    var guard=0;\n    while(guard++\u003c400){\n      var head=ring[ring.length-1], found=-1;\n      for(var i=0;i\u003csegs.length;i++){\n        if(segs[i][0][0]===head[0]\u0026\u0026segs[i][0][1]===head[1]){ ring.push(segs[i][1]); found=i; break; }\n        if(segs[i][1][0]===head[0]\u0026\u0026segs[i][1][1]===head[1]){ ring.push(segs[i][0]); found=i; break; }\n      }\n      if(found\u003c0) break;\n      segs.splice(found,1);\n      var a=ring[0], b=ring[ring.length-1];\n      if(a[0]===b[0]\u0026\u0026a[1]===b[1]){ ring.pop(); break; }\n    }\n    if(ring.length\u003e2) out.push(ring);\n  }\n  return out;\n}\nfunction roundedPath(ring,r){\n  \/* walk the ring, cutting each corner with a quadratic *\/\n  var d=\"\", n=ring.length;\n  for(var i=0;i\u003cn;i++){\n    var p0=ring[(i-1+n)%n], p1=ring[i], p2=ring[(i+1)%n];\n    var v1=[p1[0]-p0[0],p1[1]-p0[1]], v2=[p2[0]-p1[0],p2[1]-p1[1]];\n    var l1=Math.hypot(v1[0],v1[1])||1, l2=Math.hypot(v2[0],v2[1])||1;\n    var rr=Math.min(r,l1\/2,l2\/2);\n    var a=[p1[0]-v1[0]\/l1*rr, p1[1]-v1[1]\/l1*rr];\n    var b=[p1[0]+v2[0]\/l2*rr, p1[1]+v2[1]\/l2*rr];\n    d += (i===0 ? \"M\"+a[0].toFixed(2)+\" \"+a[1].toFixed(2)\n                : \"L\"+a[0].toFixed(2)+\" \"+a[1].toFixed(2));\n    d += \"Q\"+p1[0].toFixed(2)+\" \"+p1[1].toFixed(2)+\" \"+b[0].toFixed(2)+\" \"+b[1].toFixed(2);\n  }\n  return d+\"Z\";\n}\nfunction svg(t,a){ var e=document.createElementNS(NS,t);\n  for(var k in a) e.setAttribute(k,a[k]); return e; }\nfunction pieceNode(name,cells,opts){\n  var g=svg(\"g\",{style:\"cursor:grab;touch-action:none\"});\n  g.setAttribute(\"data-p\",name);\n  var rings=loops(cells).map(function(ring){\n    return roundedPath(ring.map(function(p){ return [p[0]*S,p[1]*S]; }), S*0.17);\n  });\n  var d=rings.join(\" \");\n  if(!opts.ghost){\n    g.appendChild(svg(\"path\",{d:d,fill:\"rgba(18,32,40,.22)\",transform:\"translate(0.5,0.9)\",\n      filter:\"url(#owSoft)\"}));\n  }\n  g.appendChild(svg(\"path\",{d:d,fill:\"url(#ow_\"+name+\")\",\n    \"fill-opacity\":opts.ghost?\".45\":\"1\",\n    stroke:opts.bad?\"#C2544C\":(opts.sel?\"#0B7FA8\":\"rgba(10,26,34,.42)\"),\n    \"stroke-width\":opts.sel?\"1.1\":\".45\",\"stroke-linejoin\":\"round\"}));\n  if(!opts.ghost){\n    g.appendChild(svg(\"path\",{d:d,fill:\"none\",stroke:\"rgba(255,255,255,.34)\",\n      \"stroke-width\":\".5\",\"stroke-linejoin\":\"round\",transform:\"translate(0,0.45)\",\n      \"clip-path\":\"url(#owClip_\"+name+\")\"}));\n  }\n  return g;\n}\n\/* ---------- drawing ---------- *\/\nfunction syncButtons(){\n  var t=$(\"owTake\");\n  if(t) t.disabled = !(phase===\"slide\" \u0026\u0026 picked \u0026\u0026 placed[picked]);\n}\nfunction draw(){\n  var s=svg(\"svg\",{viewBox:(-PAD)+\" \"+(-PAD)+\" \"+(W*S+PAD*2)+\" \"+(H*S+PAD*2),\n    width:\"100%\",height:\"100%\",style:\"touch-action:none\"});\n  var defs=svg(\"defs\",{});\n  var grads=\"\";\n  for(var nm in COL){\n    grads+='\u003clinearGradient id=\"ow_'+nm+'\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"\u003e'\n      +'\u003cstop offset=\"0\" stop-color=\"'+LIGHT[nm]+'\"\/\u003e'\n      +'\u003cstop offset=\"1\" stop-color=\"'+COL[nm]+'\"\/\u003e\u003c\/linearGradient\u003e';\n  }\n  defs.innerHTML=grads\n    +'\u003cfilter id=\"owSoft\" x=\"-20%\" y=\"-20%\" width=\"140%\" height=\"140%\"\u003e'\n    +'\u003cfeGaussianBlur stdDeviation=\"0.5\"\/\u003e\u003c\/filter\u003e'\n    +'\u003cfilter id=\"owGrain\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\"\u003e'\n    +'\u003cfeTurbulence type=\"fractalNoise\" baseFrequency=\"0.9\" numOctaves=\"3\" seed=\"4\"\/\u003e'\n    +'\u003cfeColorMatrix type=\"saturate\" values=\"0\"\/\u003e'\n    +'\u003cfeComponentTransfer\u003e\u003cfeFuncA type=\"discrete\" tableValues=\"0 0 0 0 .5\"\/\u003e'\n    +'\u003c\/feComponentTransfer\u003e\u003c\/filter\u003e'\n    +'\u003cradialGradient id=\"owDisc\" cx=\"0.35\" cy=\"0.3\" r=\"0.8\"\u003e'\n    +'\u003cstop offset=\"0\" stop-color=\"#3E63D8\"\/\u003e\u003cstop offset=\"1\" stop-color=\"#15308C\"\/\u003e'\n    +'\u003c\/radialGradient\u003e';\n  s.appendChild(defs);\n  \/* the tray: a speckled rim with a recessed floor, like the printed one *\/\n  s.appendChild(svg(\"rect\",{x:-PAD,y:-PAD,width:W*S+PAD*2,height:H*S+PAD*2,rx:\"3\",fill:\"#EDEAE3\"}));\n  s.appendChild(svg(\"rect\",{x:-PAD,y:-PAD,width:W*S+PAD*2,height:H*S+PAD*2,rx:\"3\",\n    fill:\"#8A8275\",\"fill-opacity\":\".5\",filter:\"url(#owGrain)\"}));\n  s.appendChild(svg(\"rect\",{x:-0.6,y:-0.6,width:W*S+1.2,height:H*S+1.2,rx:\"1.6\",\n    fill:\"#F6F4EF\",stroke:\"rgba(80,74,64,.30)\",\"stroke-width\":\".5\"}));\n  s.appendChild(svg(\"rect\",{x:-0.6,y:-0.6,width:W*S+1.2,height:H*S+1.2,rx:\"1.6\",\n    fill:\"#8A8275\",\"fill-opacity\":\".28\",filter:\"url(#owGrain)\"}));\n  s.appendChild(svg(\"rect\",{x:GOAL[1]*S+1.4,y:GOAL[0]*S+1.4,width:S-2.8,height:S-2.8,rx:\"1.4\",\n    fill:\"none\",stroke:\"#0B7FA8\",\"stroke-opacity\":\".75\",\"stroke-width\":\".65\",\n    \"stroke-dasharray\":\"1.8 1.4\"}));\n  ORDER.forEach(function(n){\n    if(!placed[n]) return;\n    if(drag\u0026\u0026drag.name===n\u0026\u0026drag.live) return;      \/* drawn as the ghost instead *\/\n    s.appendChild(pieceNode(n,placed[n],{sel:picked===n}));\n  });\n  if(disc \u0026\u0026 !(drag\u0026\u0026drag.name===\"disc\"\u0026\u0026drag.live)){\n    s.appendChild(svg(\"circle\",{cx:disc[1]*S+S\/2+0.5,cy:disc[0]*S+S\/2+0.9,r:S*0.36,\n      fill:\"rgba(18,32,40,.26)\",filter:\"url(#owSoft)\",\"pointer-events\":\"none\"}));\n    var d=svg(\"circle\",{cx:disc[1]*S+S\/2,cy:disc[0]*S+S\/2,r:S*0.36,\n      fill:\"url(#owDisc)\",stroke:picked===\"disc\"?\"#0B7FA8\":\"rgba(8,20,60,.5)\",\n      \"stroke-width\":picked===\"disc\"?\".9\":\".4\",style:\"cursor:pointer\"});\n    d.setAttribute(\"data-p\",\"disc\");\n    d.setAttribute(\"style\",\"touch-action:none\");\n    s.appendChild(d);\n    \/* the sheen is decoration: it must not swallow the click meant for the disc *\/\n    s.appendChild(svg(\"ellipse\",{cx:disc[1]*S+S\/2-S*0.1,cy:disc[0]*S+S\/2-S*0.13,\n      rx:S*0.15,ry:S*0.09,fill:\"rgba(255,255,255,.28)\",\"pointer-events\":\"none\"}));\n  }\n  if(drag\u0026\u0026drag.live){\n    if(drag.name===\"disc\"){\n      var dc=(drag.cells\u0026\u0026drag.cells[0])||disc;\n      s.appendChild(svg(\"circle\",{cx:dc[1]*S+S\/2,cy:dc[0]*S+S\/2,r:S*0.36,\n        fill:\"#1B3FAE\",\"fill-opacity\":\".78\",stroke:\"#0B7FA8\",\"stroke-width\":\".7\"}));\n    } else {\n      s.appendChild(pieceNode(drag.name,drag.cells,{ghost:true,bad:!drag.ok,sel:true}));\n    }\n  }\n  svgEl=s;\n  $(\"owBoard\").innerHTML=\"\"; $(\"owBoard\").appendChild(s);\n  wire(s);\n  syncButtons();\n  drawTray();\n  $(\"owSay\").textContent = won()? \"The disc is across. That is the whole puzzle.\" : msg;\n  $(\"owPhase\").textContent = phase===\"pack\" ? \"Step one: pack the tray\"\n                                            : \"Step two: move the disc\";\n}\nfunction drawTray(){\n  var box=$(\"owTray\"); box.innerHTML=\"\";\n  ORDER.forEach(function(n){\n    if(!tray[n]) return;\n    var cs=tray[n];\n    var hh=Math.max.apply(null,cs.map(function(c){return c[0];}))+1;\n    var ww=Math.max.apply(null,cs.map(function(c){return c[1];}))+1;\n    var s=svg(\"svg\",{viewBox:\"-.6 -.6 \"+(ww*S+1.2)+\" \"+(hh*S+1.2),\n      width:(ww*19)+\"px\",height:(hh*19)+\"px\",style:\"cursor:grab;touch-action:none\"});\n    s.appendChild(pieceNode(n,cs,{sel:picked===n}));\n    if(picked===n) s.style.outline=\"2px solid #0B7FA8\";\n    s.style.outlineOffset=\"2px\"; s.style.borderRadius=\"4px\";\n    s.addEventListener(\"pointerdown\",function(e){ startDrag(n,cs,e,true); });\n    box.appendChild(s);\n  });\n  if(!Object.keys(tray).length) box.innerHTML='\u003cspan class=\"empty\"\u003eAll packed\u003c\/span\u003e';\n}\n\/* ---------- dragging ---------- *\/\nvar PAD=3;                                   \/* the tray rim, in view units *\/\nfunction cellAt(ev){\n  \/* Derived from the viewBox rather than hardcoded. Adding the rim changed the\n     viewBox from -1 to -3 and this kept using the old numbers, so every\n     pointer position mapped to the wrong square. *\/\n  var b=svgEl.getBoundingClientRect();\n  var vw=W*S+PAD*2, vh=H*S+PAD*2;\n  var vx=-PAD+((ev.clientX-b.left)\/b.width)*vw;\n  var vy=-PAD+((ev.clientY-b.top)\/b.height)*vh;\n  return [Math.floor(vy\/S), Math.floor(vx\/S)];\n}\nfunction originOf(cells){\n  return [Math.min.apply(null,cells.map(function(c){return c[0];})),\n          Math.min.apply(null,cells.map(function(c){return c[1];}))];\n}\nfunction startDrag(name,cells,ev,fromRack){\n  ev.preventDefault();\n  var base=norm(cells.map(function(c){return c.slice();}));\n  var anchor=fromRack?[0,0]:null;\n  drag={name:name,base:base,fromRack:fromRack,live:false,cells:cells,ok:true,anchor:anchor};\n  if(!fromRack \u0026\u0026 name!==\"disc\" \u0026\u0026 placed[name]){\n    \/* which square of the piece the pointer came down on, so the piece follows\n       the hand instead of assuming it was grabbed by its first cell *\/\n    var gc=cellAt(ev), og=originOf(placed[name]);\n    drag.grab=[gc[0]-og[0], gc[1]-og[1]];\n  }\n  if(!fromRack\u0026\u0026name!==\"disc\"){\n    drag.start=cells.map(function(c){return c.slice();});\n  }\n  window.addEventListener(\"pointermove\",onMove);\n  window.addEventListener(\"pointerup\",onUp);\n  window.addEventListener(\"pointercancel\",onCancel);\n}\nfunction onCancel(){\n  window.removeEventListener(\"pointermove\",onMove);\n  window.removeEventListener(\"pointerup\",onUp);\n  window.removeEventListener(\"pointercancel\",onCancel);\n  if(!drag) return;\n  var d=drag; drag=null;\n  if(d.restore){                     \/* it was lifted off the board - put it back *\/\n    placed[d.name]=d.restore.cells; shapeOf[d.name]=d.restore.shape; delete tray[d.name];\n  }\n  picked=null; draw();\n}\nfunction onMove(ev){\n  if(!drag||!svgEl) return;\n  var rc=cellAt(ev);\n  drag.live=true;\n  if(drag.name===\"disc\"){\n    \/* the disc never jumps: it only follows as far as empty squares reach *\/\n    var occ=occupied(\"disc\");\n    if(rc[0]\u003e=0\u0026\u0026rc[0]\u003cH\u0026\u0026rc[1]\u003e=0\u0026\u0026rc[1]\u003cW\u0026\u0026!occ[rc[0]+\",\"+rc[1]]\n       \u0026\u0026reachable(disc,rc,occ)) drag.cells=[rc];\n    else if(!drag.cells) drag.cells=[disc.slice()];\n    drag.ok=true; draw(); return;\n  }\n  if(phase===\"pack\"||drag.fromRack){\n    var cells=drag.base.map(function(c){ return [c[0]+rc[0],c[1]+rc[1]]; });\n    drag.cells=cells; drag.ok=fits(drag.name,cells);\n  } else {\n    \/* sliding: step toward the pointer, pushing anything in the way *\/\n    var guard=0, grab=drag.grab||[0,0];\n    while(guard++\u003c12){\n      var cur=originOf(placed[drag.name]);\n      var want=[rc[0]-grab[0], rc[1]-grab[1]];\n      var dr=Math.sign(want[0]-cur[0]), dc=Math.sign(want[1]-cur[1]);\n      if(!dr\u0026\u0026!dc) break;\n      \/* try the bigger pull first, then the other axis, so a mostly sideways\n         drag is not abandoned just because the vertical step is blocked *\/\n      var tries=(Math.abs(want[0]-cur[0])\u003e=Math.abs(want[1]-cur[1]))\n        ? [[dr,0],[0,dc]] : [[0,dc],[dr,0]];\n      var mv=null, step=null;\n      for(var ti=0;ti\u003ctries.length;ti++){\n        var t=tries[ti];\n        if(!t[0]\u0026\u0026!t[1]) continue;\n        mv=chainMove(drag.name,t[0],t[1]);\n        if(mv){ step=t; break; }\n      }\n      if(!mv) break;\n      applyChain(mv,step[0],step[1]);\n      if(Object.keys(mv).length\u003e1) msg=\"Pushed \"+(Object.keys(mv).length-1)\n        +\" piece\"+(Object.keys(mv).length\u003e2?\"s\":\"\")+\" along.\";\n    }\n    drag.cells=placed[drag.name].map(function(c){return c.slice();});\n    drag.ok=true;\n  }\n  draw();\n}\nfunction onUp(){\n  window.removeEventListener(\"pointermove\",onMove);\n  window.removeEventListener(\"pointerup\",onUp);\n  window.removeEventListener(\"pointercancel\",onCancel);\n  if(!drag){ return; }\n  var d=drag; drag=null;\n  if(!d.live){\n    \/* a tap, not a drag *\/\n    if(d.name===\"disc\"){\n      picked=(picked===\"disc\")?null:\"disc\";\n      msg=(picked===\"disc\")?\"Disc picked up. Click an empty square to send it there.\":\"\";\n      draw(); return;\n    }\n    if(d.fromRack){ picked=d.name; }           \/* hold it until the tray is tapped *\/\n    else if(phase===\"slide\"){\n      if(picked===d.name){ picked=null; msg=\"\"; }\n      else {\n        picked=d.name;\n        msg=\"Tap a square to nudge it that way, or drag it. \"\n           +\"Take out puts it back in the tray.\";\n      }\n    }\n    draw(); return;\n  }\n  if(d.live){\n    picked=null;\n    if(d.name===\"disc\"){\n      var t=d.cells\u0026\u0026d.cells[0];\n      var occ3=occupied(\"disc\");\n      if(t\u0026\u0026!occ3[t[0]+\",\"+t[1]]\u0026\u0026reachable(disc,t,occ3)){ setDisc(t); msg=\"\"; }\n      draw(); return;\n    }\n    if(phase===\"pack\"||d.fromRack){\n      if(d.ok){ placed[d.name]=d.cells; shapeOf[d.name]=d.base; delete tray[d.name];\n        msg = packed()? \"\" : \"\";\n        if(packed()){ phase=\"slide\"; slideFrom=disc.slice();\n          msg = atGoal(disc)\n            ? \"Packed, but the disc is already sitting on its target. Start it \"\n              +\"somewhere else so it has a run to make.\"\n            : \"Packed. Drag the disc, or click it and click where it should go. \"\n              +\"Arrow keys work too. Click a piece to take it back out.\"; }\n      } else { msg=\"That will not fit there.\"; }\n    }\n  }\n  draw();\n}\nfunction discStep(dr,dc){\n  var n=[disc[0]+dr,disc[1]+dc];\n  if(n[0]\u003c0||n[0]\u003e=H||n[1]\u003c0||n[1]\u003e=W) return false;\n  var occ=occupied(\"disc\");\n  if(occ[n[0]+\",\"+n[1]]){ msg=\"The disc is blocked. Drag a piece out of its way.\"; return false; }\n  setDisc(n); msg=\"\"; return true;\n}\nfunction occupantAt(cell,movers){\n  var k=cell[0]+\",\"+cell[1];\n  for(var n in placed){\n    if(movers[n]) continue;\n    for(var i=0;i\u003cplaced[n].length;i++)\n      if(placed[n][i][0]===cell[0]\u0026\u0026placed[n][i][1]===cell[1]) return n;\n  }\n  if(!movers.disc \u0026\u0026 disc \u0026\u0026 disc[0]===cell[0] \u0026\u0026 disc[1]===cell[1]) return \"disc\";\n  return null;\n}\nfunction stepToward(name,rc){\n  var cs=placed[name];\n  var rs=cs.map(function(c){return c[0];}), cl=cs.map(function(c){return c[1];});\n  var top=Math.min.apply(null,rs), bot=Math.max.apply(null,rs);\n  var lef=Math.min.apply(null,cl), rig=Math.max.apply(null,cl);\n  var dr=rc[0]\u003ctop?-1:(rc[0]\u003ebot?1:0);\n  var dc=rc[1]\u003clef?-1:(rc[1]\u003erig?1:0);\n  if(!dr\u0026\u0026!dc) return false;\n  \/* the bigger offset first, then the other axis, so a tap that is mostly\n     sideways still moves the piece when the vertical step is blocked *\/\n  var dRow=Math.min(Math.abs(rc[0]-top),Math.abs(rc[0]-bot));\n  var dCol=Math.min(Math.abs(rc[1]-lef),Math.abs(rc[1]-rig));\n  var tries=(dRow\u003e=dCol)?[[dr,0],[0,dc]]:[[0,dc],[dr,0]];\n  for(var i=0;i\u003ctries.length;i++){\n    var t=tries[i];\n    if(!t[0]\u0026\u0026!t[1]) continue;\n    var mv=chainMove(name,t[0],t[1]);\n    if(mv){\n      applyChain(mv,t[0],t[1]);\n      msg = Object.keys(mv).length\u003e1\n        ? \"Pushed \"+(Object.keys(mv).length-1)+\" along.\"\n        : \"\";\n      return true;\n    }\n  }\n  msg=\"That piece has nowhere to go that way.\";\n  return false;\n}\nfunction chainMove(name,dr,dc){\n  \/* Slide one piece into another and the second one goes too, as long as it\n     has somewhere to go. The push carries on down the line, and the disc gets\n     shoved along with everything else, the way a loose disc in a tray would. *\/\n  var movers={}; movers[name]=1;\n  var queue=[name], guard=0;\n  while(queue.length \u0026\u0026 guard++\u003c30){\n    var n=queue.shift();\n    var cells=(n===\"disc\")?[disc]:placed[n];\n    for(var i=0;i\u003ccells.length;i++){\n      var t=[cells[i][0]+dr, cells[i][1]+dc];\n      if(t[0]\u003c0||t[0]\u003e=H||t[1]\u003c0||t[1]\u003e=W) return null;   \/* the tray wall stops it *\/\n      var occ=occupantAt(t,movers);\n      if(occ){ movers[occ]=1; queue.push(occ); }\n    }\n  }\n  if(queue.length) return null;\n  return movers;\n}\nfunction applyChain(movers,dr,dc){\n  for(var n in movers){\n    if(n===\"disc\"){ setDisc([disc[0]+dr, disc[1]+dc]); continue; }\n    placed[n]=placed[n].map(function(c){ return [c[0]+dr,c[1]+dc]; });\n  }\n}\nfunction reachable(from,to,occ){\n  \/* the disc travels through empty squares, it never jumps over a piece *\/\n  var seen={}, q=[from]; seen[from[0]+\",\"+from[1]]=1;\n  while(q.length){\n    var c=q.shift();\n    if(c[0]===to[0]\u0026\u0026c[1]===to[1]) return true;\n    var ds=[[1,0],[-1,0],[0,1],[0,-1]];\n    for(var i=0;i\u003cds.length;i++){\n      var n=[c[0]+ds[i][0],c[1]+ds[i][1]], k=n[0]+\",\"+n[1];\n      if(n[0]\u003c0||n[0]\u003e=H||n[1]\u003c0||n[1]\u003e=W||seen[k]||occ[k]) continue;\n      seen[k]=1; q.push(n);\n    }\n  }\n  return false;\n}\nfunction wire(s){\n  \/* Swiping the board walks the disc, so once everything is packed you can\n     play with flicks or the arrow keys and never have to grab the disc itself. *\/\n  s.addEventListener(\"click\",function(ev){\n    \/* Picking the disc up happens in onUp - see the tap branch there. The disc is\n       loose in the tray from the start, so it answers to clicks while you are\n       still packing, not only once the last piece is in. *\/\n    if(picked===\"disc\"){\n      var rc2=cellAt(ev);\n      var occ2=occupied(\"disc\");\n      if(rc2[0]\u003c0||rc2[0]\u003e=H||rc2[1]\u003c0||rc2[1]\u003e=W) return;\n      if(rc2[0]===disc[0]\u0026\u0026rc2[1]===disc[1]) return;   \/* the tap that picked it up *\/\n      if(occ2[rc2[0]+\",\"+rc2[1]]){ msg=\"Something is already there.\"; draw(); return; }\n      if(reachable(disc,rc2,occ2)){ setDisc(rc2); picked=null; msg=\"\"; }\n      else msg=\"No clear run of empty squares that way.\";\n      draw(); return;\n    }\n    if(phase===\"slide\"){\n      if(picked\u0026\u0026placed[picked]){\n        var rcp=cellAt(ev);\n        if(rcp[0]\u003c0||rcp[0]\u003e=H||rcp[1]\u003c0||rcp[1]\u003e=W) return;\n        stepToward(picked,rcp); draw();\n      }\n      return;\n    }\n    if(!picked||!tray[picked]) return;\n    var rc=cellAt(ev);\n    var base=norm(tray[picked].map(function(c){return c.slice();}));\n    var cells=base.map(function(c){ return [c[0]+rc[0],c[1]+rc[1]]; });\n    if(fits(picked,cells)){\n      placed[picked]=cells; shapeOf[picked]=base; delete tray[picked];\n      picked=null;\n      if(packed()){ phase=\"slide\"; slideFrom=disc.slice();\n        msg = atGoal(disc)\n          ? \"Packed, but the disc is already sitting on its target. Start it \"\n            +\"somewhere else so it has a run to make.\"\n          : \"Packed. Arrow keys or a swipe move the disc. Drag a piece to shift it.\"; }\n      else msg=\"\";\n    } else msg=\"That will not fit there.\";\n    draw();\n  });\n  var sw=null;\n  s.addEventListener(\"pointerdown\",function(ev){\n    \/* a swipe may start on the disc too - only a piece takes priority *\/\n    var hit=ev.target.closest\u0026\u0026ev.target.closest(\"[data-p]\");\n    if(hit\u0026\u0026hit.getAttribute(\"data-p\")!==\"disc\") return;\n    sw={x:ev.clientX,y:ev.clientY};\n  });\n  s.addEventListener(\"pointerup\",function(ev){\n    if(!sw) return;\n    var dx=ev.clientX-sw.x, dy=ev.clientY-sw.y; sw=null;\n    if(Math.abs(dx)\u003c12\u0026\u0026Math.abs(dy)\u003c12) return;\n    var step=Math.abs(dx)\u003eMath.abs(dy) ? [0,dx\u003e0?1:-1] : [dy\u003e0?1:-1,0];\n    var n=Math.max(1,Math.round(Math.max(Math.abs(dx),Math.abs(dy))\n          \/(s.getBoundingClientRect().width\/W)));\n    for(var k=0;k\u003cn;k++) if(!discStep(step[0],step[1])) break;\n    draw();\n  });\n  Array.prototype.forEach.call(s.querySelectorAll(\"[data-p]\"),function(e){\n    e.addEventListener(\"pointerdown\",function(ev){\n      var n=e.getAttribute(\"data-p\");\n      if(n===\"disc\"){\n        \/* a piece in hand wants to be placed, so let the click fall through\n           to the tray and report that the disc's square is taken *\/\n        if(picked\u0026\u0026picked!==\"disc\"\u0026\u0026tray[picked]) return;\n        startDrag(\"disc\",[disc.slice()],ev,false); return;\n      }\n      if(phase===\"pack\"){\n        var wasAt=placed[n], wasShape=shapeOf[n];\n        tray[n]=shapeOf[n]; delete placed[n]; delete shapeOf[n];\n        startDrag(n,tray[n],ev,true);\n        if(drag) drag.restore={cells:wasAt,shape:wasShape};\n      } else startDrag(n,placed[n],ev,false);\n    });\n  });\n}\ndocument.addEventListener(\"keydown\",function(e){\n  var d={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];\n  if(!d) return;\n  e.preventDefault();\n  if(phase===\"slide\"\u0026\u0026picked\u0026\u0026placed[picked]){\n    var mv=chainMove(picked,d[0],d[1]);\n    if(mv){ applyChain(mv,d[0],d[1]); msg=\"\"; }\n    else msg=\"That piece has nowhere to go that way.\";\n  } else discStep(d[0],d[1]);\n  draw();\n});\n$(\"owRotate\").addEventListener(\"click\",function(){\n  var n=(picked\u0026\u0026tray[picked])?picked:Object.keys(tray)[0];\n  if(n){ tray[n]=rotate(tray[n]); draw(); }\n});\n$(\"owFlip\").addEventListener(\"click\",function(){\n  var n=(picked\u0026\u0026tray[picked])?picked:Object.keys(tray)[0];\n  if(n){ tray[n]=flipped(tray[n]); draw(); }\n});\nfunction backToPack(){\n  \/* The disc stays exactly where it is. Taking a piece out is a way to free it\n     up, so sending it home would undo the run you were in the middle of. *\/\n  phase=\"pack\";\n  slideFrom=null;\n}\nvar takeBtn=$(\"owTake\");\nif(takeBtn) takeBtn.addEventListener(\"click\",function(){\n  if(phase!==\"slide\"||!picked||!placed[picked]) return;\n  tray[picked]=shapeOf[picked];\n  delete placed[picked]; delete shapeOf[picked];\n  backToPack();\n  msg=\"Took that piece out. Place it again when you are ready.\";\n  draw();\n});\nvar emptyBtn=$(\"owUnpack\");\nif(emptyBtn) emptyBtn.addEventListener(\"click\",function(){\n  ORDER.forEach(function(n){\n    if(!placed[n]) return;\n    tray[n]=shapeOf[n];\n    delete placed[n]; delete shapeOf[n];\n  });\n  backToPack(); picked=null;\n  msg=\"Tray emptied. Pack it again however you like.\";\n  draw();\n});\n$(\"owReset\").addEventListener(\"click\",reset);\nreset();\n})();\n\n})();\n\u003c\/script\u003e\n\n\n\n\n\n\n\u003cp\u003ePut the disc in one corner. Pack the pieces in around it. Now slide them until the disc comes out in the opposite corner.\u003c\/p\u003e\n\u003cp\u003eGoal: fit every piece into the tray so one corner stays free for the disc, then move the disc to the diagonally opposite corner using sliding moves alone.\u003c\/p\u003e\n\u003cp\u003eAlexander Magyarics took a tray packing puzzle and gave it somewhere to go. Finding an arrangement that fits is the easy half. Finding the one that also leaves the disc a path across the tray is the part worth owning. It earned a Jury Honorable Mention at the 2026 Nob Yoshigahara Puzzle Design Competition in Assisi.\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eWhat's special about One Way or Another?\u003c\/strong\u003e\u003c\/p\u003e\n\u003cul\u003e\n\u003cli\u003eUnique puzzle in one tray: pack it, then slide to create a path\u003c\/li\u003e\n\u003cli\u003eJury Honorable Mention, 2026 Nob Yoshigahara Puzzle Design Competition\u003c\/li\u003e\n\u003cli\u003eFlat and light enough to take with you\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003eBest for: packing puzzle fans who have run out of tray puzzles that still surprise them, and gift buyers after a small desk puzzle with a real idea behind it.\u003c\/p\u003e\n\u003cp\u003eDesigned by \u003ca href=\"\/he\/collections\/alexander-magyarics\"\u003eAlexander Magyarics\u003c\/a\u003e\u003c\/p\u003e","brand":"Greg Puzzles","offers":[{"title":"Default Title","offer_id":51517396910247,"sku":"GP-ONEWAY","price":16.0,"currency_code":"USD","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0668\/2827\/1783\/files\/one_way_or_another___move_the_disc_corne_marble.png?v=1792040466","url":"https:\/\/gregpuzzles.com\/he\/products\/one-way-or-another-move-the-disc-corner-to-corner","provider":"Greg Puzzles","version":"1.0","type":"link"}