From 032c6467aaa25a9cf7d19baf0b44f5e61cdcd79e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9gory=20Burri?= Date: Fri, 30 Nov 2018 11:42:27 +0100 Subject: [PATCH] First commit --- .gitignore | 2 ++ .vscode/launch.json | 26 ++++++++++++++++++++++++++ .vscode/tasks.json | 17 +++++++++++++++++ AdventOfCode2018.fsproj | 17 +++++++++++++++++ Day01.fs | 5 +++++ Program.fs | 37 +++++++++++++++++++++++++++++++++++++ Tests/Day01 tests.fs | 15 +++++++++++++++ Tests/Tests.fsproj | 23 +++++++++++++++++++++++ 8 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 AdventOfCode2018.fsproj create mode 100644 Day01.fs create mode 100644 Program.fs create mode 100644 Tests/Day01 tests.fs create mode 100644 Tests/Tests.fsproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd700f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +obj \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1508356 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/AdventOfCode2018.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a914fef --- /dev/null +++ b/.vscode/tasks.json @@ -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 index 0000000..5bfcb35 --- /dev/null +++ b/AdventOfCode2018.fsproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp2.1 + + + + + + + + PreserveNewest + + + + diff --git a/Day01.fs b/Day01.fs new file mode 100644 index 0000000..ca6f6b2 --- /dev/null +++ b/Day01.fs @@ -0,0 +1,5 @@ +module AdventOfCode2018.Day01 + +let readDigit d = int d - int '0' + +let parseInput (str : string) : string = str diff --git a/Program.fs b/Program.fs new file mode 100644 index 0000000..1f93628 --- /dev/null +++ b/Program.fs @@ -0,0 +1,37 @@ +module AdventOfCode2018.Main + +open System +open System.IO + +let day01 () = + let input = File.ReadAllText "Data/day01.input" |> Day01.parseInput + input + +let days : (unit -> string) array = + [| + day01 + |] + +let doDay (n : int) = + if n < 1 then + ArgumentException "day number must be greater or equal to 1" |> raise + elif n > days.Length then + NotImplementedException (sprintf "no implementation for day %i" n) |> raise + else + let sw = Diagnostics.Stopwatch () + sw.Start () + let result = days.[n - 1] () + printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds + +[] +let main argv = + printfn "https://adventofcode.com/2018" + + if argv.Length > 0 then + doDay (int argv.[0]) + else + for d = 1 to days.Length do + doDay d + + Console.Read () |> ignore + 0 diff --git a/Tests/Day01 tests.fs b/Tests/Day01 tests.fs new file mode 100644 index 0000000..6e1290d --- /dev/null +++ b/Tests/Day01 tests.fs @@ -0,0 +1,15 @@ +module AdventOfCode2018.Tests + +open System + +open Xunit +open Xunit.Abstractions +open Swensen.Unquote + +open AdventOfCode2018 + +type ``Day01 tests`` (output : ITestOutputHelper) = + + [] + let ``(Part1) My test`` () = + 1 =! 2 diff --git a/Tests/Tests.fsproj b/Tests/Tests.fsproj new file mode 100644 index 0000000..6458ea4 --- /dev/null +++ b/Tests/Tests.fsproj @@ -0,0 +1,23 @@ + + + + netcoreapp2.1 + false + + + + + + + + + + + + + + + + + + -- 2.45.2