Application Center - Maplesoft

App Preview:

Stones in a Square

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application




  Title: Stones in Square.mw

Author: Paul Weisenhorn

Objective: Place 8 objects in a 4x4 matrix in a way that:

   - every row and every column contains exactly 2 objects

   - one spot contains a maximum of one object

There are 90 different solutions

 

Please use the terminal to choose from the following output formats:

"1" Numerical output

"2" Graphic output

 

 

with(plots); p1 := array(0 .. 4); p2 := array(0 .. 4); p3 := array(0 .. 4); H := array(0 .. 91); M := [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]; w := plot([.5, 1.5, 2.5, 3.5, 4.5], x = .5 .. 4.5, color = black); v1 := plot([.5, .5], [.5, 4.5], color = black); v2 := plot([1.5, 1.5], [.5, 4.5], color = black); v3 := plot([2.5, 2.5], [.5, 4.5], color = black); v4 := plot([3.5, 3.5], [.5, 4.5], color = black); v5 := plot([4.5, 4.5], [.5, 4.5], color = black); test := true; s := 0; while test = true do g := readstat(terminal); if g = 1 or g = 2 or g = 3 then test := false end if end do; for j to 6 do for n to 4 do p1[n] := 0 end do; z1 := M[j][1]; p1[z1] := p1[z1]+1; z2 := M[j][2]; p1[z2] := p1[z2]+1; for k to 6 do for n to 4 do p2[n] := p1[n] end do; z1 := M[k][1]; p2[z1] := p2[z1]+1; z2 := M[k][2]; p2[z2] := p2[z2]+1; for i to 6 do for n to 4 do p3[n] := p2[n] end do; z1 := M[i][1]; z2 := M[i][2]; T := []; if p3[z1] < 2 and p3[z2] < 2 then p3[z1] := p3[z1]+1; p3[z2] := p3[z2]+1; for m to 4 do if p3[m] = 1 then T := [op(T), m] end if end do; if T <> [] then s := s+1; H[s] := [M[j], M[k], M[i], T]; if g = 1 then printf("%8d%s%a\n", s, "      ", H[s]) end if end if end if end do end do end do; if g = 2 then for u to 90 do t := []; for r to 4 do t1 := [r]; t1 := [op(t1), H[u][r][1]]; t2 := [r]; t2 := [op(t2), H[u][r][2]]; t := [op(t), t1, t2] end do; p := pointplot(t, style = point, symbolsize = 20, color = blue, axes = none); print(u); print(display(w, v1, v2, v3, v4, v5, p)) end do end if

NULL

NULL

 

``