[back]

Increasing Sequence

Implement the function

val inc : (int -> int) -> int -> int list

so that inc f is a function which, given an integer x, returns the longest sequence of the form [x ; f x ; f (f x) ; f (f (f x)) ; ...] such that x < f x < f (f x) < .... In the case that this sequence goes on forever, the function should not terminate.

Examples

let f x = if x * x > 100 then x else x * x
let _ = assert (inc f 3 = [3;9;81])
let _ = assert (inc f 2 = [2;4;16])