• 4 Posts
  • 10 Comments
Joined 8 months ago
cake
Cake day: May 9th, 2024

help-circle
  • Not the first year I participate but the first year I finished, 2021 was my all-time high so far with 42 stars when I was just starting oit and learning python. Knowing that there were more people in the same boat and that there was a competition kept me going, although the competiton also induced a lot of stress, not sure whether I want to keep the competitive attitude.

    Thanks to everyone for uploding solutions, Ideas and program stats, this kept me optimizing away, which was a lot of fun!



  • Haskell

    Have a nice christmas if you’re still celebrating today, otherwise hope you had a nice evening yesterday.

    import Control.Arrow
    import Control.Monad (join)
    import Data.Bifunctor (bimap)
    import qualified Data.List as List
    
    heights = List.transpose
            >>> List.map (pred . List.length . List.takeWhile (== '#'))
    
    parse = lines
            >>> init
            >>> List.groupBy (curry (snd >>> (/= "")))
            >>> List.map (List.filter (/= ""))
            >>> List.partition ((== "#####") . head)
            >>> second (List.map List.reverse)
            >>> join bimap (List.map heights)
    
    cartesianProduct xs ys = [(x, y) | x <- xs, y <- ys]
    
    part1 = uncurry cartesianProduct
            >>> List.map (uncurry (List.zipWith (+)))
            >>> List.filter (List.all (<6))
            >>> List.length
    part2 = const 0
    
    main = getContents
            >>= print
            . (part1 &&& part2)
            . parse
    


  • You could wrap the entirety of your file in a monster macro but you’d still have to assign the macro result to a variable you need to register, which doesn’t sound viable to me at least.

    Maybe you can use a script that would extract all the trait implementations and create the boilerplate glue code for you, something like this:

    grep --recursive --only-matching "impl PluginFunction for \w*" functions/ | sed --quiet "s/functions\/\(.*\)\.rs:impl PluginFunction for \(\w*\)/crate::functions::\1::\2{}.register(\&mut functions_map)/p"
    

    I tried to recreate your situation locally but it may not match perfectly, maybe you’ll have to adjust it a little. When I run it on my file tree which looks like this

    functions
    ├── attr.rs
    ├── export.rs
    └── render.rs
    
    1 directory, 3 files
    

    where every file has a content like this

    // comment
    
    pub struct MyAttrStructName {}
    
    impl PluginFunction for MyAttrStructName {
    
    }
    

    Then I receive the following output:

    crate::functions::attr::MyAttrStructName{}.register(&mut functions_map)
    crate::functions::export::MyExportStructName{}.register(&mut functions_map)
    crate::functions::render::MyRenderStructName{}.register(&mut functions_map)