A001057 is one way to represent an integer as a natural number. It lists them according to the following pattern:
0, 1, -1, 2, -2, 3, -3, 4, -4, ...
In this challenge, you'll take two distinct integers as input and return which is at a higher index in this enumeration.
Take -2
and 1
as an example: -2
comes after 1
, so it would be returned.
You may also choose to instead return the smaller integer, or one of two consistent values (such as 0
or 1
) to indicate which is higher or lower. Truthy/falsy values as output are not allowed.
Test cases:
0 1 1
1 0 1
0 -1 -1
-1 0 -1
-1 1 -1
1 -1 -1
1 -2 -2
1 2 2
-1 -2 -2
-1 2 2
[-6,4] -> [4,-6]
\$\endgroup\$0
/1
(basically for all loose type ones): in Javascript or PHP,0
/1
are falsey/truthy values, as well as all the numbers in the sequence btw.. \$\endgroup\$0
and1
. You could choose to returntrue
andfalse
if you want, just not any inconsistent truthy/falsy values. \$\endgroup\$