9
Take two inputs, a non-empty vector/list containing digits 1
and 2
and a string (no, you may not take 0/1
instead). The string will be one of the following (in lowercase, exactly as written below:
increasing
decreasing
ones
twos
all
none
If the string is ____ then you shall return the indices ___:
increasing
... where the list changes from1
to2
(every2
that follows directly after a1
)decreasing
... where the list changes from2
to1
(every1
that follows directly after a2
)ones
... of all digits that are1
twos
... of all digits that are2
all
... all the digitsnone
... none of the digits.0
is fine if the list is 1-indexed. A negative number is fine if the list is 0-indexed. You may also output an empty list or string.
Test cases:
These are 1-indexed. You may choose if you want 1-indexed or 0-indexed. The same vectors are used for different strings in the test cases.
--------------------------------
Vector:
1 1 2 2 2 1 2 2 1 1 2
String - Output
increasing - 3, 7, 11
decreasing - 6, 9
ones - 1, 2, 6, 9, 10
twos - 3, 4, 5, 7, 8, 11
all - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
none - 0 / []
------------------------------------
Vector:
1
String:
ones - 1
all - 1
decreasing / increasing / twos / none - 0 / []
Scoring
As this is code-golf, the answer with the least bytes wins.
@RobertoGraham yes. – Stewie Griffin – 2017-09-29T11:11:23.797
@KevinCruijssen You are a good guesser :) – Stewie Griffin – 2017-09-29T11:11:48.813
So far none of the answers seem to output a list as shown in the example. (ie, joined by ", " with no trailing delimiter). As the challenge text doesn't say how flexible the list can be, what's normally accepted for challenges like this? – Tahg – 2017-09-29T15:03:01.113
It's normally very flexible. As long as it's a list of numbers you're fine. – Stewie Griffin – 2017-09-29T15:59:36.973