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.
I am interested in writing a new translation for this kata in Rust. I want to know why this was rejected, so I don't repeat the mistakes
I dont think it should be there.
Why the semicolon? It does absolutely nothing here
since the memory cell is suppost to hold a value from 0-255, you can assume an extended ascii-set.
As far as encoding goes, you have to handle the ascii -> utf-8 encoding yourself (It's easier than it might look like).
Hint:
char
@Blablubqq,
Many thanks for your patience and detailed explanation. As I said, I was not familiar with Rust so I was just initially concerned that
Vec<u8>
was some sort of array of numbers instead of a type of string. Since you confirmed thatVec<u8>
is indeed a valid type of string, I have reviewed the rest of your translation and could not find any issues with it so I went ahead and approved it :)Many thanks for taking the time and effort to translate my Kata into Rust, your contribution is much appreciated :D
Cheers,
donaldsebleung
In Rust
String
is always valid UTF-8.&[u8]
(slice of bytes) is called byte-string and ascii encoded. It can be created withb"Hello"
instead of"Hello"
.Vec<u8>
(vector of bytes) is the owned version of a byte-string, likeString
is the owned version of&str
.When using
String
as input, we would have to restrict ourselves to bytes in the range 0-127 or explain the user that they have to convert the input to an acsii-encoded byte-string before reading the bits. Same goes for the output, since the native approach to convert a byte-string to a stringString::from_uft8(s).unwrap()
breaks as soon as characters from the extended set (128-255) are present in the string. A correct conversion would have to first convert the bytes tochars
(4-byte Unicode scalar values) and then toString
(looks something like thiss.into_iter().map(|b| b as char).collect()
).I'm not sure what's the best choice, but using
String
will definitly confuse some people and require additional explanation.Let me know, what you think. (The brainfuck Kata also uses
Vec<u8>
for input/output )I'm not familiar with Rust myself but why is the
input
parameter aVec<u8>
and not a&str
/String
? IsVec<u8>
yet another type of string or is it a list of bytes/bits? The Kata Description does explicitly state that the program input is from the end-user so it should be what an ordinary user would type in (i.e. a string not a list of bytes/bits). Same goes for the return type - unlessVec<u8>
is an actual type of string, please change it to&str
/String
instead. The conversion of an actual string into bytes/bits (and vice versa for output) should be done by the solver and is a part of the challenge itself.Everything looks perfect to me :D I've tried to approve your translation but there were merge conflicts in the Kata description so I forked your translation instead and approved that, hope you don't mind :)
@donaldsebleung,
random testing is now available in rust, so I went ahead and updated my translation.
Seeing forward to your feedback,
Blablubqq
Fixed, thanks!
The rust translation uses
assert_eq!
instead ofassert_fuzzy_equals
for the random tests.That's why some solutions work for other languages but not for rust.
(I submitted a fork to fix that problem)
The current version of rust doesn't use
assert_fuzzy_equals()
inrandom_tests()
and therefore only allows the answerx / ((1.0 + x).sqrt() + 1.0)
.Other approximate solutions like using the Taylor series should be accepted, too.
@donaldsebleung,
no offense taken.
I will keep my eye on the issue and update my translation, once the problem has been resolved.
Thanks for the great Kata, I highly enjoyed the series.
@Blablubqq,
Thanks for linking to the relevant GitHub issue with regards to the random tests - I will ping @jhoffner to see if he (or a contributor to the CLI repo) has a solution to this which will allow for random test cases in Rust.
Unfortunately, I will not be able to approve this yet because random tests are vital to every good translation but I will leave this open instead of rejecting it because everything else looks fine and the lack of random tests does not seem to be your fault.
Please do not take any of this personally - your efforts and contributions at translating my Kata are always welcome and highly appreciated; it's just that I usually have very high standards for translations to any of my Kata and this particular Kata Series is especially treasured by me so I have to make sure that each and every translation to this Series is impeccable before I can accept it.
Cheers,
donaldsebleung