First commit
authorGrégory Burri <gregory.burri@matisa.ch>
Fri, 30 Nov 2018 10:42:27 +0000 (11:42 +0100)
committerGrégory Burri <gregory.burri@matisa.ch>
Fri, 30 Nov 2018 10:42:27 +0000 (11:42 +0100)
.gitignore [new file with mode: 0644]
.vscode/launch.json [new file with mode: 0644]
.vscode/tasks.json [new file with mode: 0644]
AdventOfCode2018.fsproj [new file with mode: 0644]
Day01.fs [new file with mode: 0644]
Program.fs [new file with mode: 0644]
Tests/Day01 tests.fs [new file with mode: 0644]
Tests/Tests.fsproj [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..bd700f9
--- /dev/null
@@ -0,0 +1,2 @@
+bin\r
+obj
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644 (file)
index 0000000..1508356
--- /dev/null
@@ -0,0 +1,26 @@
+{\r
+    // Use IntelliSense to learn about possible attributes.\r
+    // Hover to view descriptions of existing attributes.\r
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\r
+    "version": "0.2.0",\r
+    "configurations": [\r
+        {\r
+            "name": ".NET Core Launch (console)",\r
+            "type": "coreclr",\r
+            "request": "launch",\r
+            "preLaunchTask": "build",\r
+            "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/AdventOfCode2018.dll",\r
+            "args": [],\r
+            "cwd": "${workspaceFolder}",\r
+            "console": "internalConsole",\r
+            "stopAtEntry": false,\r
+            "internalConsoleOptions": "openOnSessionStart"\r
+        },\r
+        {\r
+            "name": ".NET Core Attach",\r
+            "type": "coreclr",\r
+            "request": "attach",\r
+            "processId": "${command:pickProcess}"\r
+        }\r
+    ]\r
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644 (file)
index 0000000..a914fef
--- /dev/null
@@ -0,0 +1,17 @@
+{
+    // See https://go.microsoft.com/fwlink/?LinkId=733558
+    // for the documentation about the tasks.json format
+    "version": "2.0.0",
+    "tasks": [
+        {
+            "label": "build",
+            "command": "dotnet build",
+            "type": "shell",
+            "group": "build",
+            "presentation": {
+                "reveal": "silent"
+            },
+            "problemMatcher": "$msCompile"
+        }
+    ]
+}
\ No newline at end of file
diff --git a/AdventOfCode2018.fsproj b/AdventOfCode2018.fsproj
new file mode 100644 (file)
index 0000000..5bfcb35
--- /dev/null
@@ -0,0 +1,17 @@
+<Project Sdk="Microsoft.NET.Sdk">\r
+\r
+  <PropertyGroup>\r
+    <OutputType>Exe</OutputType>\r
+    <TargetFramework>netcoreapp2.1</TargetFramework>\r
+  </PropertyGroup>\r
+\r
+  <ItemGroup>\r
+    <Compile Include="Day01.fs" />\r
+    <Compile Include="Program.fs" />\r
+\r
+    <Content Include="Data\day01.input">\r
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
+    </Content>\r
+  </ItemGroup>\r
+\r
+</Project>\r
diff --git a/Day01.fs b/Day01.fs
new file mode 100644 (file)
index 0000000..ca6f6b2
--- /dev/null
+++ b/Day01.fs
@@ -0,0 +1,5 @@
+module AdventOfCode2018.Day01\r
+\r
+let readDigit d = int d - int '0'\r
+\r
+let parseInput (str : string) : string = str\r
diff --git a/Program.fs b/Program.fs
new file mode 100644 (file)
index 0000000..1f93628
--- /dev/null
@@ -0,0 +1,37 @@
+module AdventOfCode2018.Main\r
+\r
+open System\r
+open System.IO\r
+\r
+let day01 () =\r
+    let input = File.ReadAllText "Data/day01.input" |> Day01.parseInput\r
+    input\r
+\r
+let days : (unit -> string) array =\r
+    [|\r
+        day01\r
+    |]\r
+\r
+let doDay (n : int) =\r
+    if n < 1 then\r
+        ArgumentException "day number must be greater or equal to 1" |> raise\r
+    elif n > days.Length then\r
+        NotImplementedException (sprintf "no implementation for day %i" n) |> raise\r
+    else\r
+        let sw = Diagnostics.Stopwatch ()\r
+        sw.Start ()\r
+        let result = days.[n - 1] ()\r
+        printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds\r
+\r
+[<EntryPoint>]\r
+let main argv =\r
+    printfn "https://adventofcode.com/2018"\r
+\r
+    if argv.Length > 0 then\r
+        doDay (int argv.[0])\r
+    else\r
+        for d = 1 to days.Length do\r
+            doDay d\r
+\r
+    Console.Read () |> ignore\r
+    0\r
diff --git a/Tests/Day01 tests.fs b/Tests/Day01 tests.fs
new file mode 100644 (file)
index 0000000..6e1290d
--- /dev/null
@@ -0,0 +1,15 @@
+module AdventOfCode2018.Tests\r
+\r
+open System\r
+\r
+open Xunit\r
+open Xunit.Abstractions\r
+open Swensen.Unquote\r
+\r
+open AdventOfCode2018\r
+\r
+type ``Day01 tests`` (output : ITestOutputHelper) =\r
+\r
+    [<Fact>]\r
+    let ``(Part1) My test`` () =\r
+        1 =! 2\r
diff --git a/Tests/Tests.fsproj b/Tests/Tests.fsproj
new file mode 100644 (file)
index 0000000..6458ea4
--- /dev/null
@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">\r
+\r
+  <PropertyGroup>\r
+    <TargetFramework>netcoreapp2.1</TargetFramework>\r
+    <IsPackable>false</IsPackable>\r
+  </PropertyGroup>\r
+\r
+  <ItemGroup>\r
+    <Compile Include="Day01 tests.fs" />\r
+  </ItemGroup>\r
+\r
+  <ItemGroup>\r
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />\r
+    <PackageReference Include="Unquote" Version="4.0.0" />\r
+    <PackageReference Include="xunit" Version="2.4.0" />\r
+    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />\r
+  </ItemGroup>\r
+\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\AdventOfCode2018.fsproj" />\r
+  </ItemGroup>\r
+\r
+</Project>\r