Ad
  • Custom User Avatar

    If the type system will handle it, you can always write your let rec expressions in lambda syntax. If I can do it in LC, you can do it in Ocaml.

    See https://en.wikipedia.org/wiki/Let_expression for how to rewrite let rec, and ping me on Discord ( in #lambda-calculus ) for how to do mutual recursion and Y*.

    Note that I can't help you with the type system, and I know from Haskell recursive types can be a hassle. I might be able to do the type in Haskell, if that will help you do it in Ocaml ( it really helps here that LC is untyped ).

  • Custom User Avatar

    The let rec construct has some limitations, for example it is not possible to define the list of naturals like so :

    let rec nats = 0 :: List.map ((+) 1) nats
    

    The precise explanation of what is or is not acceptable as a right hand side is available in the OCaml manual.

  • Custom User Avatar

    👍

  • Custom User Avatar

    It looks like your algorithm needs to be optimized for speed. There are 600+ random tests.

    EDIT: To be more precise, the number of total random tests will vary with each run. When running the tests a few times, the number of tests fell in the range 650 to 699.

  • Custom User Avatar

    @scottmyran : what language is this for?

  • Custom User Avatar

    print stuff to the console, so that you end up saturating the buffer before your code times out. That might ease your way a bit, but...

  • Custom User Avatar

    Probably a problem with your code and not a Kata issue since I was able to complete the Kata without any issues. Note that problems with your code should be marked as "Question" instead.

    By the way your type signature for foldr' looks a bit fishy to me:

    foldr' :: Eq a => ((a -> t1 -> t) -> t -> [a] -> t1) -> (a -> t1 -> t) -> t1 -> [a] -> t1
                             ^^          ^                              ^                  ^^
                             (1)        (1)                            (2)                 (2)
    

    (1) Considering how ordinary foldr in Haskell works, you can't pass a seed value of type t as the second argument to a function expecting t1 instead.
    (2) If the accumulator function returns a value of type t then how can foldr return a final value of type t1?

  • Default User Avatar

    OK. I added it above the initial solution.

  • Default User Avatar

    In the fixed tests or in the random tests, "RUN SAMPLE TESTS" or "ATTEMPT", tests for ann or john or sum_ann or sum_john? Maybe you are returning a list instead of an array? I didn't put the type in the functions because I thought the examples tests cases made it clear. 4 guys passed the OCaml translation, not a lot but for OCaml not that bad...

  • Default User Avatar

    It's not the author who gives the kyu... and it is the same for all languages despite the fact that some are easier than others.

  • Default User Avatar

    The writer of the OCaml translation was @cacr. He uses open Batteries include Enum for his tests... I added that in the preloaded section so it should work now. I thank you very much for your constructive posts!

  • Default User Avatar

    The kyu is given by a moderator and not by the author; usually the Codewarrior who approves the kata and gives the kyu is a top user and for him everything seems easy...

  • Default User Avatar

    Your solution and my solution had the same name for the same function but yours returns a int and mine - in the random tests - a num. I think that it is fine now.

  • Default User Avatar

    I will try to see where the problem is but it is very late for me now and, to help... , the lines numbers are never the good ones at CW which mixes codewarriors solutions, tests and preloaded part... Be patient!-)
    PS: could you post your code (mark it as spoiler)? It can be easier to find the problem (Line 53 is in the tests but depends on your code length).

  • Default User Avatar

    Well, using floats there is maybe not so good an idea but you passed and I am happy for that. Thanks onve more!

  • Loading more items...