Search code examples
minizinc

Create even function in MiniZinc


My question is fairly simple, but I'm quite new to MiniZinc so that's why I'm asking.

I want to define a function even that, given an argument i, returns a list with the even numbers from 0 to 2i.

For example,

even(4)=[0,2,4,6,8]

Can you tell the code for such function?


Solution

  • This problem can be solved quickly using an array comprehension:

    function array[int] of int: even(int: n) =
        [ 2*i | i in 0..n];