Ad
  • Custom User Avatar

    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

  • Custom User Avatar

    I dont think it should be there.

  • Custom User Avatar

    Why the semicolon? It does absolutely nothing here

  • Custom User Avatar

    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

  • Custom User Avatar

    @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 that Vec<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

  • Custom User Avatar

    In Rust String is always valid UTF-8. &[u8] (slice of bytes) is called byte-string and ascii encoded. It can be created with b"Hello" instead of "Hello". Vec<u8> (vector of bytes) is the owned version of a byte-string, like String 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 string String::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 to chars (4-byte Unicode scalar values) and then to String (looks something like this s.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 )

  • Custom User Avatar

    I'm not familiar with Rust myself but why is the input parameter a Vec<u8> and not a &str/String? Is Vec<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 - unless Vec<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.

  • Custom User Avatar

    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 :)

  • Custom User Avatar

    @donaldsebleung,

    random testing is now available in rust, so I went ahead and updated my translation.

    Seeing forward to your feedback,
    Blablubqq

  • Custom User Avatar

    Fixed, thanks!

  • Custom User Avatar

    The rust translation uses assert_eq! instead of assert_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)

  • Custom User Avatar

    The current version of rust doesn't use assert_fuzzy_equals() in random_tests() and therefore only allows the answer x / ((1.0 + x).sqrt() + 1.0).

    Other approximate solutions like using the Taylor series should be accepted, too.

  • Custom User Avatar

    @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.

  • Custom User Avatar

    @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