%% This file is generated by preprocessor!
%% Do not edit it by hand.
%% Edit the source file cpp/pyramid.cpp.

\language{es}
\author{XIAO, Gang}
\email{xiao@unice.fr}
\computeanswer{no}
\format{html}
\precision{10000}
 \title{9: Pirámide IIb}
 \text{stage=2}
 \text{base=3}







\integer{tot=\base+1}


\integer{confparm1=\confparm1 issametext ?1}
\integer{confparm2=\confparm2 issametext ?0}
\text{vars=shuffle(a,b,c,d,r,s,t,x,y,z)}
\text{rt=sqrt(random(2,3,5))}
\text{list=wims(record \confparm1 of src/data)}
\text{nature=\list[1;]}
\text{parms=\list[2;]}
\text{smin=\list[3;1]}
\text{smax=\list[3;2]}
\integer{smean=(\smin+\smax)/2}
\text{obj=\parms[1]}
\text{sizex=\parms[2]}
\text{sizey=\parms[3]}
\text{sizex=\sizex =? 60}
\text{sizey=\sizey=? 35}
\text{size=\sizex \sizey}
\text{list=wims(rows2lines row(4..-1,\list))}
\integer{n=items(\list)}
\if{\n<=3}{
 \text{a=\list[1]}
 \text{b=\list[2]}
 \text{c=\list[3]}
 \text{randtype=computed}
 \if{\c<0}{
  \text{sh1=wims(values \c*x,-(\c)*x for x=\a to \b)}
 }{
  \text{sh1=wims(values \c*x for x=\a to \b)}
 }
 \text{list=\sh1}
}{
 \text{randtype=listed}
}
\text{list=wims(mathsubst f=\vars[1] in \list)}
\text{list=wims(mathsubst g=\vars[2] in \list)}
\text{list=wims(mathsubst rt=\rt in \list)}
\text{sh=item(1..\tot,shuffle(\list))}

\integer{Tot=(\stage+1)*(\stage+2)/2+(\base-\stage)*(\stage+1)}
\text{posx=}
\text{posy=}
\text{lcolor=black}
\text{py=line 0,\stage,(\base-\stage),\stage,\lcolor}
\integer{next=1}
\text{conds=}
\for{yy=\stage..0 step -1}{
 \integer{this=\next}
 \integer{next=\next+\base-\yy+1}
 \text{py=\yy<\stage?\py
polygon \lcolor,0,\yy}
 \for{xx=0..\base-\yy}{
  \text{conds=\yy>0?\conds \this+\xx,\next+\xx,\next+\xx+1;}
  \text{py=\xx>0 and \yy<\stage?\py,\xx-1,\yy+1,\xx,\yy}
  \text{posx=\posx\xx,}
  \text{posy=\posy\yy,}
 }
 \text{py=\py
line 0,\yy,\base-\yy,\yy}
}
\text{bb=wims(values 0 for x=1 to \Tot)}
\for{t=1..\tot}{
 \text{bb=wims(replace item number \Tot-\t+1 by \sh[\t] in \bb)}
}
\integer{condcnt=rows(\conds)}
\for{c=\condcnt to 1 step -1}{
 \if{\randtype issametext computed}{
  \real{sum=(\bb[\conds[\c;2]])+(\bb[\conds[\c;3]])}
 }{
  \text{sum=maxima(expand((\bb[\conds[\c;2]])+(\bb[\conds[\c;3]])))}
 }
 \text{bb=wims(replace item number \conds[\c;1] by \sum in \bb)}
}


