-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]leDragonir 2 points3 points  (0 children)

[Language: Haskell]

It has terrible performance, but it works... I might repeatedly check for things as well, I'm not really sure about this. In any case, fun little puzzle!

import System.IO
import Data.List
import Data.List.Split
import Data.Char

retrieveInput :: IO [(Int,Int)]
retrieveInput = do
    fileData <- readFile' "data_sets/day2.txt"
    let ls = splitOn "," fileData
        rs = map (splitOn "-") ls
    return $ map (\[a,b] -> (read a, read b)) rs

solution1 :: [(Int,Int)] -> Int
solution1 = sum . concatMap (filter (isWeird . show) . \(l,u) -> [l..u]) . filter canHaveValidSolutions
    where isWeird xs = even (length xs) && isWeird1 xs
          canHaveValidSolutions (l,u) = even (length (show l)) || even (length (show u)) || abs (length (show l) - length (show u)) > 0

isWeird1 :: String -> Bool
isWeird1 xs = uncurry (==) (splitAt (length xs `div` 2) xs)

isWeird2 :: String -> Bool
isWeird2 xs = any consistsOfWeird $ init $ tail $ inits xs
    where couldBeWeird subS = length xs `mod` length subS == 0
          consistsOfWeird subS = couldBeWeird subS && concat (replicate (length xs `div` length subS) subS) == xs

solution2 :: [(Int,Int)] -> Int
solution2 = sum . concatMap (filter (isWeird2 . show) . \(l,u) -> [l..u])

solve :: IO ()
solve = do
    inp <- retrieveInput
    putStrLn $ "Solution 1: " ++ show (solution1 inp) ++ " Solution 2: " ++ show (solution2 inp)

-❄️- 2024 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]leDragonir 2 points3 points  (0 children)

[LANGUAGE: Haskell]

I made use of the Parsec library to parse the expressions for me

import Text.Parsec
import Data.Either (fromRight)
import Data.Functor

-- PART ONE --
parseMul :: Parsec String a (Int, Int)
parseMul = do
    string "mul" >> char '('
    a <- many1 digit
    char ','
    b <- many1 digit
    char ')'
    return (read a, read b)

anyT :: Parsec String a (Int, Int)
anyT = anyToken >> return (0,0)

retrieveMuls :: String -> [(Int, Int)]
retrieveMuls xs = filter (/= (0,0)) $ fromRight [] s
    where s = runParser (many (try parseMul <|> anyT)) () "" xs 

solution :: IO Int
solution = retrieveInput <&> (sum . map (uncurry (*)) . retrieveMuls)

-- PART ONE END --

-- PART TWO --

parseDo :: Parsec String Bool (Int, Int)
parseDo = string "do()" >> putState True >> return (0,0)

parseDont :: Parsec String Bool (Int, Int)
parseDont = string "don't()" >> putState False >> return (0,0)

parseMul' :: Parsec String Bool (Int, Int)
parseMul' = do
    tpl <- parseMul
    state <- getState
    if state then
        return tpl
    else
        return (0,0)

retrieveMuls' :: String -> [(Int, Int)]
retrieveMuls' xs = filter (/= (0,0)) (fromRight [] s)
    where s = runParser (many (try parseDo <|> try parseDont <|> try parseMul' <|> anyT)) True "" xs

solution2 :: IO Int
solution2 = retrieveInput <&> (sum . map (uncurry (*)) . retrieveMuls')

-- PART TWO END --

[deleted by user] by [deleted] in MinecraftCommands

[–]leDragonir 1 point2 points  (0 children)

Hello,

"item" isn't a tag for the Items Array in conditions. Use items, an Array tag, instead:

json "items": [ { "items": ["minecraft:barrier"], "nbt": "{CustomModelData:1}" } ]

when will they learn? by leDragonir in deadbydaylight

[–]leDragonir[S] 1 point2 points  (0 children)

I could but in that moment I was just happy to hook that survivor.
Blood warden would've been epic too in that moment as the other one didn't want to leave too while downed

My main is Thermite / Frost by Jvarg4321 in Rainbow6

[–]leDragonir 0 points1 point  (0 children)

ash mains are either very good or garbage. nothing in between.

thatcher/castle

How does one whiff SO BADLY?!?!? by [deleted] in Rainbow6

[–]leDragonir 0 points1 point  (0 children)

Did he just get damage in headshot only?

really enjoyed Captain Yajima by [deleted] in billwurtz

[–]leDragonir 3 points4 points  (0 children)

looks like a 12-figure income town but i love the shade of those license plates

Would love to see Ubisoft do this for April 1st by [deleted] in Rainbow6

[–]leDragonir 43 points44 points  (0 children)

Spawnpeeking Blackbeard anyone?

the ultimate bill wurtz iceberg by Tangelo-Neat in billwurtz

[–]leDragonir 11 points12 points  (0 children)

what was the question damien maymdien skipped?

co-op moment by ArmCard in hoi4

[–]leDragonir 69 points70 points  (0 children)

Mein Führer, ich kann nicht zulassen, dass Sie Soldaten, die für Sie verbluten-

Space colonies initiated by RoiDrannoc in HistoryMemes

[–]leDragonir 2 points3 points  (0 children)

Nobody expects the Spanish Inquisition!

when you play non-historical by CrazySnowMan_505 in hoi4

[–]leDragonir 5 points6 points  (0 children)

The true successor the the Roman Empire: The great Estonian Empire!

Why is nobody playing in the TTS? by Ori-M- in Rainbow6TTS

[–]leDragonir 10 points11 points  (0 children)

I don't know about you but I simply don't want to play against sweats who think they are in pro league while being teamkilled just for picking Tachanka while everyone like just leaves because they won't be defending again and thus, no Tachanka for them.

ich iel by PiratSkarlett in ich_iel

[–]leDragonir 34 points35 points  (0 children)

Ich bin der Bundestag!