Your task is to determine whether some arbitrary programming language has zero-indexed or one-indexed arrays based on sample inputs and outputs
Inputs
- An array of integers with at least 2 elements
- A positive integer index
- The value of the array at that index
Output
One of four distinct values representing:
- One-indexed if the language unambiguously has one-indexed arrays
- Zero-indexed if the language unambiguously has zero-indexed arrays
- Unknown if the given inputs aren't enough to determine whether the language is zero- or one- indexed because it is ambiguous.
- Neither if the language is not zero- or one-indexed because it is something else that may or may not make any sense.
Example Test Cases
Formatted as [array, elements][index] == value_at_index => output
[2, 3][1] == 2 ==> one-indexed
[2, 3][1] == 3 ==> zero-indexed
[1, 2, 2, 3][2] == 2 ==> unknown
[4, 5][1] == 17 ==> neither
[-3, 5, 2][2] == 5 ==> one-indexed
[-744, 1337, 420, -69][3] == -69 ==> zero-indexed
[-744, 1337, 420, -69][3] == 420 ==> one-indexed
[-744, 1337, 420, -69][3] == -744 ==> neither
[42, 42, 42, 42, 42][2] == 42 ==> unknown
[42, 42, 42, 42, 42][1] == 56 ==> neither
Rules and Scoring
- Use any convenient I/O methods
- Use any convenient representation for each of the four distinct categories as long as it is consistent and each possible category is mapped to exactly one value.
- You may assume that all array values are between \$-2^{31}\$ and \$2^{31} - 1\$, inclusive (i.e. the signed int32 range.)
- You may assume that arrays are no longer than \$65535\$ elements.
- You may assume that the index is in-bounds for both zero- and one-indexed semantics.
Shortest code wins. Happy golfing!
(array, index, element, output as list of 0 and/or 1)
. \$\endgroup\$[7, 7, 2, 7][2] == 7
? On one hand looks like it could be 1-indexed, buuuut it could also be "-1"-indexed (which is weird, but still). \$\endgroup\$[3, 7, 2, 7][2] == 7
would be a better example, because yours could be 2-indexed, too. But I think the question only considers0
,1
, either and neither as possibilities. \$\endgroup\$