Skip to content

List of Rust Kata to Update

Voile edited this page Apr 29, 2021 · 60 revisions

Preloaded Code

From Rust 1.50, we stopped concatenating preloaded code and started to use preloaded.rs. This fixes the line number mismatch, minimizes the awkwardness, and makes it easier for users to solve locally.

This breaks existing solutions for kata using preloaded because the solution must include mod preloaded; now. But it's better to do this now considering how Rust is getting more and more popular on Codewars.

This section lists affected kata and what we can do about them. Fortunately, it looks like many of them can avoid breaking existing solutions.

For affected kata, also consider fixing any unidiomatic Rust because it's a breaking change anyway.

  1. Find the Capitals

This one is awkward. Capital struct should have either country or state set. There's nothing preventing them to be unset or both set.

Current preloaded
struct Capital<'a> {
    capital: &'a str,
    country: Option<&'a str>,
    state: Option<&'a str>,
}

impl<'a> Capital<'a> {
    fn new_country(capital: &'a str, country: &'a str) -> Capital<'a> {
        Capital {
            capital: capital,
            country: Some(country),
            state: None,
        }
    }
    
    fn new_state(capital: &'a str, state: &'a str) -> Capital<'a> {
        Capital {
            capital: capital,
            country: None,
            state: Some(state),
        }
    }
}

Constructors are only used in tests, and using Into<String> is less awkward.

Preloaded for 1.50
pub struct Capital {
    pub capital: String,
    pub country: Option<String>,
    pub state: Option<String>,
}
impl Capital {
    fn new_country<S: Into<String>>(capital: S, country: S) -> Capital {
        Capital {
            capital: capital.into(),
            country: Some(country.into()),
            state: None,
        }
    }

    fn new_state<S: Into<String>>(capital: S, state: S) -> Capital {
        Capital {
            capital: capital.into(),
            country: None,
            state: Some(state.into()),
        }
    }
}

enum is more Rusty:

pub enum Capital {
  State { state: String, capital: String },
  Country { country: String, capital: String },
}

Unidiomatic Rust?

  1. Transforming Maze Solver Return empty Vec when no solution.

Failing Random Tests

The reference solution sometimes fails random tests.

  1. Prime reduction

Use float_eq

float_eq was added to Rust 1.50. The following kata have tests matching /assert_fuzzy/, so it should probably be replaced.

  1. Braking well
  2. Euler's method for a first-order ODE
  3. Floating-point Approximation (I)
  4. Floating-point Approximation (III)
  5. Going to zero or to infinity?
  6. Magnet particules in boxes
  7. Parabolic Arc Length
  8. Positions Average
  9. Probabilities for Sums in Rolling Cubic Dice
  10. Rainfall
  11. Robinson Crusoe
  12. Simpson's Rule - Approximate Integration
  13. Which x for that sum?

Clone this wiki locally