Compare commits

...

3 Commits

Author SHA1 Message Date
Smaug123
ee38b17138 README 2023-12-03 17:24:47 +00:00
Smaug123
5c451057bf Licence MIT 2023-12-03 17:21:26 +00:00
Smaug123
4a1d9d1cae Better program 2023-12-03 17:20:55 +00:00
3 changed files with 113 additions and 34 deletions

View File

@@ -5,6 +5,7 @@
#nowarn "9" #nowarn "9"
#endif #endif
open System
open System.Diagnostics open System.Diagnostics
open System.IO open System.IO
@@ -18,49 +19,73 @@ module Program =
let endToEnd = Stopwatch.StartNew () let endToEnd = Stopwatch.StartNew ()
endToEnd.Restart () endToEnd.Restart ()
let dir = DirectoryInfo argv.[0]
let sw = Stopwatch.StartNew () let sw = Stopwatch.StartNew ()
sw.Restart ()
let contents = File.ReadAllBytes argv.[0]
sw.Stop ()
System.Console.Error.WriteLine ("Reading file (us): " + (toUs sw.ElapsedTicks).ToString ())
sw.Restart () do
let resultArr, len, lineCount = Day3.parse contents sw.Restart ()
let input = Path.Combine (dir.FullName, "day1.txt") |> File.ReadAllText
let part1 = Day1.part1 input
sw.Stop ()
Console.WriteLine (part1.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Restart ()
let part2 = Day1.part2 input
sw.Stop ()
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Stop () do
System.Console.Error.WriteLine ("Populating array (us): " + (toUs sw.ElapsedTicks).ToString ()) let input = Path.Combine (dir.FullName, "day2.txt") |> File.ReadAllText
sw.Restart ()
let part1 = Day2.part1 input
sw.Stop ()
Console.WriteLine (part1.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Restart ()
let part2 = Day2.part2 input
sw.Stop ()
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
do
let input = Path.Combine (dir.FullName, "day3.txt") |> File.ReadAllBytes
sw.Restart ()
let resultArr, len, lineCount = Day3.parse input
sw.Stop ()
Console.Error.WriteLine (
(1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString ()
+ "ms parse"
)
#if DEBUG #if DEBUG
let contents = let contents =
{ {
Elements = Array.take len resultArr Elements = Array.take len resultArr
Width = len / lineCount Width = len / lineCount
} }
#else #else
use ptr = fixed resultArr use ptr = fixed resultArr
let contents = let contents =
{ {
Elements = ptr Elements = ptr
Length = len Length = len
Width = len / lineCount Width = len / lineCount
} }
#endif #endif
// |> Array.map (fun s -> Array.init s.Length (fun i -> if s.[i] = '.' then 100uy elif s.[i] = '*' then 255uy elif '0' <= s.[i] && s.[i] <= '9' then byte s.[i] - byte '0' else 254uy)) let part1 = Day3.part1 contents
sw.Stop ()
sw.Restart () Console.WriteLine (part1.ToString ())
let part1 = Day3.part1 contents Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Stop () sw.Restart ()
System.Console.Error.WriteLine ("Part 1 (us): " + (toUs sw.ElapsedTicks).ToString ()) let part2 = Day3.part2 contents
System.Console.WriteLine (part1.ToString ()) Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Restart ()
let part2 = Day3.part2 contents
sw.Stop ()
System.Console.Error.WriteLine ("Part 2 (us): " + (toUs sw.ElapsedTicks).ToString ())
System.Console.WriteLine (part2.ToString ())
endToEnd.Stop () endToEnd.Stop ()
System.Console.Error.WriteLine ("Total (us): " + (toUs endToEnd.ElapsedTicks).ToString ()) Console.Error.WriteLine ((1_000.0 * float endToEnd.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms total")
0 0

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Patrick Stevens
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

33
README.md Normal file
View File

@@ -0,0 +1,33 @@
# Advent of Code 2023
[Puzzle site](https://adventofcode.com/2023).
# Speed
Ahead-of-time compiled with `PublishAot`, M1 Max.
The format is: "answer part1\ntime\nanswer part2\ntime\n...", with possible extra lines indicating how long it took to parse the input if I happen to have split that out.
After day 3:
```
54304
0.549458ms
54418
0.710375ms
2727
0.119959ms
56580
0.155708ms
0.1395ms parse
540131
0.1395ms
86879020
0.840791ms
4.144166ms total
```
# Building yourself
Note that `PublishAot` assumes a lot of stuff about your environment, which is not necessarily true.
The given flake should allow you to complete the publish except for a linking stage at the end: the publish will print out a failed command line, and you'll have to strip out some `-o` flags from it and run it manually.
Then run `dotnet publish` again and it should succeed.