Skip to content

Commit e0e5c96

Browse files
author
Jon
committed
First Ch. 2 exercises
1 parent c491977 commit e0e5c96

5 files changed

Lines changed: 67 additions & 8 deletions

File tree

‎Ch2P1/Ch2P1.fs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(*Declare a function f: int -> bool such that f(n) = true
2+
exactly when n is divisible by 2 or divisible by 3, but
3+
not divisible by 5. Write down the expected values of
4+
f(24), f(27), f(29), and f(30) and compare with the result.*)
5+
6+
let f n = ((n % 2 = 0) || (n % 3 = 0)) && (n % 5 <> 0)
7+
8+
printf "%b\n" (f 24)
9+
printf "%b\n" (f 27)
10+
printf "%b\n" (f 29)

‎Ch2P1/Ch2P1.fsproj‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Ch2P1.fs" />
10+
</ItemGroup>
11+
12+
</Project>

‎Ch2P2/Ch2P2.fsproj‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
</Project>

‎Ch2P2/Program.fs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(*Declare an F# function pow: string * int -> string, where
2+
pow(s, n) = s*s*...*s, where we use * to denote string
3+
concatenation *)
4+
5+
let rec pow = function
6+
| (a, 0) -> ""
7+
| (a, b) -> a + pow (a, b - 1)
8+
9+
printf "%s\n" (pow ("s", 1))
10+
printf "%s\n" (pow ("s", 2))
11+
printf "%s\n" (pow ("s", 3))
12+
printf "%s\n" (pow ("s", 4))
13+
printf "%s\n" (pow ("s", 5))

‎FunctionalProgrammingWithFSharp.sln‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 25.0.1703.2
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.4.33213.308
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Scratch", "FunctionalProgrammingWithFSharp\Scratch.fsproj", "{A45E3B53-8A4F-4622-BAC7-7ED481268ED0}"
6+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Scratch", "FunctionalProgrammingWithFSharp\Scratch.fsproj", "{A45E3B53-8A4F-4622-BAC7-7ED481268ED0}"
77
EndProject
8-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch1P1", "Ch1P1\Ch1P1.fsproj", "{DA118775-65E2-42A7-B629-18B685557153}"
8+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ch1P1", "Ch1P1\Ch1P1.fsproj", "{DA118775-65E2-42A7-B629-18B685557153}"
99
EndProject
10-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch1P2", "Ch1P2\Ch1P2.fsproj", "{2283FAAA-49A0-4664-ACCB-969E5EDC27C0}"
10+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ch1P2", "Ch1P2\Ch1P2.fsproj", "{2283FAAA-49A0-4664-ACCB-969E5EDC27C0}"
1111
EndProject
12-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch1P4", "Ch1P3\Ch1P4.fsproj", "{48542402-ADA0-4BCA-B830-8F7BA817CD7F}"
12+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ch1P4", "Ch1P3\Ch1P4.fsproj", "{48542402-ADA0-4BCA-B830-8F7BA817CD7F}"
1313
EndProject
14-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch1P5", "Ch1P5\Ch1P5.fsproj", "{F3271073-348B-4215-B8A1-B1F28B67B764}"
14+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ch1P5", "Ch1P5\Ch1P5.fsproj", "{F3271073-348B-4215-B8A1-B1F28B67B764}"
1515
EndProject
16-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch1P6", "Ch1P6\Ch1P6.fsproj", "{405A7799-19AB-4B0D-A12C-1AE3B99AF627}"
16+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ch1P6", "Ch1P6\Ch1P6.fsproj", "{405A7799-19AB-4B0D-A12C-1AE3B99AF627}"
17+
EndProject
18+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch2P1", "Ch2P1\Ch2P1.fsproj", "{0A1FF931-84EA-41F6-839D-4DE9004B3F8A}"
19+
EndProject
20+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Ch2P2", "Ch2P2\Ch2P2.fsproj", "{89F73FDD-1E10-4B35-8525-E423C3E1EFA9}"
1721
EndProject
1822
Global
1923
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,6 +49,14 @@ Global
4549
{405A7799-19AB-4B0D-A12C-1AE3B99AF627}.Debug|Any CPU.Build.0 = Debug|Any CPU
4650
{405A7799-19AB-4B0D-A12C-1AE3B99AF627}.Release|Any CPU.ActiveCfg = Release|Any CPU
4751
{405A7799-19AB-4B0D-A12C-1AE3B99AF627}.Release|Any CPU.Build.0 = Release|Any CPU
52+
{0A1FF931-84EA-41F6-839D-4DE9004B3F8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{0A1FF931-84EA-41F6-839D-4DE9004B3F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{0A1FF931-84EA-41F6-839D-4DE9004B3F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
55+
{0A1FF931-84EA-41F6-839D-4DE9004B3F8A}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{89F73FDD-1E10-4B35-8525-E423C3E1EFA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{89F73FDD-1E10-4B35-8525-E423C3E1EFA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{89F73FDD-1E10-4B35-8525-E423C3E1EFA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{89F73FDD-1E10-4B35-8525-E423C3E1EFA9}.Release|Any CPU.Build.0 = Release|Any CPU
4860
EndGlobalSection
4961
GlobalSection(SolutionProperties) = preSolution
5062
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)