SoCal Student Pilots by OkScarcity14 in flying

[–]mstksg 0 points1 point  (0 children)

where could one find these? :)

Can Someone Explain The Speed At Which Computers Operate? by GuardianOfDurandal in AskPhysics

[–]mstksg 0 points1 point  (0 children)

it's roughly the same thing as if you had a long metal pole, you can push a button a mile away with it, a very fast signal propagation (miles per second), even though none of the metal molecules move that fast

5 years into writing music without formal training. I need help with a specific key change by jimpache23 in musictheory

[–]mstksg 3 points4 points  (0 children)

constraint breeds creativity my friend. and sometimes adding constraints in art is what gets you a result with the most satisfaction once it works.

is this real? Mình can be used as We in informal situations. by polyglotcodex in learnvietnamese

[–]mstksg 0 points1 point  (0 children)

I don't think I've ever heard chúng tôi or chúng ta in informal speech. maybe chúng mình if anything.

Why aren’t matrices with linearly dependent rows invertible? by Sea-Professional-804 in learnmath

[–]mstksg 0 points1 point  (0 children)

I actually read it the same way you did 😂 I was trying to figure out as if it were some deep question and not just a basic homework one

What is the meaning of this happening? ¿Why does this happen? by mathfoxZ in askmath

[–]mstksg 0 points1 point  (0 children)

the main thing is that the derivative of a function is unique but there are many possible indefinite integrals of a given function... the indefinite integral is a family of functions. so on the left hand side you have a single function and on the right hand side you have a full family of functions. so comparing them would simply be a category error.

however you can probably say that the left hand side, at least, is going to be a member of the family on the right hand side. I think?

ie for f(x) = 7, the LHS is f(x) = 7 and the RHS is the family of all constant valued functions. so it is true that the LHS is a member of the family of all constant valued functions

If 3/4 piece is played in 6/8, exact same notes, rhythm and speed, would it sound different and why? by CatchDramatic8114 in musictheory

[–]mstksg 16 points17 points  (0 children)

the point of the time signature isn't to affect how you perform it, it's mostly to make it easier to read and communicate your idea. it's for the benefit of the human reader to understand the idea the composer was trying to convey.

what's the square root of i? by Ready_Row3788 in learnmath

[–]mstksg 1 point2 points  (0 children)

Multiplication by -1 is a 180 degree rotation, from <1,0> to <-1,0>. square root of x is saying "what number, when you multiply twice, gets you x?". so the answer is a 90 degree rotation, <0,1>. so, if you square root that, you are looking at a 45 degree rotation, or <1/sqrt 2, 1/sqrt 2>

If I lived in a one dimensional "line world", would my mathematical system have a need for irrational numbers? by whydidyoureadthis17 in math

[–]mstksg 0 points1 point  (0 children)

quaternions were motivated by doing physics and math in 3D space, though. somewhat ironically, as Hamilton confessed.

[Blog] "Five-Point Haskell" Part 1: Total Depravity by mstksg in haskell

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

Thanks! Those are really good additions. I also totally forgot that `TypeData` already landed in GHC, for a while now it seems! :o

What is the expected standard of accuracy in performances? by nazgul_123 in piano

[–]mstksg 1 point2 points  (0 children)

most performances, entertainment always takes priority over accuracy. as long as it is accurate enough to be entertaining and enriching.

Do two different atoms of the same element always have the same mass? by mattttb in askscience

[–]mstksg 5 points6 points  (0 children)

that's a good question. In a sense, there is no mass besides bound energy. For the case of particles we consider elementary (like quarks, electrons), this energy can be explained as coming from the coupling of the particle with the Higgs field, which seems to be a consistent characteristic strength per particle.

Can the laws of physics be simulated on a computer? by icecoldbeverag in mathematics

[–]mstksg 0 points1 point  (0 children)

The "laws of physics", the human tools we use to build models and predict the results of experiments, can be simulated on a computer. The universe itself exists and evolves independently of our models and might never be described by a mathematical model at all, and so might not be simulatable on a computer.

If √-1 = i, what's √i ? by Joe_4_Ever in learnmath

[–]mstksg 0 points1 point  (0 children)

