source("http://macosa.dima.unige.it/r.R")    # If I have not already loaded the library
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

# A polyomino (word derived from "domino", the tile-based game) is a plane figure
# formed by joining equal squares edge to edge. A pentòmino is formed by 5 squares.
# There are 12 pentominoes, 16 if we consider their possible refletions.
# They can be named using letters of the Latin alphabet:

         

# There are various games based on pentominoes, described in the chapter below taken
# from a book by Martin Gardner.
# They can be plotted in R using:

# The coordinates of the "letters" placed in rectangles with low and left ends placed
# in (0,0)
Nx=c(0,2,2,4,4,1,1,0,0);Ny=c(0,0,1,1,2,2,1,1,0)
Tx=c(1,2,2,3,3,0,0,1,1);Ty=c(0,0,2,2,3,3,2,2,0)
Fx=c(1,2,2,3,3,1,1,0,0,1,1);Fy=c(0,0,2,2,3,3,2,2,1,1,0)
Px=c(0,1,1,2,2,0,0);Py=c(0,0,1,1,3,3,0)
Vx=c(0,3,3,1,1,0,0);Vy=c(0,0,1,1,3,3,0)
Ix=c(0,1,1,0,0);Iy=c(0,0,5,5,0)
Yx=c(1,2,2,1,1,0,0,1,1);Yy=c(0,0,4,4,3,3,2,2,0)
Xx=c(1,2,2,3,3,2,2,1,1,0,0,1,1);Xy=c(0,0,1,1,2,2,3,3,2,2,1,1,0)
Ux=c(0,3,3,2,2,1,1,0,0);Uy=c(0,0,2,2,1,1,2,2,0)
Zx=c(1,3,3,2,2,0,0,1,1);Zy=c(0,0,1,1,3,3,2,2,0)
Lx=c(0,2,2,1,1,0,0);Ly=c(0,0,1,1,4,4,0)
Wx=c(1,3,3,2,2,1,1,0,0,1,1);Wy=c(0,0,1,1,2,2,3,3,1,1,0)
N1x=c(0,2,2,4,4,3,3,0,0);N1y=c(1,1,0,0,1,1,2,2,1)
F1x=c(0,1,1,2,2,3,3,2,2,0);F1y=c(2,2,0,0,1,1,2,2,3,3)
P1x=c(0,1,1,2,2,0,0);P1y=c(1,1,0,0,3,3,1)
Y1x=c(1,0,0,1,1,2,2,1,1);Y1y=c(0,0,4,4,3,3,2,2,0)
Z1x=c(0,2,2,3,3,1,1,0,0);Z1y=c(3,3,1,1,0,0,2,2,3)
L1x=c(0,2,2,1,1,0,0);L1y=c(0,0,4,4,1,1,0)
polymini0=function(x,y,Px,Py) {n=length(Px); px=NULL; py=NULL; for(i in 1:n)
 {px[i]=Px[i]+x;py[i]=Py[i]+y};polyC(px,py,"yellow")}
polymini1=function(x,y,Px,Py) {n=length(Px); px=NULL; py=NULL; for(i in 1:n)
 {px[i]=RotPx(Px[i],Py[i],90,0,0)+x;py[i]=RotPy(Px[i],Py[i],90,0,0)+y};polyC(px,py,"yellow")}
polymini2=function(x,y,Px,Py) {n=length(Px); px=NULL; py=NULL; for(i in 1:n)
 {px[i]=RotPx(Px[i],Py[i],180,0,0)+x;py[i]=RotPy(Px[i],Py[i],180,0,0)+y};polyC(px,py,"yellow")}
polymini3=function(x,y,Px,Py) {n=length(Px); px=NULL; py=NULL; for(i in 1:n)
 {px[i]=RotPx(Px[i],Py[i],270,0,0)+x;py[i]=RotPy(Px[i],Py[i],270,0,0)+y};polyC(px,py,"yellow")}
#

# Previous images:
BF=4; HF=4; PLANE(0,13,0,13)
polymini0(0,0,Ix,Iy); polymini0(2,0,Px,Py); polymini0(5,0,Lx,Ly); polymini0(7,0,Zx,Zy)
polymini0(10,0,Yx,Yy); polymini0(0,6,Tx,Ty); polymini0(3,5,Fx,Fy); polymini0(6,4,Xx,Xy)
polymini0(10,5,Ux,Uy); polymini0(0,10,Nx,Ny); polymini0(5,9,Wx,Wy); polymini0(9,9,Vx,Vy)
BF=4; HF=4; PLANE(0,13,0,13)
polymini0(0,0,P1x,P1y); polymini0(3,0,L1x,L1y); polymini0(6,0,Z1x,Z1y)
polymini0(10,0,Y1x,Y1y); polymini0(0,5,N1x,N1y); polymini0(5,4,F1x,F1y)
#
# images that can be printed and then cropped:
BF=6; HF=6; BOXW(0,13,0,13); GridHC(0:13,"red"); GridVC(0:13,"red")
polymini0(0,0,Ix,Iy); polymini0(2,0,Px,Py); polymini0(5,0,Lx,Ly); polymini0(7,0,Zx,Zy)
polymini0(10,0,Yx,Yy); polymini0(0,6,Tx,Ty); polymini0(3,5,Fx,Fy); polymini0(6,4,Xx,Xy)
polymini0(10,5,Ux,Uy); polymini0(0,10,Nx,Ny); polymini0(5,9,Wx,Wy); polymini0(9,9,Vx,Vy)
BF=6; HF=6; BOXW(0,13,0,13); GridHC(0:13,"red"); GridVC(0:13,"red")
polymini0(0,0,P1x,P1y); polymini0(3,0,L1x,L1y); polymini0(6,0,Z1x,Z1y)
polymini0(10,0,Y1x,Y1y); polymini0(0,5,N1x,N1y); polymini0(5,4,F1x,F1y)
#
# Some examples:
BF=3.5; HF=3.5; PLANE(-5,5,-5,5)
polymini0(0,0,F1x,F1y); polymini1(0,0,F1x,F1y); polymini2(0,0,F1x,F1y); polymini3(0,0,F1x,F1y)
BF=3.5; HF=3.5; PLANE(-5,5,-5,5)
polymini3(0,0,F1x,F1y); polymini3(-2,3,F1x,F1y)
BF=3.5; HF=3.5; PLANE(-2,8,-5,5)
polymini3(0,0,L1x,L1y); polymini3(4,5,L1x,L1y)
BF=3.5; HF=3.5; PLANE(-5,5,-5,5)
polymini2(0,0,Ux,Uy); polymini2(3,4,Ux,Uy)
# (the image first is rotated as indicated by 1,2 or 3 and then translated as indicated by x,y)

 
#
# The images of the game described in figure 76 of Gardner's book:

  


BF=1.5; HF=1.5; BOXW(0,8,0,8); GridHC(0:8,"red"); GridVC(0:8,"red")
polymini0(1,3,Xx,Xy)       # X, 1 on the right, 3 above
polymini0(2,5,Wx,Wy)       # W, 2 on the right, 5 above
polymini3(5,8,F1x,F1y)     # F1, rotated 90*3°, then 5 on the right, 8 above
polymini3(4,5,L1x,L1y)
polymini2(5,3,Nx,Ny)
polymini0(0,0,Ix,Iy)
polymini1(7,0,Vx,Vy)
polymini0(5,4,Ux,Uy)
polymini1(7,6,Yx,Yy)
polymini2(2,8,P1x,P1y)
#
# These examples are taken from the column that Martin Gardner held on Scientific American
# (or, better, from their reproduction in the book "Mathematical Magic Show").






back