step[n_] :=
step[n] = Plus @@ Delete[Divisors[n], Length[Divisors[n]]];
maxLength = 0;
For[n = 220, n < 223, n++,
chain = NestWhileList[step, n, # > 1 && # < 1000000 &];
chain = Delete[chain, Length[chain]];
If[Length[chain] > maxLength,
maxLength = Length[chain];
bestN = Min[chain];,
Nothing[]
]
]
does not work, I guess because n=220 indeed produces an infinite List (am1c4ble cha1n) which ist precisely what I am looking for. But how do I test for that, so how do I add && # is not part of chain already?
Or am I assuming what the problem is incorrectly? Working test for example with n=221, n<223 terminating and having the correct chain
NestWhileList,All? This would supply you with the information you need to check if#has appeared previously. – C. E. Jul 15 '16 at 15:03NestWhileList[step, 222, # > 1 && # < 1000000 &, All] already seems to be an infinite loop
– Erik Itter Jul 15 '16 at 19:38NestWhileList[ds, n, Signature@{1, n, ##2} =!= 0 &, All]wheredsis similar to yourstep. I usedSignatureto check for duplicates. One could also make use ofUnsameQor the new-in-10DuplicateFreeQwith different performance profiles. (6745) I'll leave the rest for you to figure out. – Mr.Wizard Jul 16 '16 at 02:39