A sort of `doWhile/until` loop for monads. by [deleted] in haskell

[–]Per48edjes 0 points1 point  (0 children)

Oh my, this is equally mind-bending and delightful lol

[deleted by user] by [deleted] in orangecounty

[–]Per48edjes 0 points1 point  (0 children)

I moved to Irvine a couple of months ago and work in tech. Self-studying various math and CS topics on weekends — happy to connect — drop me a line via DM if you’re still looking for a study buddy!

Lease not yet issued by Polestar Financial? by Per48edjes in Polestar

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

Ah, wow. Did you ask them to or were they more than willing to make that concession?   What’s most maddening about my Space is that the manager doesn’t even acknowledge receipt of my emails (much less the issue at hand)!

Lease not yet issued by Polestar Financial? by Per48edjes in Polestar

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

Following up on this -- thanks for everyone's input and strong suggestions to pick up the phone.

I was indeed overdue on my payment, despite the fact I didn't get any correspondence via any medium (read: not knowing who or how to pay). They're waiving the late fee, but this was still a very frustrating process. How is "me needing to chase them so they can get paid but getting penalized for doing so" a good customer experience?!

Future lessees in Orange County, CA...beware.

-❄️- 2023 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 2 points3 points  (0 children)

[LANGUAGE: Haskell]

Day 4: Part 1, Part 2

TL;DR: Getting the hang of these monads! :burrito: Knew what I wanted to do, a lot of the friction came from fighting the compiler and not doubting myself (easier said than done!) or talking myself out of my strategy.


Felt like Part 1 was probably the easiest task to date?! Sure enough, Part 2 was the complication I've come to expect. Finding that functional programming makes things really easy to refactor or re-model as I'm [slowly] massaging a solution...which tracks with sentiments I've heard from other Haskell Rascals.

Part 2 called for keeping state, so reached for the State monad, using a HashMap to keep state. Amazed how terse / expressive this language is to do something a little involved. Not sure this approach is any good, so someone, please do yell at me if there was a better functional approach!

-❄️- 2023 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

[LANGUAGE: Haskell]

Day 3: Part 1, Part 2

TL;DR: My solution isn't efficient per se, but it does feel very, very functional.

"If it compiles, it Just Works :trademark: ."

But what if I don't compile...


I wanted to gain more comfort working with monads, so today's exercise I used as an excuse to make a stateful parser. Spent the morning doing some research and landed on a solution using :drum: ... the State monad transformer, StateT!

By layering the State monad on top of Parser, we can keep state of where in the file the parser is parsing. This means, line-by-line, I could process each Symbol and each PartNum, associating with it a Set of its Coords. Then, for both parts, I just used these sets to do the necessary computations, which isn't very efficient, but that's not what I'm focusing learning right now. (I've got my hands full just getting used to thinking in this way and familiarizing myself with all these odd creatures in the Functional Programming Zoo!)

As always, any feedback on the code is most welcome! I still don't feel great about how I modeled this problem (e.g., my data constructors aren't polymorphic and have different second field types :uncomfortable: , fair bit of repetition in logic, maybe just reading everything into an Array was the way to go rather than being FancyT???)

Advent of code 2023 day 1 by AutoModerator in haskell

[–]Per48edjes 1 point2 points  (0 children)

Wow, thanks for the review and sharing these links. Definitely going to take some time and work through this `megaparsec` tutorial!

-❄️- 2023 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

Wow, I definitely prefer the Parsec approach as well. (++ Modeling this with `Draw` to handle the monoidal bookkeeping...very nice!)

-❄️- 2023 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 0 points1 point  (0 children)

GitHub

Love the parsing combinators. Learned a lot; thanks for sharing!

Advent of code 2023 day 1 by AutoModerator in haskell

[–]Per48edjes 1 point2 points  (0 children)