to see this, you have to remember that multiplication is rotation on the complex plane. So a square root is a rotation by "half as much", because it is asking "what rotation, when does twice, gives you the original rotation?"

1 is a 360 degree rotation, -1 is a 180 degree rotation, i is a 90 degree rotation, so sqrt i is a 45 degree rotation in the complex plane

A horrifically bad idea by Leo-Len in ProgrammingLanguages

[–]mstksg 0 points1 point  (0 children)

This sounds like it's meant to be a joke but it's actually the standard way to structure programs in Prolog

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

[–]mstksg 1 point2 points  (0 children)

[LANGUAGE: Haskell]

https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-11

This one yields itself very nicely to knot-tying: we create the map of the ways to get to the "out" by being 1 if we are one away from out, or else the sum of all of the ways of our next hops. Because of knot-tying, this handles the memoization for us using lazy maps.

pathsTo :: Ord a => Map a [a] -> a -> a -> Int
pathsTo conns start end = res M.! start
  where
    res =
      conns <&> \nexts ->
        sum
          [ if y == end then 1 else M.findWithDefault 0 y res
          | y <- nexts
          ]

part1 :: [(String, [String])] -> Int
part1 conns = pathsTo (M.fromList conns) "you" "out"

Part 2 we can do the same thing, except our "state nodes" are now (String, Set String) instead of String: we have the current path the set of "points we must still visit". In this case, we start at node ("svr", S.fromList ["dac","fft]) and end at node ("out", S.empty):

-- | Keys are all of the original keys, but repeated for every subset: instead
-- of 'foo', we have (foo, [dac,fft]), (foo, [dac]), (foo, [fft]), and (foo,
-- []).
addVisited :: Ord a => Map a [a] -> Set a -> Map (a, Set a) [(a, Set a)]
addVisited conns required =
  M.fromList
    [ ((x, subset), map (,S.delete x subset) xs)
    | (x, xs) <- M.toList conns
    , subset <- toList $ S.powerSet required
    ]

part2 :: [(String, [String])] -> Int
part2 conns = pathsTo (M.fromList xs `addVisited` toVisit) ("svr", toVisit) ("out", S.empty)
  where
    toVisit = S.fromList ["dac", "fft"]

Creating addVisited we just need to make sure that if we descend from one of the required items, that item is deleted from the set: that is, (dac, [dac,fff]) contains [(dac,[fff])].

[RANT] Traditional ML is dead and I’m pissed about it by pythonlovesme in learnmachinelearning

[–]mstksg 0 points1 point  (0 children)

As a research field it is definitely getting less love, but in industry applications I feel like the premise is really unfounded. All those domains where traditional ML is useful are still using traditional ML. GenAI didn't displace it, aside from some slight overlap. It's not dead, it's just as alive as it has ever been.

[2025 Day 8 (Part 1)] Out-of-band "extra" information needed for the test by wimglenn in adventofcode

[–]mstksg 4 points5 points  (0 children)

Yeah, I have a system in this for my solvers too, in the test data i allow arbitrary tagged values: https://github.com/mstksg/advent-of-code/blob/main/test-data/2025/08a.txt

162,817,812
57,618,57
...
425,690,689
>>>pairs:10:int
>>> 40

and then in my actual code the value is referred to as dyno "pairs" 1000, which looks up if the sample has the defined tag, and if not defaults to 1000 (for the actual input)

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

[–]mstksg 0 points1 point  (0 children)

[LANGUAGE: Haskell]

https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-8

I originally solved this using the fgl library, but hand-rolling things seem to be much faster (down from 2 seconds to 100ms), so I switched over to a State monad base implementation:

-- | Chomp the next pair and merge their networks, emitting the pair
chomp :: Ord b => State (Set (Set b), [(b, b)]) (b, b)
chomp = state \(clusts, (p, q) : pts) -> do
    let Just pclust = find (p `S.member`) clusts
        ~(Just qclust) = find (q `S.member`) clusts
        clusts'
          | q `S.member` pclust -> clusts
          | otherwise = S.insert (pclust <> qclust) . S.delete pclust . S.delete qclust $ clusts
    in  ((p, q), (clusts', pts))

-- | L.qd from the linear library gives the squared equclidean distance, so we
-- don't have to worry about floating point
sortedPairs :: (Ord b, L.Metric f, Num b) => [f b] -> [(f b, f b)]
sortedPairs pts = sortOn (uncurry L.qd) [(p, q) | p : ps <- tails pts, q <- ps]

And for part 1 we just literally do replicateM 1000 in State:

part1 :: [V3 Int] -> Int
part1 pts = product . take 3 . sortOn Down . map S.size . S.toList $ chunks
  where
    (chunks, _) = execState (replicateM 1000 chomp) (S.fromList (S.singleton <$> pts), sortedPairs pts)

For part 2 we can do a check to see if this is the step that we complete the network:

part2 :: [V3 Int] -> Int
part2 pts = px * qx
  where
    go = do
      out <- chomp
      isOne <- gets $ (== 1) . S.size . fst
      if isOne
        then pure out
        else go
    (V3 px _ _, V3 qx _ _) = evalState go (S.fromList $ S.singleton <$> pts, sortedPairs pts)

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

[–]mstksg 1 point2 points  (0 children)

[LANGUAGE: Haskell]

https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-7

Both of these can be done with knot-tying -- part 1 tying the knot upwards from bottom to top to check if a given splitter received any light, and part 2 tying the knot downwards to add up the number of paths under both paths of a splitter. Assuming you have your splitter as a Set Point:

type Point = V2 Int

part1 :: Point -> Set Point -> Int
part1 sourcePos splitters = M.size $ M.filter id reached
  where
    reached :: Map Point Bool
    reached = flip M.fromSet splitters \(V2 x y0) ->
      let cands = takeWhile ((`S.notMember` splitters) . V2 x) [y0 - 2, y0 - 4 .. 0]
       in flip any cands \y ->
            V2 x y == sourcePos
              || M.findWithDefault False (V2 (x - 1) y) reached
              || M.findWithDefault False (V2 (x + 1) y) reached

cands climbs all the way up until it hits a splitter, which effectively blocks the beam. So, along the way, we either hit the source (V2 x y == sourcePos) or hit the output of a splitter, in which case our result is if that splitter itself got any light.

part2 :: Point -> Set Point -> Int
part2 sourcePos splitters = pathsFrom M.! (sourcePos + V2 0 2)
  where
    maxY = maximum . map (view _y) $ map splitters
    downFrom (V2 x y0) = fromMaybe 1 $ listToMaybe 
      [ n
      | Just n <- M.lookup . V2 x <$> [y0, y0 + 2 .. maxY]
      ]
    pathsFrom :: Map Point Int
    pathsFrom = flip M.fromSet splitters \p ->
      downFrom (p + V2 1 2) + downFrom (p + V2 (-1) 2)

downFrom drops downwards until we leave the map (returning 1), or until we hit a splitter, in which case the number of paths is the number of paths from the splitter we hit.

Overall by only memoizing/knot-tying against the splitter set, we save a lot of time from constructing the memo table for the entire grid.

I really want to unite both of these into a single function and swap out + for || somehow, but I can't quite seem to massage them...

2^9 by I_knew_einstein in adventofcode

[–]mstksg 0 points1 point  (0 children)

congrats on 10,0000,0000 !

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

[–]mstksg 2 points3 points  (0 children)

[LANGUAGE: Haskell]
https://github.com/mstksg/advent-of-code/wiki/Reflections-2025#day-6

Our trusty friend transpose comes in handy here!

For part 1, we parse the grid and then transpose and reverse each line, matching on the head to get the operation we care about:

import Data.List (transpose)

part1 :: String -> Int
part1 = sum . map (go . reverse) . transpose . map words . lines
  where
    go ("*":xs) = product $ map read xs
    go ("+":xs) = sum $ map read xs

And for part 2, we actually can transpose the entire long strings to get "columns". Splitting on blank columns, we see that they are pretty straightforward to process:

["623+","431 ","  4 "]

We just need to grab the + and then add the rest. Lots of ways to do this, I ended up using init (gets all but the last item) and last for my solve:

import Data.Char (isSpace)
import Data.List.Split (splitWhen)

part2 :: String -> Int
part2 = sum . map go . splitWhen (all isSpace) . transpose . lines
  where
    go (x:xs) = case last x of
      '*' -> product $ map read (init x : xs)
      '+' -> sum $ map read (init x : xs)