From 9dc73e73af6ece3234d78b81b7d1e6c8b9c3722e Mon Sep 17 00:00:00 2001 From: Artem-Darius Weber Date: Fri, 18 Apr 2025 08:50:45 +0300 Subject: [PATCH] lab 6 task 10 --- lab6/Makefile | 12 ++++++++++- lab6/task10/Program.fs | 42 +++++++++++++++++++++++++++++++++++++++ lab6/task10/task10.fsproj | 8 ++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lab6/task10/Program.fs create mode 100644 lab6/task10/task10.fsproj diff --git a/lab6/Makefile b/lab6/Makefile index 5788751..2efc68d 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 +.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 # task1 run: @@ -101,3 +101,13 @@ build-task9: clean-task9: cd task9 && dotnet clean + +# task10 +task10: + cd task10 && dotnet run --project task10.fsproj + +build-task10: + cd task10 && dotnet build + +clean-task10: + cd task10 && dotnet clean diff --git a/lab6/task10/Program.fs b/lab6/task10/Program.fs new file mode 100644 index 0000000..2853002 --- /dev/null +++ b/lab6/task10/Program.fs @@ -0,0 +1,42 @@ +open System + +let readStringList () = + let rec readLines acc = + let line = Console.ReadLine() + if String.IsNullOrEmpty(line) then + List.rev acc + else + readLines (line :: acc) + readLines [] + +let sortByLength strings = + strings |> List.sortBy (fun s -> s.Length) + +let printStringList strings = + strings |> List.iter (fun s -> printfn "%s" s) + +let demonstrateWithSample () = + let sampleStrings = ["hello"; "world"; "a"; "programming"; "test"] + printfn "Original list:" + printStringList sampleStrings + printfn "\nSorted by length:" + let sorted = sortByLength sampleStrings + printStringList sorted + +[] +let main argv = + printfn "Enter strings (empty line to finish):" + let strings = readStringList () + + if List.isEmpty strings then + printfn "No strings entered. Using sample data:" + demonstrateWithSample () + else + printfn "\nOriginal strings:" + printStringList strings + + printfn "\nSorted by length:" + let sortedStrings = sortByLength strings + printStringList sortedStrings + + 0 \ No newline at end of file diff --git a/lab6/task10/task10.fsproj b/lab6/task10/task10.fsproj new file mode 100644 index 0000000..1cddbd7 --- /dev/null +++ b/lab6/task10/task10.fsproj @@ -0,0 +1,8 @@ + + + + Exe + net7.0 + + + \ No newline at end of file