I am running WebWork 2.10 (commit id: 6543eb8286a482c347ffce684472238f78c4573a), on an Amazon Linux server. At the moment, I can't upgrade to 2.12 (largely because of some issues with the Perl dependencies).
Answers that are entered get saved to the MySQL database (they are visible by doing
select last_answer from COURSE_problem_user where user_id='USERID' and set_id='Ionic' and problem_id=1;
The past answers are also visible if I go to View Past Answers
Only when returning to the problem, does an error appear:
Odd number of elements in hash assignment at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 881.
When I dump the output from to Utils.pm --> decodeAnswers(), I see:
$VAR1 = [ 'AnSwEr0001', 'Ru', 'AnSwEr0002', '+3', ... 'AnSwEr0030', '+4', 'AnSwEr0031', 'As', 'AnSwEr0032' ];
The output just stops at answer 32, and doesn't have a matching field (explaining the odd number of elements error).
Deleting my question and replacing it with another one that works fine, still produces the error when existing answers are populated.
PG Code for question:
##DESCRIPTION
## Chemistry problem: determine cations and anions
##ENDDESCRIPTION
##KEYWORDS('Chemistry', 'ionic', 'ions')
## DBsubject('Chemistry')
## DBchapter('Ionic')
## DBsection('Naming')
## Date('26/11/2013')
## Author('Chris')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
);
@cations = (
["hydrogen", "H", [1],0],
["lithium", "Li", [1],0],
["sodium", "Na", [1],0],
["potassium", "K", [1],0],
["rubidium", "Rb", [1],0],
["cesium", "Cs", [1],0],
["beryllium", "Be", [2],0],
["magnesium", "Mg", [2],0],
["calcium", "Ca", [2],0],
["strontium", "Sr", [2],0],
["barium", "Ba", [2],0],
["scandium", "Sc", [3],0],
["yttrium", "Y", [3],0],
["lutetium", "Lu", [3],0],
["titanium", "Ti", [2,3,4],0],
["zirconium", "Zr", [4],0],
["hafnium", "Hf", [4], 0],
["vanadium", "V", [2,3,4,5],0],
["niobium", "Nb", [3,5],0],
["tantalum", "Ta", [5],0],
["chromium", "Cr", [2,3,6],0],
["molybdenum", "Mo", [6],0],
["tungsten", "W", [6],0],
["manganese", "Mn", [2,3,4,7],0],
["rhenium", "Re", [4,6,7],0],
["iron", "Fe", [2,3],0],
["ruthenium", "Ru", [3],0],
["osmium", "Os", [3,4],0],
["cobalt", "Co", [2,3],0],
["rhodium", "Rh", [3],0],
["iridium", "Ir", [3,4],0],
["nickel", "Ni", [2,3],0],
["palladium", "Pd", [2,4],0],
["platinum", "Pt", [2,4],0],
["copper", "Cu", [1,2],0],
["silver", "Ag", [1],0],
["gold", "Au", [1,3],0],
["zinc", "Zn", [2],0],
["cadmium", "Cd", [2],0],
["mercury", "Hg", [1,2],0],
["boron", "B", [3],0],
["aluminum", "Al", [3],0],
["gallium", "Ga", [3],0],
["indium", "In", [1,3],0],
["thallium", "Tl", [1,3],0],
["germanium", "Ge", [2,4],0],
["tin", "Sn", [2,4],0],
["lead", "Pb", [2,4],0],
["bismuth", "Bi", [3,5],0],
["ammonium", "NH4", [1], 1,0],
);
@anions = (
["carbide", "C", 4, 0],
["silicide", "Si", 4,0],
["nitride", "N", 3,0],
["phosphide", "P", 3,0],
["arsenide", "As", 3,0],
["oxide", "O", 2,0],
["sulfide", "S", 2,0],
["selenide", "Se", 2,0],
["telluride", "Te", 2,0],
["fluoride", "F", 1,0],
["chloride", "Cl", 1,0],
["bromide", "Br", 1,0],
["iodide", "I", 1,0],
["acetate", "CH3COO", 1,1],
["bicarbonate", "HCO3",1,1],
["chlorate", "ClO3", 1,1],
["cyanide", "CN", 1,1],
["hydrogen sulfate", "HSO4", 1,1],
["hydroxide", "OH", 1,1],
["nitrate", "NO3", 1,1],
["nitrite", "NO2", 1,1],
["permanganate", "MnO4", 1,1],
["carbonate", "CO3", 2,1],
["chromate", "CrO4", 2,1],
["dichromate", "Cr2O7", 2,1],
["hydrogen phosphate", "HPO4", 2,1],
["oxide", "O",2,0],
["sulfate", "SO4", 2,1],
["sulfite", "SO3", 2,1],
["thiosulfate", "S2O3", 2,1],
["phosphate", "PO4", 3,1]
);
@roman = ("I","II","III","IV","V","VI","VII","VIII","IX","X");
$table_row="";
my @answers = ();
$num = 20;
$num++;
for ($i = 0; $i < $num; $i++) {
@cat = @{$cations[random(0,$#cations)]};
$cat_v = $cat[2][random(0,$#{$cat[2]})];
@an = @{$anions[random(0,$#anions)]};
$an_v = $an[2];
$gcf = gcf($cat_v, $an_v);
$orig = $cat_v . ", " . $an_v;
$cat_v_orig = $cat_v;
$an_v_orig = $an_v;
$cat_v /= $gcf;
$an_v /= $gcf;
$formula_ans = ($cat[3] && ($an_v > 1)?"(":"") . $cat[1] . ($cat[3] && ($an_v > 1)?")":"") . ($an_v > 1? $an_v:"") . ($an[3] && ($cat_v > 1)?"(":"") . $an[1] . ($an[3] && ($cat_v > 1)?")":"") . ($cat_v > 1 ? $cat_v :"");
$formula_disp = $formula_ans;
$formula_disp =~ s!([0-9]+)!<sub>$1</sub>!g;
$name = $cat[0] . " " . ($#{$cat[2]} > 0? "(" .$roman[$cat_v_orig-1] . ")" : "") . " " . $an[0];
if($i==0){
$table_row .= row($formula_disp, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);
}else{
$table_row .= row($formula_disp, ans_rule(15), ans_rule(15), ans_rule(15), ans_rule(15));
push(@answers, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);
}
}
Context()->normalStrings;
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
# Print problem number and point value (weight) for the problem
BEGIN_TEXT
For each ionic compound below, identify the cation and anion, and write the charges. Do NOT include the charge in the cation/anion column. You must include the plus sign and minus sign. The first one is done for you. $PAR
$BCENTER
\{ begintable(2) \}
\{ row( "Formula", "Cation", "Cation Charge", "Anion", "Anion Charge") \}
$table_row
\{ endtable() \}
$ECENTER
END_TEXT
for my $i (0 .. $#answers) {
ANS(std_cs_str_cmp($answers[$i]));
}
ENDDOCUMENT();
Any suggestions on how to fix this issue would be appreciated.
Thanks,
-Chris