Compare commits
3 Commits
woodpekcer
...
54eb8b20e9
Author | SHA1 | Date | |
---|---|---|---|
|
54eb8b20e9 | ||
|
a9afb23c79 | ||
|
afe82facb6 |
@@ -3,17 +3,6 @@ steps:
|
||||
image: nixos/nix
|
||||
commands:
|
||||
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
|
||||
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=true || echo 'First publish failed'"
|
||||
- "nix develop --command sh -c 'patchelf --set-interpreter $LINKER_PATH /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc'"
|
||||
- "ls -al /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "chmod a+x /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "ls -al /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc"
|
||||
- "whoami"
|
||||
- "cp -r AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/obj /tmp/obj"
|
||||
- "nix develop --command sh -c 'ls -la $LINKER_PATH'"
|
||||
- "nix develop --command sh -c 'strace /tmp/dotnet-home/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.0/tools/ilc /tmp/obj/Release/net8.0/linux-x64/native/AdventOfCode2023.FSharp.ilc.rsp'"
|
||||
- "nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release -p:PublishAot=true"
|
||||
# Lint
|
||||
- "nix flake check"
|
||||
# Test
|
||||
|
@@ -3,14 +3,6 @@ namespace AdventOfCode2023
|
||||
[<RequireQualifiedAccess>]
|
||||
module Arithmetic =
|
||||
|
||||
[<Struct>]
|
||||
type EuclidResult<'a> =
|
||||
{
|
||||
Hcf : 'a
|
||||
A : 'a
|
||||
B : 'a
|
||||
}
|
||||
|
||||
/// Compute floor(sqrt(i)).
|
||||
let inline sqrt (i : ^a) =
|
||||
if i <= LanguagePrimitives.GenericOne then
|
||||
@@ -33,14 +25,22 @@ module Arithmetic =
|
||||
go LanguagePrimitives.GenericOne
|
||||
|
||||
/// Find Hcf, A, B s.t. A * a + B * b = Hcf, and Hcf is the highest common factor of a and b.
|
||||
let inline euclideanAlgorithm (a : ^a) (b : ^a) : EuclidResult< ^a > =
|
||||
let inline euclideanAlgorithm
|
||||
(a : ^a)
|
||||
(b : ^a)
|
||||
: {|
|
||||
Hcf : ^a
|
||||
A : ^a
|
||||
B : ^a
|
||||
|}
|
||||
=
|
||||
let rec go rMin1 r sMin1 s tMin1 t =
|
||||
if r = LanguagePrimitives.GenericZero then
|
||||
{
|
||||
{|
|
||||
Hcf = rMin1
|
||||
A = sMin1
|
||||
B = tMin1
|
||||
}
|
||||
|}
|
||||
else
|
||||
let newQ = rMin1 / r
|
||||
go r (rMin1 - newQ * r) s (sMin1 - newQ * s) t (tMin1 - newQ * t)
|
||||
@@ -60,8 +60,8 @@ module Arithmetic =
|
||||
if a = maxA then
|
||||
result
|
||||
else
|
||||
{
|
||||
{|
|
||||
Hcf = result.Hcf
|
||||
A = result.B
|
||||
B = result.A
|
||||
}
|
||||
|}
|
||||
|
@@ -78,33 +78,31 @@ module Day8 =
|
||||
let part2 (s : string) =
|
||||
let data = parse s
|
||||
|
||||
let startingNodes = ResizeArray ()
|
||||
|
||||
for key in data.Nodes.Keys do
|
||||
if key.[key.Length - 1] = 'A' then
|
||||
startingNodes.Add key
|
||||
let startingNodes =
|
||||
data.Nodes.Keys
|
||||
|> Seq.choose (fun k -> if k.[k.Length - 1] = 'A' then Some k else None)
|
||||
|> Seq.toArray
|
||||
|
||||
let periods =
|
||||
Array.init
|
||||
startingNodes.Count
|
||||
(fun startNode ->
|
||||
let mutable i = 0
|
||||
let mutable currentNode = startingNodes.[startNode]
|
||||
let mutable answer = 0ul
|
||||
startingNodes
|
||||
|> Array.map (fun startNode ->
|
||||
let mutable i = 0
|
||||
let mutable currentNode = startNode
|
||||
let mutable answer = 0ul
|
||||
|
||||
while currentNode.[currentNode.Length - 1] <> 'Z' do
|
||||
let instruction = data.Nodes.[currentNode]
|
||||
while currentNode.[currentNode.Length - 1] <> 'Z' do
|
||||
let instruction = data.Nodes.[currentNode]
|
||||
|
||||
if data.Steps.[i] then
|
||||
// "true" is R
|
||||
currentNode <- snd instruction
|
||||
else
|
||||
currentNode <- fst instruction
|
||||
if data.Steps.[i] then
|
||||
// "true" is R
|
||||
currentNode <- snd instruction
|
||||
else
|
||||
currentNode <- fst instruction
|
||||
|
||||
i <- (i + 1) % data.Steps.Length
|
||||
answer <- answer + 1ul
|
||||
i <- (i + 1) % data.Steps.Length
|
||||
answer <- answer + 1ul
|
||||
|
||||
uint64 answer
|
||||
)
|
||||
uint64 answer
|
||||
)
|
||||
|
||||
lcm periods
|
||||
|
@@ -166,7 +166,6 @@ module Program =
|
||||
Path.Combine (dir.FullName, "day8part1.txt") |> File.ReadAllText
|
||||
with :? FileNotFoundException ->
|
||||
Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
||||
|
||||
sw.Restart ()
|
||||
let part1 = Day8.part1 input
|
||||
sw.Stop ()
|
||||
|
21
flake.lock
generated
21
flake.lock
generated
@@ -18,26 +18,6 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix-ld": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701153607,
|
||||
"narHash": "sha256-h+odOVyiGmEERMECoFOj5P7FPiMR8IPRzroFA4sKivg=",
|
||||
"owner": "Mic92",
|
||||
"repo": "nix-ld",
|
||||
"rev": "bf5aa84a713c31d95b4307e442e966d6c7fd7ae7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "Mic92",
|
||||
"repo": "nix-ld",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1701253981,
|
||||
@@ -57,7 +37,6 @@
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nix-ld": "nix-ld",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
|
13
flake.nix
13
flake.nix
@@ -3,17 +3,12 @@
|
||||
inputs = {
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nix-ld = {
|
||||
url = "github:Mic92/nix-ld";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
nix-ld,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
@@ -30,14 +25,9 @@
|
||||
pkgs.darwin.apple_sdk.frameworks.GSS
|
||||
]
|
||||
else [];
|
||||
in let
|
||||
deps = darwinDeps ++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu];
|
||||
in {
|
||||
devShells = {
|
||||
default = pkgs.mkShell {
|
||||
HOME = "/tmp/dotnet-home";
|
||||
NUGET_PACKAGES = "/tmp/dotnet-home/.nuget/packages";
|
||||
LINKER_PATH = "${pkgs.stdenv.cc}/nix-support/dynamic-linker";
|
||||
buildInputs = with pkgs;
|
||||
[
|
||||
(with dotnetCorePackages;
|
||||
@@ -46,7 +36,8 @@
|
||||
dotnetPackages.Nuget
|
||||
])
|
||||
]
|
||||
++ [pkgs.alejandra pkgs.patchelf pkgs.strace];
|
||||
++ darwinDeps
|
||||
++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu pkgs.alejandra];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user