(*
FRACTRAN.wls
Invoke with `wolframscript -file FRACTRAN.wls <codefile> <starting_integer> <max_iterations>`
*)
FractranIt[f_List, n_Integer] := Module[{i = 1, l = Length[f]},
While[i <= l && ! IntegerQ[n f[[i]]], i++];
If[i > l, 0, n f[[i]]]
]
Fractran[f_List, n0_Integer, nmax_: 100] := Module[{i = 1, l = {n0}},
While[l[[-1]] > 0 && i <= nmax,
i++;
l = Append[l, FractranIt[f, l[[-1]]]]
];
l
]
code = ReadString@$ScriptCommandLine[[2]]
n = ToExpression@$ScriptCommandLine[[3]]