Finding Collatz-like rules with many loops
GolfScript, arbitrary score

~:l 2:m.@?):d\1 l,{m\)?d-*}/abs.{1 m 3$)?-*m@)?d-m(*/}+l,/]' '*


This takes an integer on stdin and outputs a sequence with that many loops, in the input format of the Python tester. The online demo runs it for l = 4 and produces output 17 2 1755 117 405 1365 26325; this fork of the tester verifies it.

Explanation

In order to keep it simple, I restricted the analysis to primitive loops: ones with only one division.

(x -&gt; mx + i)^n = (x -&gt; m^n x + (m^n - 1)/(m-1) i)


so this means that I'm looking for solutions to

m^n x + (m^n - 1)/(m - 1)i = dx


or

(m^n - d) x + (m^n - 1)/(m - 1)i = 0


When n &gt; 0, m &gt; 1, m^n - d != 0 this has exactly one solution for x. m - 1 &gt; 0 and m^n - 1 &gt; 0, so in order for the solution to be positive we require m^n - d &lt; 0, and in order for the solution to be an integer we require d - m^n to be a factor of (m^n - 1)/(m - 1)i.

The rest may already be obvious. We pick the desired score, l. We're going to find primitive loops of length 1 to l, so we want d - m^l &gt; 0. To get a smallish output we pick m = 2, d = 2^l + 1. Then to get an easy guarantee of the divisibility constraints we pick i to be the absolute value of (m - d)(m^2 - d)...(m^l - d).