Code Golf: Paired Opposites
You will receive a string of comma-separated integers whose elements have both a negative and a positive value, except for one integer that is either only negative or only positive, our challenge will be to find that integer.
As usual shortest solution wins.
Input
"1,-1,2,-2,3"
Output
3
3
has no matching negative appearance
Note
- The only-positive or only-negative integer may appear more than once
- Use this code to check the result length
- You also can use this test case here
Rules
- The signature of the contest entry MUST be:
Class CodeGolf.PairedOpposites
{
ClassMethod Solve(o As %String) As %Integer
{
}
}
- It is forbidden to modify class/signature, including but not limited to:
- Adding inheritance
- Setting default argument values
- Adding class elements (Parameters, Methods, Includes, etc).
- It is forbidden to refer to non-system code from your entry. For example, this is not a valid entry:
ClassMethod Solve(o)
{
q ##class(myPackage.myClass).test(o)
}
- The use of $ZWPACK and $ZWBPACK is also discouraged.