/* Simple linear congruential random number generator with the following parameters X(n+1) = (a*X(n) + b) mod m where a = 11 b = 23 mod = 127 X(1) = 1 The first entries: 1 34 16 72 53 98 85 69 20 116 29 88 It has a cycle of 125. Can we restore the parameters? * With only the specific contants [1,11,23,127] (i.e. cheating) gen = 172 [program = (11 * A + 23) mod (127 * 1),res = 88,count = 1] * With constants 0..130 stop_criteria=generations, num_gens=1800 gen = 700 (time: 10.287s) results_best = [[172,(82 * 86 + (A + A)) mod 78]] gen = 33 (time: 0.316s) results_best = [[21,if_then_else(if_then_else(10 != A == 85,20,A),34 * (A != 10),if_then_else(88,(A == A) mod A != 75 + 86,A * A) mod 87)]] gen = 990 (time: 14.559s) results_best = [[129,(A + A + (A + 35)) mod 111]] gen = 487 (time: 7.026s) results_best = [[132,56 * 100 div 46 * A mod 111]] */ data(linear_congruential_generator,Data,Vars,Unknown,Ops,Constants,MaxSize,Params) :- % make_seq([1,34,16,72,53,98,85,69,20,116,29,88],1,Data,Unknown,Vars), make_seq([1,34,16,72,53,98,85,69,20,116,29],1,Data,Unknown,Vars), % make_seq([1,34,16,72,53],1,Data,Unknown,Vars), println(data=Data), % Ops = [+,*,mod], % We know that it's an LCG. Ops = [+,*,-,mod,==,!=], % Constants = [1,11,23,127], % OK, but cheating :-) % Constants = 0..10, Constants = 0..130, MaxSize = 21, Params = new_map([ init_size=500, show_best=1, show_only_improvements=true, stop_criteria=generations, num_gens=1800 ]).