WeBWorK Main Forum

Strings starting with "0"

Strings starting with "0"

by Oscar Levin -
Number of replies: 2

I have a question where I want students to write out a collection of bit strings.  The correct answer should be:

110, 101, 011

with those three strings occurring in any order.  If the intended answer was 

110, 101, 100

then I'm able to get this with the following pg-code:

Context()->strings->add(110 => {}, 101 => {}, 100 => {});
$strings = List(String(110), String(101), String(100));

And using `$strings` as the answer works great.
Something is strange with the answer checker or sting object.  In fact, the answer that that is accepted where the string "011" should go is "9".  What????

I don't think it matters, but I've authored this problem in PreTeXt.

In reply to Oscar Levin

Re: Strings starting with "0"

by Alex Jordan -
With String(011), the leading 0 would signify interpreting the number in octal. So of course it is 9 back in decimal. Try String('011'), and also using '011' as the key in that hash.

Also you may want to consider adding all eight strings to the context in case a student enters one of the incorrect bit strings.


In reply to Alex Jordan

Re: Strings starting with "0"

by Oscar Levin -
That fixed it! I think I must have tried using double quotes which gave an error compiling. I forget how picky perl is.

Thanks!