Google
{% for i in range((length // 4) + 1) %} {% for j in range([length - (i*4), 4]|min) %} {% endfor %} {% endfor %}