Ad
Code
Diff
  • fn incrementString(string: &str) -> String {
        if string.is_empty() {
            return "1".to_string();
        }
        
        let split_point = string
            .rfind(|ch: char| !ch.is_ascii_digit())
            .map(|i| i + 1)
            .unwrap_or(0);
        
        let (text, numeric) = string.split_at(split_point);
        
        let next = numeric
            .parse()
            .map(|n: u128| n + 1)
            .unwrap_or(1);
        
        format!("{text}{next:>0width$}", width=numeric.len())
    }
    • function incrementString (strng) {
    • // return incrementedString
    • fn incrementString(string: &str) -> String {
    • if string.is_empty() {
    • return "1".to_string();
    • }
    • let split_point = string
    • .rfind(|ch: char| !ch.is_ascii_digit())
    • .map(|i| i + 1)
    • .unwrap_or(0);
    • let (text, numeric) = string.split_at(split_point);
    • let next = numeric
    • .parse()
    • .map(|n: u128| n + 1)
    • .unwrap_or(1);
    • format!("{text}{next:>0width$}", width=numeric.len())
    • }
Code
Diff
  • public class Kumite {
      public static bool IsThree(int x) =>
        x.ToString().Contains('3');
    }
    • using System.Linq;
    • public class Kumite {
    • public static bool IsThree(int x) =>
    • $"{x}".Any(x => x == '3');
    • x.ToString().Contains('3');
    • }

Changes:

  • any returns a bool based on a predicate, so removed match and position
  • the into_iter wasn't needed because chars is already an Iterator!
Code
Diff
  • fn solution(x: i32) -> bool {
        x.to_string().chars().any(|s| s == '3')
    }
    • fn solution(mut x: i32) -> bool {
    • match x.to_string().chars().into_iter().position(|s| s == '3') {
    • Some(_t) => true,
    • _e => false,
    • }
    • fn solution(x: i32) -> bool {
    • x.to_string().chars().any(|s| s == '3')
    • }