From 2cd2341673144682569d9eb98915e12919bc4246 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 30 Dec 2025 12:03:21 +0000 Subject: [PATCH] Share frame generation to avoid accidental quadratic complexity Previously each test was computing all frames from scratch. --- haskell/Puzzles/Day4.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/haskell/Puzzles/Day4.hs b/haskell/Puzzles/Day4.hs index 25f409b..ad758fe 100644 --- a/haskell/Puzzles/Day4.hs +++ b/haskell/Puzzles/Day4.hs @@ -26,11 +26,11 @@ puzzle = t <- TL.readFile if isRealData then "../inputs/real/4" else "../inputs/examples/4" input' <- input t @=? drawGrid (mkGrid input' <&> \case InEmpty -> OutEmpty; InRoll -> OutRoll) - , testGroup - "frames" - let frames = Seq.fromList . takeUntil noneAccessible . fmap snd . generateFrames . mkGrid <$> input - nFrames = if isRealData then 58 else 9 - in ( [0 .. nFrames] <&> \n -> + , withResource + (Seq.fromList . takeUntil noneAccessible . fmap snd . generateFrames . mkGrid <$> input) + mempty + \frames -> testGroup "frames" let nFrames = if isRealData then 58 else 9 in + ( [0 .. nFrames] <&> \n -> goldenVsStringDiff (show n) diffCommand (path <> "frames/" <> show n) $ TL.encodeUtf8 . maybe "frame list too short!" drawGrid . Seq.lookup n <$> frames )