# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

wims_print_precision=5
wims_compare_precision=1000
x_range=!evalue 2^(-$zoom_factor)
zoom_mm=!evalue $x_range*50
xy_size=!evalue sqrt(2)^($size_factor-1)
!ifval $size_factor < 0
  insplot_font=small
!else
  insplot_font=medium
!endif  
insplot_set=zeroaxis; size $xy_size,$xy_size; tmargin 1

!if $cmd=new or $cmd=renew
  wims_module_log=$cmd: degree=$Degree, range=$range
!endif

!for i=$Degree+1 to 5
  c$i = 0
!next  

!if $cmd = reply and $abandon != yes
  reply_cnt=!evalue $reply_cnt+1
!endif

try_cnt=!eval $reply_cnt+1

diff=0
!for i = 0 to 5
  c$i =!evalue rint($(c$i))
  diff=!evalue $diff+|$(c$i)-$(oc$i)|
!next

!if $abandon=yes and $done != yes
  abandon=
  wims_module_log=abandon after $reply_cnt tries
  !for i = 0 to $Degree
   c$i=$(oc$i)
  !next i
  diff=0
  write_solution=yes
!endif
	 
!if $[$diff] = 0 and $done != yes
  done=yes
  poly=
  !for i = $Degree to 0 step -1
    poly=$poly $(oc$i)
  !next i
  poly=!trim $poly
  poly=!translate $ $ to , in $poly
  !read poly2html
  !if $cmd=reply and $write_solution != yes
    wims_module_log=success after $reply_cnt tries
    module_score=$[1.5*($Degree+1)*$range/$reply_cnt]
    !if $module_score>10
     module_score=10
    !endif
  !endif
!endif

