How to Read a File in Rust

If you need to read a file in Rust, then you can use the fs package from the standard library: use std::fs; fn main() { let contents = fs::read_to_string(filename) .expect("Something went wrong reading the file"); println!("With text:\n{}", contents); }

July 8, 2022 · 1 min · 39 words · Andrew

How to find the number of trailing zeros of N in Rust

The challenge Write a program that will calculate the number of trailing zeros in a factorial of a given number. N! = 1 * 2 * 3 * ... * N Be careful 1000! has 2568 digits… For more info, see: http://mathworld.wolfram.com/Factorial.html Examples zeros(6) = 1 # 6! = 1 * 2 * 3 * 4 * 5 * 6 = 720 --> 1 trailing zero zeros(12) = 2 # 12!...

May 30, 2022 · 2 min · 314 words · Andrew

How to do RGB To Hex Conversion in Rust

The challenge The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 – 255. Any values that fall out of that range must be rounded to the closest valid value. Note: Your answer should always be 6 characters long, the shorthand with 3 will not work here. The following are examples of expected output values:...

May 29, 2022 · 2 min · 313 words · Andrew