// F#
[]
let main argv =
let getRandomCollection n =
let rand = new System.Random()
Array.map (fun x -> rand.Next(-10, 10)) [| 1..n |]
let inputArray = getRandomCollection 15
printf "source array: %A\n" (inputArray |> Array.toList)
// First part
printf "numberToCheckOnEqual: "
let numberToCheckOnEqual = System.Console.ReadLine() |> System.Int32.Parse
let indecesEqualsToNumber =
inputArray
|> Array.mapi (fun i x -> (x, i))
|> Array.filter (fun (x, i) -> x = numberToCheckOnEqual)
|> Array.map (fun (x, i) -> i)
|> Array.toList
printf "%d equals to %d: %A\n" (indecesEqualsToNumber |> List.length) numberToCheckOnEqual indecesEqualsToNumber
// Second part
printf "a: "
let a = System.Console.ReadLine() |> System.Int32.Parse
printf "b: "
let b = System.Console.ReadLine() |> System.Int32.Parse
let sum =
inputArray.[a..b]
|> Array.sum
printf "sum of array [%d..%d]: %d\n" a b sum
// Last part
let finalArray =
inputArray
|> Array.map (fun x -> if x < 0 then x*x else x)
printf "final array: %A" finalArray
System.Console.ReadKey true |> ignore
0