\text{redund=}
\text{red=wims(listcomplement \bb in \list)}
\integer{rcnt=min(\confparm2,items(\red))}
\for{t=1 to \rcnt}{
 \text{rrr=item(1..\confparm2,\red)}
 \text{tt=/ isin \rrr[\t]?wims(replace / by /( in \(\rrr[\t]))):\(\rrr[\t])}
 \text{redund=\redund,\tt}
}
\text{obj=}
\for{t=1 to \Tot}{
 \if{/ isin \bb[\t]}{
  \text{tt=wims(replace / by /( in \(\bb[\t])))}
 }{\text{tt=\(\bb[\t])}}
 \text{obj=wims(append item \tt to \obj)}
}
\text{border=0.2}
\integer{xstep=150}
\integer{ystep=100}
\integer{Sizex=(\base+\border*2)*\xstep}
\integer{Sizey=(\stage+\border*2)*\ystep}
\text{bigimg=draw(\Sizex,\Sizey
 xrange -\border,\base+\border
 yrange -\border,\stage+\border
 fill 0,0,white
 linewidth 3
 linear 1,0.5,0,1
 \py
)}
\text{px=}
\for{t=1..\Tot}{\text{px=wims(append item \posx[\t]+\posy[\t]*0.5 to \px)}}
\text{posx=wims(values (x+\border)*\xstep-\sizex/2 for x in \px)}
\text{posy=wims(values (\border+\stage-y)*\ystep-\sizey/2 for y in \posy)}
\text{caselist=}
\for{i=1 to \Tot}{
 \text{caselist=\caselist
r\i,\posx[\i]x\posy[\i]}
}
\text{steps=item(1..\Tot,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15)}
\steps{\steps}
\statement{Rellenar la imagen con los objetos dados,
de manera que cada caja de un nivel superior sea igual a la suma
de las dos cajas inmediatamente inferiores.
<p><center>
 \special{imagefill \bigimg,\Sizex \Sizey,\size
\caselist
}
</center>
}
\answer{Caja 1}{\r1;\obj[1]\redund}{type=dragfill}
\answer{Caja 2}{\r2;\obj[2]}{type=dragfill}
\answer{Caja 3}{\r3;\obj[3]}{type=dragfill}
\answer{Caja 4}{\r4;\obj[4]}{type=dragfill}
\answer{Caja 5}{\r5;\obj[5]}{type=dragfill}
\answer{Caja 6}{\r6;\obj[6]}{type=dragfill}
\answer{Caja 7}{\r7;\obj[7]}{type=dragfill}
\answer{Caja 8}{\r8;\obj[8]}{type=dragfill}
\answer{Caja 9}{\r9;\obj[9]}{type=dragfill}
\answer{Caja 10}{\r10;\obj[10]}{type=dragfill}
\text{r=item(1..\Tot,\r1,\r2,\r3,\r4,\r5,\r6,\r7,\r8,\r9,\r10,\r11,\r12,\r13,\r14,\r15)}
\text{R=wims(replace internal \ by in \r)}
\text{t1=simplify((\R[\conds[1;1]])-(\R[\conds[1;2]])-(\R[\conds[1;3]]))}
\text{p1=\r[\conds[1;3]]}
\text{p1=- isin \p1?(\p1)}
\condition{\r[\conds[1;1]] = \r[\conds[1;2]] + \p1}
 {\t1 notsametext and \t1=0}

\text{t2=simplify((\R[\conds[2;1]])-(\R[\conds[2;2]])-(\R[\conds[2;3]]))}
\text{p2=\r[\conds[2;3]]}
\text{p2=- isin \p2?(\p2)}
\condition{\r[\conds[2;1]] = \r[\conds[2;2]] + \p2}
 {\t2 notsametext and \t2=0}


\text{p3=\r[\conds[3;3]]}
\text{p3=- isin \p3?(\p3)}
\text{t3=simplify((\R[\conds[3;1]])-(\R[\conds[3;2]])-(\R[\conds[3;3]]))}
\condition{\r[\conds[3;1]] = \r[\conds[3;2]] + \p3}
 {\t3 notsametext and \t3=0}


\text{p4=\r[\conds[4;3]]}
\text{p4=- isin \p4?(\p4)}
\text{t4=simplify((\R[\conds[4;1]])-(\R[\conds[4;2]])-(\R[\conds[4;3]]))}
\condition{\r[\conds[4;1]] = \r[\conds[4;2]] + \p4}
 {\t4 notsametext and \t4=0}


\text{p5=\r[\conds[5;3]]}
\text{p5=- isin \p5?(\p5)}
\text{t5=simplify((\R[\conds[5;1]])-(\R[\conds[5;2]])-(\R[\conds[5;3]]))}
\condition{\r[\conds[5;1]] = \r[\conds[5;2]] + \p5}
 {\t5 notsametext and \t5=0}
