You are viewing a single comment's thread. Return to all comments →
Solution in Ocaml without using builtins function:
let read_inputs () = let rec get_inputs liste = try let tmp = read_int () in get_inputs (liste @ [tmp]) (* Accumulate input into the list *) with | End_of_file -> liste in get_inputs [] ;; let rec filter_odd_position_element liste n = if n <> List.length liste && (n mod 2) = 1 then Printf.printf "%d\n" (List.nth liste n); if n <> List.length liste then filter_odd_position_element liste (n + 1) ;; let liste = read_inputs ();; filter_odd_position_element liste 0;;
Seems like cookies are disabled on this browser, please enable them to open this website
Filter Positions in a List
You are viewing a single comment's thread. Return to all comments →
Solution in Ocaml without using builtins function: