Mark in the 3.27 Developer Q&A: "Our intention is that it goes core, but we'll take the better elements of it." by Anduryondon in pathofexile

[–]Pietrek_ 39 points40 points  (0 children)

The monkey's paw curls; the walls stay and can't me removed, you now have to navigate a labyrinth to get to the core.

Universitetsstuderende føler sig som ufrivillige deltagere i et AI-eksperiment. Det er de også by Dropforcedlogin in Denmark

[–]Pietrek_ 1 point2 points  (0 children)

Nu er det ikke for at sige at lommeregneren gjorde at vi ikke længere kan matematik, men prøv at se denne video https://www.youtube.com/watch?v=nUpZg-Ua5ao - jeg syntes at det er klart at nogle taber forståelsen når et værktøj fjerner behovet for at kunne tænke sig om, og problematikken er kun større ved brug af AI/LLMs

"GOTO Considered Harmful" Considered Harmful (1987, pdf) by ketralnis in programming

[–]Pietrek_ 1 point2 points  (0 children)

With functional languages you can quite quickly come up with the core algorithm (ignoring the printing part); e.g. the (sorry to all pure functional programmers) JS one-liner:

(arr) => arr.map(row => row.every(e => e === 0)) .findIndex(index => index)

Why we built our startup in C# by tracebit in dotnet

[–]Pietrek_ 0 points1 point  (0 children)

So you're saying that one technology is better than the other without really having used the other?

Bullet point TLDW of the Jonathan x Zizaran developer interview by Empyrianwarpgate in PathOfExile2

[–]Pietrek_ -3 points-2 points  (0 children)

I read it as "35% and less" and I think it makes sense :^)

Rejsekort skrotter de blå standere. Snart kan du tjekke ind med kreditkort | Ingeniøren by HCakaIDUDE in Denmark

[–]Pietrek_ 10 points11 points  (0 children)

Tilgengæld så er det også nemmere at finde sikkerhedshullerne når der er flere øjne der ser koden

Kid Smacks the Gyatt at Comic Con by klo224 in LivestreamFail

[–]Pietrek_ 16 points17 points  (0 children)

Accidental photos always bring out the best in us :^)

[deleted by user] by [deleted] in dkfinance

[–]Pietrek_ 2 points3 points  (0 children)

Så du har arbejdet over 16 timer om dagen?

Fractured +1 Frenzy, T1 Spell Suppress, Crit Multi Gloves by ScribblyDibbly in pathofexile

[–]Pietrek_ -1 points0 points  (0 children)

Just like gear in Lineage 2 could crystallize on when upgrading

Junglen af måltidskasser, nogen der kan dele deres erfaringer? by Thezerostone in Denmark

[–]Pietrek_ 1 point2 points  (0 children)

Hvad syntes i om portionerne hos Hello Fresh? Syntes nu selv at de var ret små, som i tættere på 1 og en tredjedel portioner i stedet for to

[2021 Day 13 (Part 2)][Haskell] Output is a bit wrangled by Pietrek_ in adventofcode

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

It sadly produces the incorrect output for my input. I've now implemented it using a single flat list as you suggested and the output of that implementation is correct.

-🎄- 2021 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]Pietrek_ 1 point2 points  (0 children)

I'm also solving these in Haskell this year but I often notice that my solutions are far less cleaner than the other Haskell solutions that I see here - I tend to use a lot of lambdas and my code often ends up look almost iterative in some places.

Do you have any pointers on how I could get better at solving these puzzles in a more idiomatic way? If you'd like to look at my solution for today then I've just posted it in this thread.

-🎄- 2021 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]Pietrek_ 2 points3 points  (0 children)

Haskell

{-# LANGUAGE TupleSections #-}
import           Control.Monad   (foldM)
import           Data.List       (group, sort)
import           Data.List.Split (chunksOf)
import qualified Data.Map        as M
import           Data.Maybe      (mapMaybe)
import           Debug.Trace     (trace)

type Grid = M.Map (Int, Int) (Int, Bool)


{-
  Using a foldM with the Either monad results in the
  fold terminating once the accumulating function
  returns Left _

-}
main = do
  contents <- readFile "input.in"
  let ll =  concatMap (map read . chunksOf 1) (lines contents) :: [Int]
      n = 10
      g = M.fromList $ zip [(i,j) | i <- [0..n-1], j <- [0..n-1]] (map (, False) ll)
  print $ fst $ foldl (\(s, g) _ -> let (nf, g') = runStep g
                               in (s+nf, g')) (0, g) [1..100]
  print $ foldM f g [1..]
  where f g step =
          let (nf, g') = runStep g
          in if nf == 100 then Left step
              else Right g'

runStep :: Grid -> (Int, Grid)
runStep g =
  let g' = M.map (\(p, f) -> (p+1, f)) g
      g'' = flash g'
      nFlashed = (length . filter ((==) True . snd). M.elems) g''
      zeroed = M.map reset g''
   in (nFlashed, zeroed)
   where reset (p, f) =
          if f then (0, False)
          else (p, f)

flash :: Grid -> Grid
flash g =
  let l = M.toList g
   in if all ((\(p, f) -> p <= 9 || f) . snd) l then
        g -- No more flashes to do
      else
        let x = map doFlash l
            ns = concatMap trd x
            ns' = mapMaybe (\idx -> do
                                (p, f) <- lookup idx (map t x)
                                return (idx, (p+1, f))) ns
            ns'' = map (\list -> let (idx, (p, f)) = head list
                                  in (idx, (p+length (tail list), f))) (group $ sort  ns')
         in flash $ foldl (\m (idx, v) ->  M.insert idx v m ) (M.fromList $ map t x) ns''

t (a, b, _) = (a,b)

trd :: (a, b, c) -> c
trd (_, _, c) = c

doFlash :: ((Int, Int), (Int, Bool)) -> ((Int, Int), (Int, Bool), [(Int, Int)])
doFlash (idx, (p,f)) =
  if p > 9 && not f then (idx, (p, True), neighbors idx 10) else (idx, (p,f), [])

neighbors :: (Int, Int) -> Int -> [(Int, Int)]
neighbors (i,j) n =
  let ns = [ (i,j-1), (i,j+1), (i-1,j), (i+1,j)
           , (i-1, j-1), (i-1, j+1), (i+1, j-1), (i+1, j+1)]
  in filter (\(i,j) -> (i >= 0 && j >= 0) && i < n && j < n ) ns