Compare commits
3 Commits
woodpekcer
...
54eb8b20e9
Author | SHA1 | Date | |
---|---|---|---|
|
54eb8b20e9 | ||
|
a9afb23c79 | ||
|
afe82facb6 |
@@ -3,17 +3,6 @@ steps:
|
|||||||
image: nixos/nix
|
image: nixos/nix
|
||||||
commands:
|
commands:
|
||||||
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
|
- 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
|
# Lint
|
||||||
- "nix flake check"
|
- "nix flake check"
|
||||||
# Test
|
# Test
|
||||||
|
@@ -3,14 +3,6 @@ namespace AdventOfCode2023
|
|||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Arithmetic =
|
module Arithmetic =
|
||||||
|
|
||||||
[<Struct>]
|
|
||||||
type EuclidResult<'a> =
|
|
||||||
{
|
|
||||||
Hcf : 'a
|
|
||||||
A : 'a
|
|
||||||
B : 'a
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compute floor(sqrt(i)).
|
/// Compute floor(sqrt(i)).
|
||||||
let inline sqrt (i : ^a) =
|
let inline sqrt (i : ^a) =
|
||||||
if i <= LanguagePrimitives.GenericOne then
|
if i <= LanguagePrimitives.GenericOne then
|
||||||
@@ -33,14 +25,22 @@ module Arithmetic =
|
|||||||
go LanguagePrimitives.GenericOne
|
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.
|
/// 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 =
|
let rec go rMin1 r sMin1 s tMin1 t =
|
||||||
if r = LanguagePrimitives.GenericZero then
|
if r = LanguagePrimitives.GenericZero then
|
||||||
{
|
{|
|
||||||
Hcf = rMin1
|
Hcf = rMin1
|
||||||
A = sMin1
|
A = sMin1
|
||||||
B = tMin1
|
B = tMin1
|
||||||
}
|
|}
|
||||||
else
|
else
|
||||||
let newQ = rMin1 / r
|
let newQ = rMin1 / r
|
||||||
go r (rMin1 - newQ * r) s (sMin1 - newQ * s) t (tMin1 - newQ * t)
|
go r (rMin1 - newQ * r) s (sMin1 - newQ * s) t (tMin1 - newQ * t)
|
||||||
@@ -60,8 +60,8 @@ module Arithmetic =
|
|||||||
if a = maxA then
|
if a = maxA then
|
||||||
result
|
result
|
||||||
else
|
else
|
||||||
{
|
{|
|
||||||
Hcf = result.Hcf
|
Hcf = result.Hcf
|
||||||
A = result.B
|
A = result.B
|
||||||
B = result.A
|
B = result.A
|
||||||
}
|
|}
|
||||||
|
@@ -78,18 +78,16 @@ module Day8 =
|
|||||||
let part2 (s : string) =
|
let part2 (s : string) =
|
||||||
let data = parse s
|
let data = parse s
|
||||||
|
|
||||||
let startingNodes = ResizeArray ()
|
let startingNodes =
|
||||||
|
data.Nodes.Keys
|
||||||
for key in data.Nodes.Keys do
|
|> Seq.choose (fun k -> if k.[k.Length - 1] = 'A' then Some k else None)
|
||||||
if key.[key.Length - 1] = 'A' then
|
|> Seq.toArray
|
||||||
startingNodes.Add key
|
|
||||||
|
|
||||||
let periods =
|
let periods =
|
||||||
Array.init
|
startingNodes
|
||||||
startingNodes.Count
|
|> Array.map (fun startNode ->
|
||||||
(fun startNode ->
|
|
||||||
let mutable i = 0
|
let mutable i = 0
|
||||||
let mutable currentNode = startingNodes.[startNode]
|
let mutable currentNode = startNode
|
||||||
let mutable answer = 0ul
|
let mutable answer = 0ul
|
||||||
|
|
||||||
while currentNode.[currentNode.Length - 1] <> 'Z' do
|
while currentNode.[currentNode.Length - 1] <> 'Z' do
|
||||||
|
@@ -166,7 +166,6 @@ module Program =
|
|||||||
Path.Combine (dir.FullName, "day8part1.txt") |> File.ReadAllText
|
Path.Combine (dir.FullName, "day8part1.txt") |> File.ReadAllText
|
||||||
with :? FileNotFoundException ->
|
with :? FileNotFoundException ->
|
||||||
Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
||||||
|
|
||||||
sw.Restart ()
|
sw.Restart ()
|
||||||
let part1 = Day8.part1 input
|
let part1 = Day8.part1 input
|
||||||
sw.Stop ()
|
sw.Stop ()
|
||||||
|
21
flake.lock
generated
21
flake.lock
generated
@@ -18,26 +18,6 @@
|
|||||||
"type": "github"
|
"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": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1701253981,
|
"lastModified": 1701253981,
|
||||||
@@ -57,7 +37,6 @@
|
|||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nix-ld": "nix-ld",
|
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
13
flake.nix
13
flake.nix
@@ -3,17 +3,12 @@
|
|||||||
inputs = {
|
inputs = {
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
nix-ld = {
|
|
||||||
url = "github:Mic92/nix-ld";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
flake-utils,
|
flake-utils,
|
||||||
nix-ld,
|
|
||||||
}:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system: let
|
system: let
|
||||||
@@ -30,14 +25,9 @@
|
|||||||
pkgs.darwin.apple_sdk.frameworks.GSS
|
pkgs.darwin.apple_sdk.frameworks.GSS
|
||||||
]
|
]
|
||||||
else [];
|
else [];
|
||||||
in let
|
|
||||||
deps = darwinDeps ++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu];
|
|
||||||
in {
|
in {
|
||||||
devShells = {
|
devShells = {
|
||||||
default = pkgs.mkShell {
|
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;
|
buildInputs = with pkgs;
|
||||||
[
|
[
|
||||||
(with dotnetCorePackages;
|
(with dotnetCorePackages;
|
||||||
@@ -46,7 +36,8 @@
|
|||||||
dotnetPackages.Nuget
|
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