Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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 andY*
.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 ).
The
let rec
construct has some limitations, for example it is not possible to define the list of naturals like so :The precise explanation of what is or is not acceptable as a right hand side is available in the OCaml manual.
👍
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.
@scottmyran : what language is this for?
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...
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:(1) Considering how ordinary
foldr
in Haskell works, you can't pass a seed value of typet
as the second argument to a function expectingt1
instead.(2) If the accumulator function returns a value of type
t
then how canfoldr
return a final value of typet1
?OK. I added it above the initial solution.
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...
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.
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!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...
Your solution and my solution had the same name for the same function but yours returns a
int
and mine - in the random tests - anum
. I think that it is fine now.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).
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...