Ad
Code
Diff
  • public class SpeedLimit {
        public static int sequence(int[] arr) {
            int result = 0;  // initialize the result to 0
            for (int i = 0; i < arr.length; i++) {
                // add the current element to the result
                result += arr[i];
            }
            return result;  // return the result
        }
    }
    
    • public class SpeedLimit{
    • public static int sequence(int[] arr) {
    • return 0;
    • int [] ar = new int[12];
    • }
    • }
    • public class SpeedLimit {
    • public static int sequence(int[] arr) {
    • int result = 0; // initialize the result to 0
    • for (int i = 0; i < arr.length; i++) {
    • // add the current element to the result
    • result += arr[i];
    • }
    • return result; // return the result
    • }
    • }
Strings
Code
Diff
  • fn last_char(s: &str) -> Option<char> {
        s.chars().last()
    }
    
    • const last_char:&dyn Fn(&str)->Option<char>=&|s|s.chars().last();
    • fn last_char(s: &str) -> Option<char> {
    • s.chars().last()
    • }
Code
Diff
  • fun fact(n: Int): Int {
        return (1..n).fold(1) { acc, i -> acc * i }
    }
    
    • fun fact(n: Int) = (1..n).reduce(Int::times)
    • fun fact(n: Int): Int {
    • return (1..n).fold(1) { acc, i -> acc * i }
    • }
Arrays
Code
Diff
  • import static java.util.stream.IntStream.of;
    
    interface Kata {
      // Constants for fine amounts
      static final int FINE_SMALL = 100;
      static final int FINE_MEDIUM = 250;
      static final int FINE_LARGE = 500;
    
      static int speedLimit(int speed, int[] signals) {
        int fine = 0;
    
        // Iterate through the signals
        for (int signal : signals) {
          if (speed > signal + 29) {
            fine += FINE_LARGE;
          } else if (speed > signal + 19) {
            fine += FINE_MEDIUM;
          } else if (speed > signal + 9) {
            fine += FINE_SMALL;
          }
        }
    
        return fine;
      }
    }
    
    • import static java.util.stream.IntStream.of;
    • interface Kata {
    • // Constants for fine amounts
    • static final int FINE_SMALL = 100;
    • static final int FINE_MEDIUM = 250;
    • static final int FINE_LARGE = 500;
    • static int speedLimit(int speed, int[] signals) {
    • return of(signals).reduce(0, (fine, sign) -> fine + (
    • speed > sign + 29 ? 500 :
    • speed > sign + 19 ? 250 :
    • speed > sign + 9 ? 100 : 0));
    • int fine = 0;
    • // Iterate through the signals
    • for (int signal : signals) {
    • if (speed > signal + 29) {
    • fine += FINE_LARGE;
    • } else if (speed > signal + 19) {
    • fine += FINE_MEDIUM;
    • } else if (speed > signal + 9) {
    • fine += FINE_SMALL;
    • }
    • }
    • return fine;
    • }