Started on part 2

This commit is contained in:
pingu 2024-12-09 10:57:31 +01:00
parent fb98633a56
commit 2e810eb03b

View File

@ -3,7 +3,9 @@ module Main where
import Data.Functor
import Data.List
import Data.List.Extra
import Data.List.Split
import Data.List.Extra hiding (split)
import Debug.Trace
data where
None ::
@ -24,11 +26,25 @@ sort1 s
None -> sort1 $ init s
n -> sort1 $ takeWhile (/= None) s ++ [n] ++ drop 1 (dropWhile (/= None) (init s))
chunks :: [] -> [[]]
chunks =
init . foldr (\a (x:xs) -> if a `elem` x then (a:x):xs else [a]:x:xs) [[]]
fit :: [[]] -> [] -> []
fit s t = let (p,a) = break (elem None) s
(n,a') = span (elem None) a in
if null n then concat s ++ t else
concat p ++ if length n >= length t then t ++ concat a' ++ replicate (length n) None else fit a' t
sort2 :: [] -> []
sort2 = undefined
sort2 s = let c = chunks s -- TODO: needs more work here
fitted = fit (init c) (last c) in
if s == fitted then s else sort2 s
solve :: ([] -> []) -> [] -> Int
solve f s = let fixed = (\(Num n) -> n) <$> f s in
solve f s = let fixed = (\case
Num n -> n
None -> 0) <$> f s in
sum $ zipWith (*) fixed [0..]
main :: IO ()