[-] lwhjp 5 points 5 days ago
[-] lwhjp 10 points 6 days ago

I tried some of this recently. The peach flavor was a bit too sweet for me, but the plain stuff is <3

[-] lwhjp 9 points 2 weeks ago

That sounds lIke fun! What do you do about hills? Do you have power assist?

[-] lwhjp 7 points 3 weeks ago

It was nice to see some of the same faces (as it were) again from last year!

Also great to see more Haskell solutions, and props to those crazy enough to write in J and Uiua.

[-] lwhjp 15 points 3 weeks ago

Sorry to hear that :/

I think you handled it well.

[-] lwhjp 10 points 1 month ago

Haskell

This was quite fun! I got a bit distracted trying to rewrite safe in point-free style, but I think this version is the most readable. There's probably a more monadic way of writing lessOne as well, but I can't immediately see it.

safe xs = any gradual [diffs, negate <$> diffs]
  where
    diffs = zipWith (-) (drop 1 xs) xs
    gradual = all (`elem` [1 .. 3])

lessOne [] = []
lessOne (x : xs) = xs : map (x :) (lessOne xs)

main = do
  input :: [[Int]] <- map (map read . words) . lines <$> readFile "input02"
  print . length $ filter safe input
  print . length $ filter (any safe . lessOne) input
[-] lwhjp 7 points 1 month ago

Haskell

Plenty of scope for making part 2 faster, but I think simple is best here. Forgot to sort the lists in the first part, which pushed me waaay off the leaderboard.

import Data.List

main = do
  [as, bs] <- transpose . map (map read . words) . lines <$> readFile "input01"
  print . sum $ map abs $ zipWith (-) (sort as) (sort bs)
  print . sum $ map (\a -> a * length (filter (== a) bs)) as
[-] lwhjp 45 points 9 months ago

Most people would use "word", "half-word", "quarter-word" etc, but the Anglophiles insist on "tuppit", "ternary piece", "span" and "chunk" (that's 5 bits, or 12 old bits).

[-] lwhjp 9 points 1 year ago

Maybe it was due to attempting the puzzles in real-time for the first time, but it felt like there was quite a spike in difficulty this year. Day 5 (If You Give A Seed A Fertilizer) in particular was pretty tough for an early puzzle.

Day 8 (Haunted Wasteland), Day 20 (Pulse Propagation) and Day 21 (Step Counter) were (I felt) a bit mean due to hidden properties of the input data.

I particularly liked Day 6 (Wait For It), Day 14 (Parabolic Reflector Dish) and Day 24 (Never Tell Me The Odds), although that one made my brain hurt.

Day 25 (Snowverload) had me reading research papers, although in the end I stumbled across Karger's algorithm. That's the first time I've used a probabilistic approach. This solution in particular was very clever.

I learned the Shoelace formula and Pick's theorem this year, which will be very helpful to remember.

Perhaps I'll try using Prolog or J next year :)

[-] lwhjp 5 points 1 year ago

Haskell

A little slow (1.106s on my machine), but list operations made this really easy to write. I expect somebody more familiar with Haskell than me will be able to come up with a more elegant solution.

Nevertheless, 59th on the global leaderboard today! Woo!

Solution

import Data.List
import qualified Data.Map.Strict as Map
import Data.Semigroup

rotateL, rotateR, tiltW :: Endo [[Char]]
rotateL = Endo $ reverse . transpose
rotateR = Endo $ map reverse . transpose
tiltW = Endo $ map tiltRow
  where
    tiltRow xs =
      let (a, b) = break (== '#') xs
          (os, ds) = partition (== 'O') a
          rest = case b of
            ('#' : b') -> '#' : tiltRow b'
            [] -> []
       in os ++ ds ++ rest

load rows = sum $ map rowLoad rows
  where
    rowLoad = sum . map (length rows -) . elemIndices 'O'

lookupCycle xs i =
  let (o, p) = findCycle 0 Map.empty xs
   in xs !! if i < o then i else (i - o) `rem` p + o
  where
    findCycle i seen (x : xs) =
      case seen Map.!? x of
        Just j -> (j, i - j)
        Nothing -> findCycle (i + 1) (Map.insert x i seen) xs

main = do
  input <- lines <$> readFile "input14"
  print . load . appEndo (tiltW <> rotateL) $ input
  print $
    load $
      lookupCycle
        (iterate (appEndo $ stimes 4 (rotateR <> tiltW)) $ appEndo rotateL input)
        1000000000

42.028 line-seconds

[-] lwhjp 6 points 1 year ago

Haskell

This was fun and (fairly) easy! Off-by-one errors are a likely source of bugs here.

import Control.Monad
import Data.List
import Data.List.Split
import Data.Maybe

score d pat = ((100 *) <$> search pat) `mplus` search (transpose pat)
  where
    search pat' = find ((d ==) . rdiff pat') [1 .. length pat' - 1]
    rdiff pat' i =
      let (a, b) = splitAt i pat'
       in length $ filter (uncurry (/=)) $ zip (concat $ reverse a) (concat b)

main = do
  input <- splitOn [""] . lines <$> readFile "input13"
  let go d = print . sum . map (fromJust . score d) $ input
  go 0
  go 1

Line-seconds score: 0.102 πŸ˜‰

6
Rating problems and solutions (self.advent_of_code)
submitted 1 year ago by lwhjp to c/advent_of_code@programming.dev

We all know and love (!) the leaderboard, but how about a different method?

One can solve a problem with a simple, naive method resulting in a short program and long runtime, or put in lots of explicit optimizations for more code and shorter runtime. (Or if you're really good, a short, fast program!)

I propose the line-second.

Take the number of lines in your program (eg, 42 lines) and the runtime (eg 0.096 seconds). Multiply these together to get a score of 4.032 line-seconds.

A smaller score is a shorter, faster program.

Similarly, (for a particular solver), a larger score is a "harder" problem.

[-] lwhjp 76 points 1 year ago

TDD

const max12 = (x, y) => {
    if (x === 1 &amp;&amp; y === 2) {
        return 2;
    } else if (x === 7 &amp;&amp; y === 4) {
        return 7;
    } else {
        return x;
    }
};
6
submitted 1 year ago by lwhjp to c/cruciverbalism

Tried a little too hard to go with a theme on this one, and some of the clues are a bit contrived. Feel free to suggest alternatives!

4
Puzzle #5 (lwh.jp)
submitted 2 years ago by lwhjp to c/cruciverbalism

Here's an old puzzle of mine to get started. One of the clues (at least!) is a little unfair, but the puzzle has been solved by others so it should be possible. Comments much appreciated, and more to come...

view more: next β€Ί

lwhjp

joined 2 years ago
MODERATOR OF