Sounds quite straightforward, but I didn't find a solution yet. How do I get the first (oder last) n elements of a minizinc array with one dimension? The result should be an array, so that I can apply count () oder sum().
Asked
Active
Viewed 204 times
1 Answers
1
The easiest way if you have an array arr
with an index set of 1..m
is the following array comprehension:
[ arr[i] | i in 1..n ]
You can also construct an array comprehension that does not depend on the index set starting from 1:
[ arr[i] | i in (min(index_set(arr)))..(min(index_set(arr)))+n ]
Note that either comprehension will not work if length(arr) < n
.

Dekker1
- 5,565
- 25
- 33
-
Thank you very much. Works like a charm. – P. Beer Aug 15 '18 at 13:42