diff --git a/lab6/Makefile b/lab6/Makefile index 2efc68d..0bc4899 100644 --- a/lab6/Makefile +++ b/lab6/Makefile @@ -1,4 +1,4 @@ -.PHONY: run build clean task1 build-task1 clean-task1 task2 build-task2 clean-task2 task3 build-task3 clean-task3 task4 build-task4 clean-task4 task5 build-task5 clean-task5 task6 build-task6 clean-task6 task7 build-task7 clean-task7 task8 build-task8 clean-task8 task9 build-task9 clean-task9 task10 build-task10 clean-task10 +.PHONY: run build clean task1 build-task1 clean-task1 task2 build-task2 clean-task2 task3 build-task3 clean-task3 task4 build-task4 clean-task4 task5 build-task5 clean-task5 task6 build-task6 clean-task6 task7 build-task7 clean-task7 task8 build-task8 clean-task8 task9 build-task9 clean-task9 task10 build-task10 clean-task10 task16 build-task16 clean-task16 # task1 run: @@ -111,3 +111,13 @@ build-task10: clean-task10: cd task10 && dotnet clean + +# task16 +task16: + cd task16 && dotnet run --project task16.fsproj + +build-task16: + cd task16 && dotnet build + +clean-task16: + cd task16 && dotnet clean diff --git a/lab6/task16/Program.fs b/lab6/task16/Program.fs new file mode 100644 index 0000000..f2851aa --- /dev/null +++ b/lab6/task16/Program.fs @@ -0,0 +1,93 @@ +let task4_church arr = + arr + |> List.mapi (fun i x -> (i, x)) + |> List.sortByDescending snd + |> List.map fst + +let task4_list arr = + arr + |> List.mapi (fun i x -> (i, x)) + |> List.sortByDescending snd + |> List.map fst + +let task14_church arr a b = + arr |> List.filter (fun x -> x >= a && x <= b) |> List.length + +let task14_list arr a b = + arr |> List.filter (fun x -> x >= a && x <= b) |> List.length + +let task24_church arr = + let sorted = arr |> List.sortByDescending id + [sorted.[0]; sorted.[1]] + +let task24_list arr = + let sorted = arr |> List.sortByDescending id + [sorted.[0]; sorted.[1]] + +let task34_church arr a b = + arr |> List.filter (fun x -> x >= a && x <= b) + +let task34_list arr a b = + arr |> List.filter (fun x -> x >= a && x <= b) + +let isInteger (x: float) = x = float (int x) + +let task44_church (arr: float list) = + let rec checkAlternating lst = + match lst with + | [] | [_] -> true + | h1 :: h2 :: t -> + let first = isInteger h1 + let second = isInteger h2 + if first <> second then checkAlternating (h2 :: t) + else false + checkAlternating arr + +let task44_list (arr: float list) = + let rec checkAlternating lst = + match lst with + | [] | [_] -> true + | h1 :: h2 :: t -> + let first = isInteger h1 + let second = isInteger h2 + if first <> second then checkAlternating (h2 :: t) + else false + checkAlternating arr + +let task54_church arr = + arr + |> List.groupBy id + |> List.filter (fun (_, occurrences) -> List.length occurrences > 3) + |> List.map fst + +let task54_list arr = + arr + |> List.groupBy id + |> List.filter (fun (_, occurrences) -> List.length occurrences > 3) + |> List.map fst + +[] +let main argv = + let testArr = [3; 1; 4; 1; 5; 9; 2; 6] + + printfn "Task 4 - Church: %A" (task4_church testArr) + printfn "Task 4 - List: %A" (task4_list testArr) + + printfn "Task 14 - Church: %d" (task14_church testArr 2 5) + printfn "Task 14 - List: %d" (task14_list testArr 2 5) + + printfn "Task 24 - Church: %A" (task24_church testArr) + printfn "Task 24 - List: %A" (task24_list testArr) + + printfn "Task 34 - Church: %A" (task34_church testArr 2 5) + printfn "Task 34 - List: %A" (task34_list testArr 2 5) + + let testFloatArr = [1.0; 2.5; 3.0; 4.7; 5.0] + printfn "Task 44 - Church: %b" (task44_church testFloatArr) + printfn "Task 44 - List: %b" (task44_list testFloatArr) + + let testArr54 = [1; 2; 2; 3; 3; 3; 3; 4; 4; 4; 4; 4; 5] + printfn "Task 54 - Church: %A" (task54_church testArr54) + printfn "Task 54 - List: %A" (task54_list testArr54) + + 0 \ No newline at end of file diff --git a/lab6/task16/task16.fsproj b/lab6/task16/task16.fsproj new file mode 100644 index 0000000..299cf40 --- /dev/null +++ b/lab6/task16/task16.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net7.0 + + + + + + +