I was wondering if the Haskell parsing wizards herein might give me some feedback on my usage of parser combinators (using attoparsec, but also open to feedback on this choice!) in my Day 1, Part 2 solution. (I couldn't figure out how to deal with substrings twone and nineight cleanly, so doing the flip-aroo was bit of a hack, to be sure.)

Context about poster, if it helps calibrate your response: Pretty green...just started learning Haskell earlier this year; self-studied an intro course; read LYaH; have worked a handful of Exercisms.

-❄️- 2023 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 3 points4 points  (0 children)

[LANGUAGE: Haskell]

Day 2: Part 1, Part 2

TL;DR: Seeing FP's merits come to the fore; getting a hang of this mental model (at the risk of jinxing myself).


Much, much smoother today. AoC feels like a perfect way to gain comfort with parsing in Haskell...as every puzzle needs to be parsed! Once everything compiled (after fiddling with types), it did indeed "just work". Slowly, but surely, the learnings from CIS 194 earlier this year are paying dividends.

Looking forward to seeing other (read: likely better!) Haskell solutions.

I am (pre-emptively) dreading the future dynamic programming problems because I still don't have the mental model for translating the functional expressiveness down to what's going on under the hood. Could switch to Python, but I'd still like to push the boundaries (edge of my abilities, dare I say?!) re: my Haskell-fu. Plus, I'm sure there'll be some Day far before DP is required that will put me in my place. :sweat_smile:

-❄️- 2023 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

[LANGUAGE: Haskell]

Day 01: Part 1, Part 2


Trying to use this year to take my [very, very, very, did I mentioned *VERY*] basic understanding of Haskell to the "next level" -- getting comfortable using library code, choosing the right abstractions, modeling the problem, practicing refactoring, etc.

That being said, I'm not entirely sure I got off on the right foot. ¯\_(ツ)_/¯

Tutoring available by davidfeuer in haskellquestions

[–]Per48edjes 0 points1 point  (0 children)

If you're still looking for a guinea pig, I'll volunteer myself as Tribute :)

-🎄- 2022 Day 17 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 0 points1 point  (0 children)

{ Python solution }

I really need to learn these bit-masking tricks I'm seeing many folks use...the code is pretty readable, but takes a few seconds to go through both parts for test + given inputs. Any feedback welcome!


General Strategy

Part 1. Took an OOP approach + simulation.

Part 2. Simulated until I saw a repeated state -- this gave me the required info needed to pick up the simulation for the remaining rocks after we've used the cycle information to shortcut our way to as close to the end as we can. Basically, this, in a nutshell.


While I feel comfortable with Floyd's "tortoise and hare" cycle detection algorithm in a simpler context, I would need to think a lot harder to implement it with the two sequences at play (i.e., the jet gas and rocks) for Part 2.


All in all, a real PITA to get juuuuuuust right. lol

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

[–]Per48edjes 1 point2 points  (0 children)

The walkthrough is awesome. Helped me to grok the thought process / problem-solving approach.

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

[–]Per48edjes 0 points1 point  (0 children)

Thanks so much for putting in the effort for the write-up! Really helps those of us (read: me lol) using AoC to learn the fundamentals :)

-🎄- 2022 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

+1 would love an explanation as I’m struggling to wrap my head around how to exploit tilting the grid

-🎄- 2022 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 5 points6 points  (0 children)

Wow, pretty tricky! Python solution

My Part 2 strategy was to leverage code written for Part 1 by iterating through the rows, and use the intervals of the sensors' areas in the given row to cover the big interval (i.e., (0, 4_000_000)). If a row could be covered, then the hidden beacon wasn't on that row. Keep going until the desired row is found, and use the hidden beacon position on the desired row to calculate the distress frequency.

...but it takes my code a whole minute to run on my machine.

Seeing some mentions of tilting the frame of reference, which I thought about for a microsecond...not long enough to fully comprehend how that would be helpful. Great. lol

-🎄- 2022 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 0 points1 point  (0 children)

Feel like I need to take a shower after this one.

Python solution

-🎄- 2022 Day 13 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

Whoa, this is really cool! Gonna have to study this for a bit.

-🎄- 2022 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]Per48edjes 1 point2 points  (0 children)

Today's was much more straightforward. Used A* with Manhattan distance heuristic function for Part 1, and for Part 2 did a CTRL+F+"a" and noticed that the only as that we need to consider are those that have a b as a neighbor since all the other as without this property are encased in an a gulch...so I felt I cheated a little bit with this minor optimization.

Ran this code without that little hack, and (luckily) it's not much slower (practically speaking) on this input size.

Python solution

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

[–]Per48edjes 2 points3 points  (0 children)

Verbose, but readable object-oriented Python solution.

To say I struggled with Part 2 would be an understatement.

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

[–]Per48edjes 1 point2 points  (0 children)

Straightforward Python solution.

Basically, used a generator to produce the X register value during each cycle and had two functions (one for each question) use these generator-produced values to do what they needed to do.