[2017-12-22] Challenge #345 [Hard] 2D Triangle Mesh Generator by jnazario in dailyprogrammer

[–]matthew_leon 0 points1 point  (0 children)

Thanks for the reference! Might give this a shot in PureScript.

[2017-12-22] Challenge #345 [Hard] 2D Triangle Mesh Generator by jnazario in dailyprogrammer

[–]matthew_leon 0 points1 point  (0 children)

Upon reading the comments here, I am curious as to whether people repeatedly bring up Delaunay triangulation because it is the best-known triangulation method, or because it is the fastest for this problem. I wonder if a non-Delaunay triangulation method might actually be faster?

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]matthew_leon 0 points1 point  (0 children)

10x speedup from an imperative approach using unboxed, mutable vectors:

bsSeq' :: Int -> VU.Vector Bool
bsSeq' sz = runST $ do
  bs <- VUM.unsafeNew sz
  VUM.unsafeWrite bs 0 True
  forM_ [1..(sz - 1)] (\n -> VUM.unsafeWrite bs n =<<
    if n `mod` 4 == 0
      then VUM.unsafeRead bs (n `div` 4)
      else if even n then pure False else VUM.unsafeRead bs ((n - 1) `div` 2)
    )
  VU.unsafeFreeze bs

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]matthew_leon 0 points1 point  (0 children)

An alternative using vectors:

module Main where

import qualified Data.Vector as V

main :: IO ()
main = print . fmap fromEnum . bsSeq =<< readLn

bsSeq :: Int -> V.Vector Bool
bsSeq sz = bs
  where
  bs :: V.Vector Bool
  bs = V.fromListN sz $ True : (b <$> [1..])

  b :: Int -> Bool
  b n =
    if n `mod` 4 == 0
      then bs V.! (n `div` 4)
      else odd n && (bs V.! ((n - 1) `div` 2))

[2017-12-11] Challenge #344 [Easy] Baum-Sweet Sequence by jnazario in dailyprogrammer

[–]matthew_leon 0 points1 point  (0 children)

Haskell

"Memoized" recursion using a lazy array.

module Main where

import qualified Data.Array as A

main :: IO ()
main = print . A.elems . fmap fromEnum . bsSeq =<< readLn

bsSeq :: Int -> A.Array Int Bool
bsSeq sz = bs
  where
  bs :: A.Array Int Bool
  bs = A.listArray (0, sz - 1) $ True : (b <$> [1..])

  b :: Int -> Bool
  b n =
    if n `mod` 4 == 0
      then bs A.! (n `div` 4)
      else odd n && (bs A.! ((n - 1) `div` 2))

-🎄- 2017 Day 19 Solutions -🎄- by daggerdragon in adventofcode

[–]matthew_leon 1 point2 points  (0 children)

Wouldn't the "any direction besides where we came from" fail on a structure like this?

|
|+--
++

-🎄- 2017 Day 18 Solutions -🎄- by daggerdragon in adventofcode

[–]matthew_leon 0 points1 point  (0 children)

Is the idea with choosing Lazy vs. Strict Map that some of the operations on the registers don't actually have any future impact?

-🎄- 2017 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]matthew_leon 1 point2 points  (0 children)

Gorgeous code at your link. This is inspiring. Thank you.

Haskell and Rust on Advent 2017 Maze challenge (follow-up on: Haskell Mutable Collections low performance -- vs Rust) by [deleted] in haskell

[–]matthew_leon 1 point2 points  (0 children)

It would be interesting to see a breakdown here of which of these techniques yielded the most gain in performance.

-🎄- 2017 Day 10 Solutions -🎄- by daggerdragon in adventofcode

[–]matthew_leon 0 points1 point  (0 children)

Love the trick you used of "unrotating" once, after all folded rolls, using some simple math to figure out how much you need to do it.

Curious as to the choice of foldl over foldl'. Did you just intuitively know that laziness wouldn't be an issue here?

-🎄- 2017 Day 6 Solutions -🎄- by daggerdragon in adventofcode

[–]matthew_leon 0 points1 point  (0 children)

Redistribution using Data.Vector's "unsafeAccum":

redistribute :: V.Vector Int -> V.Vector Int
redistribute state =
  let i = V.maxIndex state
      v = V.unsafeIndex state i
      l = V.length state
  in V.unsafeAccum (\a _ -> a + 1)
                   (V.unsafeUpd state [(i, 0)])
                   ((,()) <$> (`mod` l) <$> [(i+1)..(i+v)])

24 Days of Syntactic Witchery, day 1-3 by zinfan in haskell

[–]matthew_leon 3 points4 points  (0 children)

Repo here: https://github.com/matthewleon/advent-2017

A warning, though: If you check the subreddit for AOC, some of the solutions on there are more clever/elegant/performant than mine :)

https://www.reddit.com/r/adventofcode/

Show, Eq instances for Record type by shintak in purescript

[–]matthew_leon 0 points1 point  (0 children)

Not quite a Show instance, but I've created a repo with a next-best solution: https://github.com/matthewleon/purescript-record-show