```On Sep 1, 9:41=A0am, Max Williams <toastkid.willi... / gmail.com> wrote:
> Little ruby algorithm puzzle...
>
> I have a situation where i have an array of 12 items. =A0If someone
> chooses to have n of them (where n can be between 3 and 12) then i want
> to always include the first and last, and then 'spread' the others out
> as evenly as possible between the rest.
>
> So, lets say for the sake of argument that the array holds the numbers 1
> to 12.
>
> >> arr =3D (1..12).to_a
>
> =3D> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>
> I would get results back like this
>
> =3D> [1,6,12] (or [1,7,12], either is fine)
>
> =3D> [1, 5, 9, 12] =A0(or [1,4,8,12] or [1, 5, 8, 12])
>
> It feels like there should be a simple solution for this but i can't
> think of a nice way. =A0Anyone?
>
> thanks
> max
> --
> Posted viahttp://www.ruby-forum.com/.

This should do what you're looking for. It's not always going to be
100% the most spread out possible, but it looks like you're ok with
that :)

http://pastie.org/601932

-Dylan

```