This commit is contained in:
Smaug123
2023-12-23 15:24:43 +00:00
parent fd5b914237
commit b0ebbe5842
3 changed files with 20 additions and 21 deletions

View File

@@ -265,6 +265,7 @@ module Day19 =
AcceptanceCriterion.Base (rule.Component, 1, rule.Operand - 1)
else
AcceptanceCriterion.Base (rule.Component, rule.Operand + 1, 4000)
let negCond =
if rule.IsLess then
AcceptanceCriterion.Base (rule.Component, rule.Operand, 4000)
@@ -272,28 +273,27 @@ module Day19 =
AcceptanceCriterion.Base (rule.Component, 1, rule.Operand)
match rule.Target with
| Register target ->
acOr (acAnd cond (acceptance store workflows target)) (acAnd negCond crit)
| Accept ->
acOr cond (acAnd negCond crit)
| Reject ->
acAnd negCond crit
| Register target -> acOr (acAnd cond (acceptance store workflows target)) (acAnd negCond crit)
| Accept -> acOr cond (acAnd negCond crit)
| Reject -> acAnd negCond crit
)
store.[key] <- result
result
let inclusionExclusion
((*[<InlineIfLambda>]*) sizeOf : 'a -> uint64)
((*[<InlineIfLambda>]*) sizeOfTuple : 'a list -> uint64)
( (*[<InlineIfLambda>]*) sizeOf : 'a -> uint64)
( (*[<InlineIfLambda>]*) sizeOfTuple : 'a list -> uint64)
(xs : 'a list)
: uint64
=
let mutable result = List.sumBy sizeOf xs
let mutable i = 2
while i <= xs.Length do
let nTuples = List.nTuples i xs
let sum = List.sumBy sizeOfTuple nTuples
if sum = LanguagePrimitives.GenericZero then
i <- Int32.MaxValue
else
@@ -301,16 +301,18 @@ module Day19 =
result <- result - sum
else
result <- result + sum
i <- i + 1
result
let componentSize (x : (Component * Interval) list) : uint64 =
let mutable weHave =
x
|> List.map snd
|> List.fold (fun x y -> x * uint64 (Interval.size y)) 1uL
x |> List.map snd |> List.fold (fun x y -> x * uint64 (Interval.size y)) 1uL
for i = x.Length + 1 to 4 do
weHave <- weHave * 4000uL
weHave
let intersectionSize (x : (Component * Interval) list list) : uint64 =

View File

@@ -6,15 +6,13 @@ open System
module List =
let rec nTuples (n : int) (xs : 'a list) : 'a list list =
#if DEBUG
if n < 0 then raise (ArgumentException "n cannot be negative")
if n < 0 then
raise (ArgumentException "n cannot be negative")
#endif
match n, xs with
| 0, _ -> [[]]
| 0, _ -> [ [] ]
| _, [] -> []
| _, x :: xs ->
let withX =
nTuples (n - 1) xs
|> List.map (fun xs -> x :: xs)
let withoutX =
nTuples n xs
let withX = nTuples (n - 1) xs |> List.map (fun xs -> x :: xs)
let withoutX = nTuples n xs
withX @ withoutX

View File

@@ -14,8 +14,7 @@ module TestList =
let n = min (abs n) 6
let xs = xs |> List.take (min 10 xs.Length)
let tuples = List.nTuples n xs
tuples
|> List.forall (fun i -> i.Length = n)
tuples |> List.forall (fun i -> i.Length = n)
property 1 ['v'] |> shouldEqual true
property 1 [ 'v' ] |> shouldEqual true
Check.QuickThrowOnFailure property