Rev 5923 | Blame | Compare with Previous | Last modification | View Log | RSS feed
# this file expect the answer to be reply$n and returns a modulescore
# it just checks a number answer
# examples
# sqrt(2) 1123
# 234242.234242 2.3e+23
# 2*10^2323
# x1=23432 x2=34353653 x3=345353543535
# if you expect "x=" or "z=" or "y=" in the reply$n , declare arglist=x
# if the answer is 5*x use variable.proc
# complex numbers declare: complex=1
# if no real answers/solutions: answer$n=nil
# >>> set var1=yes if the sequence of answers matters
# 3/2010 changed rounding
# 6/2010 "improved rounding"
# 12/2010 "improved presentation" multiple answers (in html)
# 12/2010 declare var10=10,1000,10000,1,0 ... as list of roundings when using multiple answers
# 2/2011 presentation without <ul> list when single answer
# 10/2011 if no "arglist" is set, now no "error" when pupils write: V=123 and A=456 B=12
# 10/2011 : this file becomes too big: should be rewritten... :(
goback=0
errortext=$empty
n=$counter
!if $(reply$n)=?
remark$n=$NOK
goback=0
maxscore=0
!exit
!endif
test=!lower $(reply$n)
# there is no real solution
nothing=!record 71 of $remarkdir/commonremarks.$taal
#@ nul,zero,zip,nop,niks,nada,geen,niente
A=0
test=!singlespace $test
!for check in $nothing
!if $A=0
!if $check iswordof $test
A=1
!endif
!endif
!next p
!if $(answer$n)=nil
!if $A=1
remark$n=$OK
maxscore=1
!increase modulescore
!else
remark$n=$NOK
maxscore=0
!endif
goback=0
!exit
!else
!if $A=1
ex=!record 83 of $remarkdir/commonremarks.$taal
#@ Er zijn wel degelijk oplossingen...
remark$n=$NOK <br />$ex
maxscore=0
goback=0
!exit
!endif
!endif
errortext=$empty
!if $wordmax=$empty
wordmax=20
!endif
AAA=!lower $(reply$n)
tot=!singlespace $AAA
# first check for the 'decimal' comma
!if $questiontype notin 0,7,9
# questiontype=0 uses precheck.js as default answer-filter questiontype=7 is tailored with own js-functions
# checking on decimal comma is already done
c=!positionof char , in $tot
!if $c != $empty
ta=!itemcnt $(answer$n)
!if $ta>1
check=1
!else
check=0
!endif
nummers=0123456789
!for i in $c
c1=!char $[$i-1] of $tot
c2=!char $[$i+1] of $tot
!if $c1 isin $nummers and $c2 isin $nummers
!increase check
maxscore=$[$maxscore*$P1]
!if $check >1
errortext=!record 28 of $remarkdir/commonremarks.$taal
goback=1
!exit
!else
# we replace only 1 decimal comma by a point...
tot=!replace internal char number $i by . in $tot
ex=!record 24 of $remarkdir/commonremarks.$taal
!if $extra != $empty
extra=$extra<br />$ex
!else
extra=$ex
!endif
!endif
!endif
!next i
AAA=$tot
!endif
!endif
!for p in -->,==>,->,=>
AAA=!replace internal $p by = in $AAA
!next p
AAA=!replace internal word is by = in $AAA
AAA=!words2items $AAA
test=!itemcnt $AAA
!if $test > $wordmax
maxscore=$[$maxscore*$P3]
errortext=!record 48 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
AAA=!nospace $AAA
# pfff
!for p=1 to 3
AAA=!replace internal ,, by , in $AAA
!next p
c1=!char 1 of $AAA
c2=!char -1 of $AAA
!if $c1=,
AAA=!char 2 to -1 of $AAA
!endif
!if $c2=,
AAA=!char 1 to -2 of $AAA
!endif
AAA=!nospace $AAA
AAA=!replace internal ** by ^ in $AAA
!if $questiontype != 0
# questiontyp=0 uses precheck.js as default answer-filter !
# checking on scientific notation and letter "o" as number "0" is already done
!if x10 isin $AAA
ex=!record 68 of $remarkdir/commonremarks.$taal
maxscore=$[$P1*$maxscore]
!if $teaching=1
goback=1
errortext=$ex
!exit
!else
AAA=!replace internal x10 by *10 in $AAA
!if $extra=$empty
extra=$ex
!else
extra=$extra<br />$ex
!endif
!endif
!endif
test=!replace [0-9]e[0-9] by @ in $AAA
!if @ isin $test
maxscore=$[$P1*$maxscore]
testvar1=!replace internal e by e+ in $AAA
testvar1=<span style="color:green:>$testvar1</span>
testvar2=<br /><span style="color:red">$AAA</span>
errortext=!record 16 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
AAA=!replace internal e+ by *10^ in $AAA
AAA=!replace internal e- by *10^- in $AAA
!for p=1 to 3
AAA=!replace internal ** by * in $AAA
!next p
t=!char 1 of $AAA
!if $t=*
AAA=!char 2 to -1 of $AAA
!endif
# check on the letter 'o' as number "0"
aaa=!nospace $AAA
aaa=!replace internal = by @ in $aaa
t=!positionof char o in $aaa
!if $t != $empty
nummers=0.123456789
!for p in $t
check=0
t1=!char $[$p-1] of $aaa
!if $t1=@
# dus x=o
check=1
!endif
t2=!char $[$p+1] of $aaa
!if $t1 isin $nummers and $t2 isin $nummers
check=1
!endif
# dus 123o 123.o
!if $check=1
maxscore=$[$P2*$maxscore]
!if $teaching=1
errortext=!record 13 of $remarkdir/commonremarks.$taal
goback=1
!exit
!else
ex=!record 48 of $remarkdir/commonremarks.$taal
# we corrigeren o -> 0 !
aaa=!replace internal char number $p by 0 in $aaa
extra=!append line <br />$ex to $extra
!endif
!endif
!next p
AAA=$aaa
!endif
!endif
# checkfor a stray '+' or '-' sign as operator.
# do your own calculations !
# but an answer like 1+3*sqrt(2) should ofcourse be Ok
# and if $varlist is not empty, we should skip this test anyway
# (3+4x) is a sound answer
!if $varlist = $empty
!if (+ isin $AAA) or (- isin $AAA)
dingen=i,sqrt,cos,tan,abs,log,ln
# 'sin' is covered by 'i'
!for r in $dingen
!if $r isin $AAA
# no need to go on
!goto READY1
!endif
!next r
nummers=0,1,2,3,4,5,6,7,8,9
!for s in +,-
t=!positionof char $s in $AAA
!if $t != $empty
!for p in $t
t1=!char $[$p-1] of $AAA
t2=!char $[$p+1] of $AAA
!if ($t1 isitemof $nummers) and ($t2 isitemof $nummers)
maxscore=$[$P3*$maxscore]
errortext=!record 14 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
!next p
!endif
!next s
!endif
!endif
:READY1
!for p in +,-,*,^,/,|
stupid=!nospace , $p ,
!if $stupid isin $AAA
AAA=!replace internal $stupid by $p in $AAA
!endif
!next p
!for p in sqrt,sin,cos,tan,abs,log,ln,+,-,*,^,/,(,|
stupid=!nospace $p ,
!if $stupid isin $AAA
AAA=!replace internal $stupid by $p in $AAA
!endif
!next p
!for p in +,*,),^,/
stupid=!nospace , $p
!if $stupid isin $AAA
AAA=!replace internal $stupid by $p in $AAA
!endif
!next p
#check for sin etc
!for i in sqrt,log,sin,ln,cos,tan,abs
!if $i isin $AAA
# test on balanced |x|
test1=!replace internal $i| by # in $AAA
!if # isin $test1
# so ln|x| ===> ln(|x|)
# rawmath deals elegantly with |x| => abs(x)
pos=!positionof char | in $AAA
tot=!itemcnt $pos
!if $[gcd($tot,2)] != 2
maxscore=$[$P1*$maxscore]
# uneven number of |-bars
errortext=!record 15 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
!for r=1 to $[$tot-1]
p1=!item $r of $pos
p2=!item $[$r+1] of $pos
AAA=!replace internal char number $p1 by ~ in $AAA
AAA=!replace internal char number $p2 by # in $AAA
AAA=!replace internal ~ by (| in $AAA
AAA=!replace internal # by |) in $AAA
!next r
!endif
test2=!replace internal $i( by # in $AAA
!if # notin $test2
testvar1=!nospace $i ( x )
testvar2=!nospace $i x
maxscore=$[$maxscore*$P2]
errortext=!record 19 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
!if $i=ln
!if LOG isin $AAA
errortext=Het lijkt me sterk dat dit sommetjes zowel een <br /><b>log()</b><br />als een<br /><b>ln()</b><br />in het antwoord moet hebben
maxscore=$[$P4*$maxscore]
goback=1
!exit
!endif
AAA=!replace internal ln by LOG in $AAA
!endif
I=!toupper $i
AAA=!replace internal $i by $I in $AAA
!endif
!next i
AAA=!nospace $AAA
#check on "=" sign or "is"
#after that remove x1= x_1= x_23= or a1= a2= a3= b9= ... z2= etc etc from tha studentanswer
test=!replace internal = by @ in $AAA
!if @ isin $test
!if $arglist != $empty
use_arg=1
!for p in $arglist
P=!lower $p
AAA=!replace $P[_0-9]* by @ in $AAA
!next p
!if @ notin $AAA
maxscore=$[$P1*$maxscore]
testvar= <b> $arglist =... </b>
errortext=!record 53 of $remarkdir/commonremarks.$taal
goback=1
!exit
!else
AAA=!replace internal @ by $empty in $AAA
AAA=!replace internal = by $empty in $AAA
# now: ,,en,,3,,en,ook,4
!endif
!else
use_arg=0
new_AAA=$empty
# strip all a=123,b=4334,c=2344 --> 123,4334,2344
AAA=!replace internal = by , in $AAA
!for p in $AAA
!if NaN notin $[1*$p]
new_AAA=!append item $p to $new_AAA
!endif
!next p
AAA=$new_AAA
!endif
!else
!if $arglist != $empty
maxscore=$[$P1*$maxscore]
testvar= <b> $arglist =... </b>
errortext=!record 53 of $remarkdir/commonremarks.$taal
goback=1
!exit
!endif
!endif
AAA=!nospace $AAA
# the position of "!rawmath" is critical...
# ATTENTION: rawmath ln(|x|) => ln(abs(x))
# ATTENTION: rawmath ln|x| => ln(abs)*(x)
AAA=!replace internal pi by PI in $AAA
# correcting for x=1 en x=2
!for p in en,et,er,euro,euros
AAA=!replace internal $p by $empty in $AAA
!next p
AAA=!replace internal e by E in $AAA
# i -> 10
!if $complex=1
# complex numbers gewoon vervangen door een getal
!if i isin $AAA
AAA=!rawmath $AAA
# we consider both "5i" and "i5" ok-> 5*10* ,*10*5
AAA=!replace internal i by *10* in $AAA
AAA=!replace internal ** by * in $AAA
AAA=!replace internal (* by ( in $AAA
AAA=!replace internal *) by ) in $AAA
AAA=!replace internal /* by / in $AAA
AAA=!replace internal */ by / in $AAA
AAA=!replace internal -* by - in $AAA
AAA=!replace internal *- by - in $AAA
AAA=!replace internal +* by + in $AAA
AAA=!replace internal *+ by + in $AAA
!endif
GGG=!replace internal pi by PI in $(answer$n)
GGG=!replace internal sin by SIN in $GGG
GGG=!replace internal i by 10 in $GGG
GGG=!lower $GGG
!else
GGG=$(answer$n)
!endif
AAA=!replace internal abs by ABS in $AAA
AAA=!replace [a-z\~\!\@\#\$\=\%\&\_\;] by $empty in $AAA
AAA=!tolower $AAA
AAA=!rawmath $AAA
AAA=!nospace $AAA
!for p=1 to 6
AAA=!replace internal ,, by , in $AAA
!next p
c1=!char 1 of $AAA
!if $c1=,
AAA=!char 2 to -1 of $AAA
!endif
c1=!char -1 of $AAA
!if $c1=,
AAA=!char 1 to -2 of $AAA
!endif
ta=!itemcnt $AAA
tg=!itemcnt $GGG
!if $ta=0
maxscore=$[$P5*$maxscore]
goback=1
errortext=!record 36 of $remarkdir/commonremarks.$taal
!exit
!endif
tot=$empty
AAA=!nospace $AAA
!for p=1 to $ta
A=!item $p of $AAA
!if ? isin $A
A=123456789
!else
a=!char -1 of $A
!if $a=*
A=!char 1 to -2 of $A
!endif
a=!char 1 of $A
!if $a=*
A=!char 2 to -1 of $A
!endif
!if NaN isin $[1*($A)] and $complex!=1
# test op sqrt(-4)
!if (sqrt isin $A) or (log isin $A) or (ln isin $A)
test=!replace internal sqrt( by @ in $A
test=!replace internal log( by @ in $test
test=!replace internal ln( by @ in $test
p1=!positionof char @ in $test
p2=!positionof char ) in $test
h=!itemcnt $p2
k=!itemcnt $p1
chars=$empty
!if $h=1 and $k=1
!for s=$[$p1+1] to $[$p2-1]
ch=!char $s of $test
chars=!append word $ch to $chars
!next s
!else
klaar=0
!if $k=1
!for w in $p2
kkk=!append line w=$w<br /> to $kkk
!if $w>$p1 and $klaar=0
!for s=$[$p1+1] to $[$w-1]
ch=!char $s of $test
chars=!append word $ch to $chars
!next s
klaar=1
!endif
!next w
!else
# meerdere sqrt's in 1 antwoord... wordt erg onwaarschijnlijk en niet echt interessant
chars=1
!endif
!endif
chars=!nospace $chars
testvar=$[1*$chars]
!ifval $testvar<0
# hehe negatieve wortel
errortext=!record 88 of $remarkdir/commonremarks.$taal
!else
errortext=!record 26 of $remarkdir/commonremarks.$taal
!endif
!else
errortext=!record 26 of $remarkdir/commonremarks.$taal
!endif
maxscore=$[$P5*$maxscore]
goback=1
!exit
!endif
!endif
tot=!append item $A to $tot
!next p
AAA=$tot
!if $ta != $tg
!if $ta>$tg
maxscore=$[$P7*$maxscore*$tg/$ta]
!else
maxscore=$[$P5*$maxscore*$ta/$tg]
!endif
testvar2=$ta
testvar1=$tg
ex=!record 50 of $remarkdir/commonremarks.$taal
extra=!append line <br />$ex to $extra
!endif
afr1=$empty
afr2=$empty
!if $var10 != $empty
# tg=!itemcnt GGG
multiple_roundings=1
t3=!itemcnt $var10
!if $t3 != $tg
errortext=error in module : var10 should be used for a list of rounding factors (var10= $var10)
goback=1
!exit
!endif
!for p=1 to $t3
a=!item $p of $var10
!if $a<1
!if $a=-1
#not given
afr1=!append item 1000 to $afr1
afr2=!append item 100 to $afr2
!else
#exact
afr1=!append item 1000000 to $afr1
afr2=!append item 10000 to $afr2
!endif
!else
afr1=!append item $a to $afr1
afr2=!append item $[$a/10] to $afr2
!endif
!next p
!else
multiple_roundings=0
!for p=1 to $tg
!if $rounding<1
!if $rounding=-1
#not given
afr1=!append item 1000 to $afr1
afr2=!append item 100 to $afr2
!else
#exact
afr1=!append item 1000000 to $afr1
afr2=!append item 10000 to $afr2
!endif
!else
afr1=!append item $rounding to $afr1
afr2=!append item $[$rounding/10] to $afr2
!endif
!next p
!endif
G0=$empty
G1=$empty
G2=$empty
A0=$empty
A1=$empty
A2=$empty
A3=$empty
!for p=1 to $tg
g=!item $p of $GGG
ar1=!item $p of $afr1
ar2=!item $p of $afr2
g1=$[(round($ar1*($g)))/$ar1]
g2=$[(round($ar2*($g)))/$ar1]
G0=!append item $g to $G0
G1=!append item $g1 to $G1
G2=!append item $g2 to $G2
!next p
!for p=1 to $ta
a=!item $p of $AAA
ar1=!item $p of $afr1
ar2=!item $p of $afr2
!if $ar1=$empty
# more pupil replies then expected...use last rounding values
ar1=!item -1 of $afr1
ar2=!item -1 of $afr2
!endif
a1=$[(round($ar1*($a)))/$ar1]
a2=$[(round($ar2*($a)))/$ar1]
A0=!append item $a to $A0
A1=!append item $a1 to $A1
A2=!append item $a2 to $A2
# 5/11/2012
# we maken een lijst om -0,0,sqrt(0),-sqrt(0) als antwoorden af te vangen
A3=!append item $[1*($a)] to $A3
!next p
!if NaN isin $A0,$A1,$A2
maxscore=$[$P3*$maxscore]
goback=1
errortext=!record 26 of $remarkdir/commonremarks.$taal
!endif
parivraag0=$empty
parivraag1=$empty
parivraag2=$empty
reversed=0
!if $var1=yes
# sequence matters : item 1 of $GGG == item 1 of $AAA
# there are $tg inputs/questions
!for p=1 to $tg
a0=!item $p of $A0
!if $a0 != $empty
a1=!item $p of $A1
a2=!item $p of $A2
g0=!item $p of $G0
g1=!item $p of $G1
g2=!item $p of $G2
rev=$[-1*$a1]
!if $rev notitemof $A1
!ifval $a1 != 0 and $rev=$g1
!increase reversed
!endif
!endif
# 1.0* ivm paribug grote getallen: if( abs(1.234*10^45 - 1.234*10^45) <10^-15,1,0) == 0
parivraag0=!append line if( abs(1.0*($g0) - 1.0*($a0)) <= 1.0*10^(-15) ,1,0 ) to $parivraag0
parivraag1=!append line if( abs(($g1) - ($a1)) <= 1.0*10^(-15) ,1,0 ) to $parivraag1
parivraag2=!append line if( abs(($g2) - ($a2)) <= 1.0*10^(-15) ,1,0 ) to $parivraag2
!else
parivraag0=!append line if(1==0,1,0) to $parivraag0
parivraag1=!append line if(1==0,1,0) to $parivraag1
parivraag2=!append line if(1==0,1,0) to $parivraag2
!endif
!next p
mx=$tg
stap=1
!else
# one inputfield/question but multiple answers possible in textarea
# sequence in reply does not matter
# x=10 and x=100 == x=100 and x=10
# so check for doublures
# A3 5/11/2012
check_uniq=!listuniq $A3
#check_uniq=!listuniq $A0
tchk=!itemcnt $check_uniq
!if $ta>$tchk
testvar=$[$ta - $tchk]
ex=!record 51 of $remarkdir/commonremarks.$taal
extra=!append line <br />$ex to $extra
maxscore=$[$maxscore*$tchk/$ta]
A0=$check_uniq
A1=!listuniq $A1
A2=!listuniq $A2
ta=!itemcnt $A0
!endif
!for s=1 to $ta
a0=!item $s of $A0
a1=!item $s of $A1
a2=!item $s of $A2
rev=$[-1*$a1]
!if $rev notitemof $A1
!if $rev isitemof $G1
!increase reversed
!endif
!endif
!for p=1 to $tg
g0=!item $p of $G0
g1=!item $p of $G1
g2=!item $p of $G2
# 1.0* ivm paribug grote getallen: if( abs(1.234*10^45 - 1.234*10^45) <10^-15,1,0) == 0
parivraag0=!append line if( abs(1.0*($g0) - 1.0*($a0)) <= 1.0*10^(-15) ,1,0 ) to $parivraag0
parivraag1=!append line if( abs(($g1) - ($a1)) <= 1.0*10^(-15) ,1,0 ) to $parivraag1
parivraag2=!append line if( abs(($g2) - ($a2)) <= 1.0*10^(-15) ,1,0 ) to $parivraag2
!next p
!next s
mx=$[$tg*$ta]
stap=$tg
!endif
dryrun=!exec pari if(log(5)/log(2)==log(5)/log(2),1,0)
# i.v.m. precision "bug" pari/gp 2.2.10 (chroot version)
tot0=!exec pari $parivraag0
tot1=!exec pari $parivraag1
tot2=!exec pari $parivraag2
tot0=!lines2items $tot0
tot1=!lines2items $tot1
tot2=!lines2items $tot2
!if $wims_exec_error != $empty
maxscore=$[$P4*$maxscore]
goback=1
errortext=!record 26 of $remarkdir/commonremarks.$taal
!exit
!endif
!if $use_arg=1
arg= <em>$arglist</em> =
!else
arg=$empty
!endif
score=0
score0=0
score1=0
score2=0
!if $ta>1
rep=<ul>
!else
rep=$empty
!endif
c=1
i=1
!for p=1 to $mx step $stap
a=!item $i of $A0
sum0=0
sum1=0
sum2=0
!for s=$c to $[$c+$stap-1]
s1=!item $s of $tot0
sum0=$[$sum0+$s1]
s1=!item $s of $tot1
sum1=$[$sum1+$s1]
s1=!item $s of $tot2
sum2=$[$sum2+$s1]
!next s
c=$[$c+$stap]
!if $sum0=1
!increase score0
!increase score1
!increase score2
k=#00b800
!else
!if $sum1=1
!increase score1
!increase score2
k=#009300
!else
!if $sum2=1
k=#e89300
!increase score2
!else
k=#ff0000
!endif
!endif
!endif
!increase i
!if $ta>1
rep=!append line <li><span style="color:$k">$arg<b>$a</b></span></li> to $rep
!else
rep=<span style="color:$k">$arg<b>$a</b></span>
!endif
!next p
!if $multiple_roundings=0
!if $rounding < 1
score=$score0
!if $score = 0
!if $score1 = $mx or $score2 = $mx
score =$[$mx/3]
ex=!record 66 of $remarkdir/commonremarks.$taal
extra=!append line <br />$ex to $extra
!endif
!endif
!else
!if $score2>$score1
ex=!record 29 of $remarkdir/commonremarks.$taal
extra=!append line <br />$ex to $extra
!endif
score=$[(2*$score1+$score2)/3]
!endif
!else
score=$[(2*$score1 + $score2)/3]
!endif
!if $reversed>0
ex=!record 27 of $remarkdir/commonremarks.$taal
extra=!append line $ <br />$ex $ to $extra
score=$[$score + $P7*$reversed]
!endif
maxscore=$[$maxscore*$score/$tg]
modulescore=$[$modulescore + $maxscore]
!if $maxscore>0.9
remark$n=$OK
!else
!if $maxscore >0.45
remark$n=$BOK
!else
remark$n=$NOK
!endif
!endif
# no !insmath : using html-list and colours.
math=0
!if $ta>1
reply$n=!append word </ul> to $rep
!else
reply$n=$rep
!endif
!if $extra != $empty
remark$n=!append line $ <br />$extra $ to $(remark$n)
!endif
goback=0
!exit