diff --git a/hw1/hw1.sln b/hw1/hw1.sln new file mode 100644 index 0000000..82a77d5 --- /dev/null +++ b/hw1/hw1.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "hw1", "hw1\hw1.fsproj", "{0D25A530-A669-4CFC-92DF-161703584B9A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0D25A530-A669-4CFC-92DF-161703584B9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D25A530-A669-4CFC-92DF-161703584B9A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D25A530-A669-4CFC-92DF-161703584B9A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D25A530-A669-4CFC-92DF-161703584B9A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/hw1/hw1/Program.fs b/hw1/hw1/Program.fs new file mode 100644 index 0000000..36c958c --- /dev/null +++ b/hw1/hw1/Program.fs @@ -0,0 +1,48 @@ +open System + +let factorial x = + if x < 0 then + raise (ArgumentException "n должно быть неотрицательным") + if x = 0 then + 1 + else + let rec factorialCount x i acc = + if x = i then + i * acc + else + factorialCount x (i + 1) (acc * i) + factorialCount x 1 1 + +let fibonacci n = + if n < 0 then + raise (ArgumentException "n должно быть неотрицательным") + else + let rec fibonacciCount number acc1 acc2 = + if number = n then + acc1 + else + fibonacciCount (number + 1) acc2 (acc1 + acc2) + fibonacciCount 0 0 1 + +let reverseList list = + let rec reverseListMaker list listNew = + match list with + | [] -> listNew + | _ -> reverseListMaker (List.tail list) ((List.head list) :: listNew) + reverseListMaker list [] + +let makeList n m = + let rec countPower n m list = + if n = m then + list + else + countPower n (m - 1) (pown 2 m :: list) + countPower n (n + m) [] + +let findFirst list number = + let rec findElement list number i = + match list with + | [] -> raise(ArgumentException "Нет такого элемента в списке") + | h :: t when h = number -> i + | _ -> findElement (List.tail list) number (i + 1) + findElement list number 0 \ No newline at end of file diff --git a/hw1/hw1/hw1.fsproj b/hw1/hw1/hw1.fsproj new file mode 100644 index 0000000..761405f --- /dev/null +++ b/hw1/hw1/hw1.fsproj @@ -0,0 +1,13 @@ + + + + Exe + net6.0 + Windows + + + + + + +