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.
Well, I have a working thing but I'm not sure it's what was expected. I'll look at the other solutions when I'm done with this kata.
Currently, I am battling a bit with Haskell so my join function doesn't do much; but when it "worked", it indeed went through all elements, except that you would see 2^n elements of the first stream before seeing the first of the n-th stream, which is probably why it broke down (NB. when I click on Attempt, it successfully passes the first batch of tests for
LazyThunk
, but not forLazyOption
, because it times out — so the implementation is correct, it's just too long)... Whatever, I guess I'll just change the order, even if that's a bit longer to code.Unfortunately, I know almost nothing about Haskell (if I'm currently 4 kyu in Haskell it's merely because I found Kata were you don't need to know how to code in Haskell to finish them).
My problem about that is how do I reuse already built information. I mean, I don't even know where to put the initializatoin!
After some thoughs, I realized what I was supposed to do for these.
Except it does :') I tested my solution and it [stack overlowed / exceeded the allowed runtime] because the order I chose made it so that you have to wait very long before you actually reach the first element of the n-th stream. But I guess that's easy to fix (just a bit sad that my unpractical solution is rejected). I realized after posting that it was not because a given order was enforced, but rather because mine was really bad.
Thanks for the tips! I think the only thing I am still struggling with is the fibonacci one...
After some more attempts, I have circumvented the
tail
issue, by realizing it was myjoin
which was not lazy enough! And that's because, even though it was successfully type-checked, it didn't do what it was supposed to because there wasn't a clear explanation about that :| This kata could really benefit from being more precise.I have some trouble with this Kata. First of all, it's not clear at all what the
tie
function should do (or, really, any other function). It's relatively straightforward to "guess" what other functions should do from their signature, buttie
's signature is not enough for me. I guess it should be something like "create a dummy thunk in a reference, pass it to the function given and store the result where the dummy thunk was, then return it" but I'm not sure. And, because I'm unsure about that, I'm a little bit confused about what I should do for the fibonacci one.Secondly, I don't understand how it is possible in OCaml to actually make
tail
"lazy enough" with the provided signature. That is, the tests require the head not to be evaluated if I only want to tail of the stream, but since both the head and the tail are in the same thunk, it's impossible to evaluate one without the other. I tried changing the signature of Stream to provide two thunks, but then it doesn't work because the constructor is used directly in the tests (which is strange since the module also provides an interface to create streams).Finally, I'm not sure about which order to use in the join function. Since there are several ways to do that, and that each provides a different stream in the end, it's not clear which one should be chosen.
I have the impression that this solution is wrong... Consider "1110000000111" (3x1, 7x0, 3x1). The shortest sequence of zeros or ones is of length 3, and yet the time unit is 1. You should take the gcd instead of the min.
A
match
over a boolean value is just anif
.