## WeBWorK Problems

### Checking 1-(-1)^n

by Ian Delbridge -
Number of replies: 3
Hi,

I was wondering if anyone could help me with a specific problem that I evidently don't know how to fix.

I'm trying to check the answer "1-(-1)^n". I want n as a variable rather than a named constant as to check when n is an even integer as well as an odd integer. When I don't restrict the limits that n is tested at, I always get an error "can't generate enough valid points for comparison". So, I want restrict the domain to integers to keep it from trying to test roots of a negative number, giving imaginary values.

Is there a setting that I can choose that will only check n at integers?

I tried giving the following command:
Context()->variables->set(n=>{limits=>{1,2,3,4}});
However, instead of fixing the problem, it causes a new one it would seem, because it doesn't accept the correct answer now, despite getting rid of the "can't generate enough valid points for comparison" error. I might be using wrong syntax here, but I'm not sure.

Any thoughts would be appreciated.
Problem file (as a .txt file) attached.

### Re: Checking 1-(-1)^n

by Paul Pearson -
Hi Ian,

There was a post to the forum about this a while back.  One way to achieve the desired effect is to set the resolution:

The documentation for other ways to accomplish this can probably be found at:
• http://webwork.maa.org/wiki/FormulaTestPoints
Best regards,

Paul Pearson

### Re: Checking 1-(-1)^n

by Ian Delbridge -
Awesome! That works completely and seamlessly - exactly the kind of function I was hoping for. Thank you!
$f->{test_at} = [[2],[3]]; (where$f is your function)