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.
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
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 )@donaldsebleung,
random testing is now available in rust, so I went ahead and updated my translation.
Seeing forward to your feedback,
Blablubqq
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.