Algo produces something similar to correct, not respecting 1 <= r <= d (r == d+1 sometimes)