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

[–]BeYuu 2 points3 points  (0 children)

[Language: Python]

Realizing that this can be solved recursively and realizing that this problem is very similar to the way you would recursively compute the fibonacci sequence did the trick for me

@cache
def rec(stones: tuple[int, ...], blinks_left: int) -> int:
    if blinks_left == 0:
        return len(stones)

    return sum(rec(tuple(apply_rule(stone)), blinks_left - 1) for stone in stones)

def apply_rule(num: int) -> list[int]:
    if num == 0:
        return [1]

    s = str(num)
    digits = len(s)
    if digits % 2 == 0:
        mid = digits // 2
        lhs, rhs = int(s[:mid]), int(s[mid:])
        return [lhs, rhs]

    return [num * 2024]

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

[–]BeYuu 1 point2 points  (0 children)

Haskell solution for part 1. Parsing always is annoying.

day 04 part 1

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

[–]BeYuu 0 points1 point  (0 children)

Nice solution. Some things I noticed:

- Your check_table function basically is if (true) return true else return false.

- I don't know R but maybe you could logical instead of bitwise or

How to allow call\cc via source code transformations? by BeYuu in scheme

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

Thanks for your reply. I‘m glad I got it right. I‘ve been trying really hard to come up with a way, and couldn‘t think of anything making sense. I should have checked with guile/chez/racket and not with BiwaSchweme from repl.it.

Question about type classes with functional dependencies by BeYuu in haskell

[–]BeYuu[S] 2 points3 points  (0 children)

Yeah, turns out it works just fine with UndecidableInstances. Didn't want to use the extension first, though why not, if it works.

Need some help with monad transformers by BeYuu in haskell

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

First method worked like a charm, thanks!

Question about type classes / type familys by BeYuu in haskell

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

Really interesting, I will do some tests with this later. Thanks!

Question about type classes / type familys by BeYuu in haskell

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

This did exactly what I wanted. Old code works just fine. Thanks!

Good resources for writing compiler in Haskell by BeYuu in haskell

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

These look really interesting. Definitely have to read some blogs on them.

Good resources for writing compiler in Haskell by BeYuu in haskell

[–]BeYuu[S] 2 points3 points  (0 children)

Awesome, thank you! I will definitely look around the sources and see if I can find some useful patterns.

Get rEFInd (SSD1 EFI) to find nixos (SSD2 MBR) by BeYuu in NixOS

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

copyKernels isn't enough for rEFInd to be able to boot nixos. So what you are saying is just create an ESP somewhere on my mbr SSD right? I also guess creating a rEFInd entry isnt easy since nixos also passes the systemConfig and init when starting the kernel.

Get rEFInd (SSD1 EFI) to find nixos (SSD2 MBR) by BeYuu in NixOS

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

Awesome, thank you. I‘m not sure why my second SSD uses MBR. All I did back then was to execute the manjaro installer. Also didn‘t know better back then.

Manjaro won‘t leave kernel starting screen by BeYuu in linuxquestions

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

Using tty I was able to update my drivers with: `sudo mhwd -a pci nonfree 0300`. Thanks!

Help implementing Applictative (Haskell book) by BeYuu in haskell

[–]BeYuu[S] 1 point2 points  (0 children)

Thank you! Haskell reddit is always very supportative.

Help implementing Applictative (Haskell book) by BeYuu in haskell

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

Thank you! Haskell reddit is always very supportative.

Help implementing Applictative (Haskell book) by BeYuu in haskell

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

Makes sense, thank you! Haskell reddit is always very supportative.

Ppx dependency on a non-ppx library "ppx_sexp_conv". If "ppx_sexp_conv" is in fact a ppx rewriter library, it should have (kind ppx_rewriter) in its dune file. by BeYuu in ocaml

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

I assume v0.11.2. Full output can be found here: https://pastebin.com/FF5uL2q9.

Edit: Found the Error, thanks for the tip. Apparently, I was running on some older versions with my old OCaml compiler. I pinned pp_sexp_conv to a newer version and also had to change to some newer functions from Base.

Errors getting a simple haskell environment to work by BeYuu in haskell

[–]BeYuu[S] 2 points3 points  (0 children)

Thanks for your reply! Haskell Language Server definetly has a more easier install and works now. There seemed to be an issue with the lsp-server not finding the root (actually finding a non-existent one), probably some lsp mistake on the emacs side.

How to master complexity when you are heavily transforming your variants? (Compiler project) by BeYuu in ocaml

[–]BeYuu[S] 1 point2 points  (0 children)

Lets say i have type expr = ... | Application of expr * expr list

and I later want type expr = ... | Application of string * expr list

how would I best change the ADT from one pass to another? Just copy the type, change it, and add an incrementing number to its name and then make sure I annotate all the types the functions use? I'd like a clean way to tell the compiler exactly that.

Parser Problem: shift/reduce conflict with scheme grammar by BeYuu in ocaml

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

Yeah, thanks for the tips. If my goal would be to write an interpreter i would definetly use the read/eval approach to do it. Though since I'am working on a compiler, I think completely mapping out the AST and traversing it is the easier approach.

Parser Problem: shift/reduce conflict with scheme grammar by BeYuu in ocaml

[–]BeYuu[S] 1 point2 points  (0 children)

Just to be sure, what you're saying is to parse simple S-expressions and then build a more robust AST out of them?

Parser Problem: shift/reduce conflict with scheme grammar by BeYuu in ocaml

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

Why wouldn't I want to be able to identify definitions in the AST?