<commit_before>import Control.Monad
import Data.List
import Data.List.Extra
import Data.Maybe
import qualified Data.Map as Map

--partitions :: Eq a => [a] -> [([a], [a])]
partitions cost xs =
  do l <- subsequences xs
     guard $ sum l == cost
     return (l, xs \\ l)

--partitions3 :: Eq a => [a] -> [([a], [a], [a])]
partitions3 cost l =
  do (a, b) <- partitions cost l
     (b', c) <- partitions cost b
     return (a, b', c)

--search :: [Int] -> Int
search packages =
  do (a, bc) <- partitions cost packages
     guard $ length a <= 6
     guard $ not $ null $ partitions cost bc
     return (length a, product a)

  where cost = sum packages `div` 3

--pack :: [Int] -> Int
pack packages = search packages

--solve :: String -> Int
solve = pack . map read . lines

answer f = interact $ (++"\n") . show . f
main = answer solve<commit_msg>Belated checkin of an upgrade to 24. Do a pruning search using a pruning search monad.<commit_after>-- For Prune
import Control.Monad
import Control.Monad.Reader
import Control.Monad.ListT
--import Control.Monad.Trans.List
import Data.List.Class

import Data.List
import Data.List.Extra
import Data.Maybe
import qualified Data.Map as Map

type Prune r a = ListT (Reader (Maybe r)) a

--pick :: [a] -> Prune a
pick = fromList

prune :: (a -> Bool) -> Prune a ()
prune f =
  do v <- lift ask
     case v of
       Nothing -> return ()
       Just v' -> guard $ f v'

runPrune :: Prune a a -> [a]
runPrune m = run Nothing m
  where run v m = case runReader (runListT m) v of
          Nil -> []
          Cons x xs -> x : run (Just x) xs


--partitions :: Eq a => [a] -> [([a], [a])]
partitions cost xs =
  do l <- subsequences xs
     guard $ sum l == cost
     return (l, xs \\ l)

search :: [Int] -> Prune (Int, Int) (Int, Int)
search packages =
  do (a, bc) <- pick $ partitions cost packages
     let v = (length a, product a)
     prune (v<)
     guard $ not $ null $ partitions cost bc
     return v

  where cost = sum packages `div` 3


--pack :: [Int] -> Int
pack packages = search packages

--solve :: String -> Int
solve = runPrune . pack . map read . lines

answer f = interact $ (++"\n") . show . f
main = answer solve
{'fraction_non_alphanumeric': 0.14049586776859505, 'fraction_numerical': 0.0032139577594123047, 'mean_word_length': 2.520193861066236, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3410229', 'n_tokens_mistral': 751, 'n_tokens_neox': 718, 'n_words': 302}