fn s(a:&mut[u8]){let z=a.len();for b in 0..z*z{if a[b/z]<a[b%z]{a.swap(b%z,b/z)}}}
// Add your tests here.
// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sort_test() {
let mut test_list = [
(vec![0, 2, 189, 200, 76, 10, 200], vec![0, 2, 10, 76, 189, 200, 200]),
(vec![255, 1, 22, 111, 222, 11, 2], vec![1, 2, 11, 22, 111, 222, 255]),
(vec![0, 99, 56, 32, 2, 9, 3], vec![0, 2, 3, 9, 32, 56, 99]),
];
for test in &mut test_list {
s(&mut test.0);
assert_eq!(test.0, test.1);
}
}
}
only 1 line less and more readable var names
fn flip_the_number(&(mut n): &u64) -> u64 { let mut out = 0; while n > 0 { out = out * 10 + n % 10; n /= 10; } out }
fn flip_the_number(x: &u64) -> u64 {let mut x = *x;let mut y = 0;while x != 0 {y = y * 10 + x % 10;x /= 10;- fn flip_the_number(&(mut n): &u64) -> u64 {
- let mut out = 0;
- while n > 0 {
- out = out * 10 + n % 10;
- n /= 10;
- }
y- out
- }