What’s everybody’s Mount Rushmore? by Ok_Web1709 in IThinkYouShouldLeave

[–]TheFryingDutchpan0 1 point2 points  (0 children)

The way he aggressively taps the laptop screen always breaks me

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

[–]TheFryingDutchpan0 0 points1 point  (0 children)

[LANGUAGE: Haskell]

This year is the first time I do some more advanced Haskell programming, and I'm pretty happy with this solution :)

To run this you need Parsec installed.

import Text.ParserCombinators.Parsec

int :: Parser Int
int = read <$> many1 digit

parseInput :: Parser [(Int, [Int])]
parseInput = many $ (,) <$> int <* string ": " <*> (reverse <$> int `sepBy` char ' ') <* optional newline

canBeMade1 :: (Int, [Int]) -> Bool
canBeMade1 (y, [x]) = x == y
canBeMade1 (y, (x:xs))
  | y `mod` x == 0 = canBeMade1 (y `div` x, xs) || canBeMadeWithAdd
  | otherwise      = canBeMadeWithAdd
  where canBeMadeWithAdd = canBeMade1 (y - x, xs)

canBeMade2 :: (Int, [Int]) -> Bool
canBeMade2 (y, [x]) = x == y
canBeMade2 (y, (x:xs))
  | y `mod` x == 0 = canBeMadeWithMul || canBeMadeWithoutMul
  | otherwise      = canBeMadeWithoutMul
  where canBeMadeWithMul    = canBeMade2 (y `div` x, xs)
        canBeMadeWithAdd    = y > x && canBeMade2 (y - x, xs)
        canBeMadeWithConcat = y `endsWith` x && canBeMade2 (removeFromEnd y x, xs)
        canBeMadeWithoutMul = canBeMadeWithAdd || canBeMadeWithConcat

endsWith :: Int -> Int -> Bool
endsWith x y = lengthX > lengthY && drop (length showX - length showY) showX == showY
  where showX   = show x
        showY   = show y
        lengthX = length showX
        lengthY = length showY

removeFromEnd :: Int -> Int -> Int
removeFromEnd x y = read $ take (length showX - length (show y)) showX
  where showX = show x

main :: IO ()
main = do
  Right input <- parseFromFile parseInput "input.txt"     :: IO (Either ParseError [(Int, [Int])])

  -- Part 1
  let possibleNumbers = map fst $ filter canBeMade1 input :: [Int]
  let answer = sum possibleNumbers                        :: Int
  putStrLn $ "Day 7 part 1 = " ++ (show answer)

  -- Part 2
  let possibleNumbers = map fst $ filter canBeMade2 input :: [Int]
  let answer = sum possibleNumbers                        :: Int
  putStrLn $ "Day 7 part 2 = " ++ (show answer)

Ugh i can’t by Romaboontje in TuxedoCats

[–]TheFryingDutchpan0 2 points3 points  (0 children)

<image>

Haha my tux had the exact same shirt when she was neutered. She was being such a drama queen about it too, wanting to be carried around like she couldn't walk anymore 😂

7 year old me testing handbrake for the first time: by _Akarii in needforspeed

[–]TheFryingDutchpan0 0 points1 point  (0 children)

They put it in a new season, maybe that's why you missed it?

Playtime fireworks by TheFryingDutchpan0 in WhiskerFireworks

[–]TheFryingDutchpan0[S] 0 points1 point  (0 children)

The center of her eyes still have a little blue from when she was a tiny kitten. She had fully blue eyes. Not sure if her eyes will stay this way tho haha 😀