Ad
Code
Diff
  • fn verify_sum(name_one: &str, name_two: &str) -> bool {
        sum(name_one) == sum(name_two)
    }
    
    fn sum(name: &str) -> u32 {
        name.chars()
            .filter(|ch| ch.is_ascii_alphabetic())
            .map(|ch| ch as u32)
            .sum()
    }
    • fn verify_sum(name_one: &str, name_two: &str) -> bool {
    • sum(name_one) == sum(name_two)
    • }
    • fn sum(name: &str) -> u32 {
    • name.bytes().map(u32::from).sum()
    • name.chars()
    • .filter(|ch| ch.is_ascii_alphabetic())
    • .map(|ch| ch as u32)
    • .sum()
    • }
Code
Diff
  • fn reverse(s: &str) -> String {
        s.chars().fold(String::new(), |acc, c| format!("{}{}", c, acc))
    }
    • fn reverse(s:&str)->String{s.chars().rev().collect()}
    • fn reverse(s: &str) -> String {
    • s.chars().fold(String::new(), |acc, c| format!("{}{}", c, acc))
    • }
Code
Diff
  • x = lambda a: ''.join(reversed(a))
    • x=lambda a:a[::-1]
    • x = lambda a: ''.join(reversed(a))
Debugging
Image Processing
Code
Diff
  • import shutil
    import os
    
    
    def move_image_files(source, destination):
        [shutil.move(os.path.join(source, filename), os.path.join(destination, filename)) for filename in os.listdir(source)
         if filename.endswith((".png", ".jpeg", ".jpg", ".svg", ".tiff", ".webp", ".ppm"))]
    • import shutil
    • import os
    • IMAGE_FILE_EXTENSIONS = (".png", ".jpeg", ".jpg", ".svg", ".tiff", ".webp",".ppm")
    • def move_image_files(source, destination):
    • for filename in os.listdir(source):
    • if filename.endswith(IMAGE_FILE_EXTENSIONS):
    • old_path = os.path.join(source, filename)
    • new_path = os.path.join(destination, filename)
    • shutil.move(old_path, new_path)
    • [shutil.move(os.path.join(source, filename), os.path.join(destination, filename)) for filename in os.listdir(source)
    • if filename.endswith((".png", ".jpeg", ".jpg", ".svg", ".tiff", ".webp", ".ppm"))]
Code
Diff
  • def is_palindrome(s: str) -> bool:
        s = s.lower()
        s = ''.join([c for c in s if c.isalnum()])
        return s == s[::-1]
    • def is_palindrome(s: str) -> bool:
    • return s.lower() == s.lower()[::-1]
    • s = s.lower()
    • s = ''.join([c for c in s if c.isalnum()])
    • return s == s[::-1]
Code
Diff
  • yearlyElectricCosts=(...c)=>+`${(''+c.reduce((a,b)=>a+b)).split`.`[0]}.${(''+c.reduce((a,b)=>a+b)).split`.`[1].slice(0,2)}`
    • yearlyElectricCosts=(...c)=>(r=>+`${r[0]}.${r[1].slice(0,2)}`)((''+c.reduce((a,b)=>a+b)).split`.`)
    • yearlyElectricCosts=(...c)=>+`${(''+c.reduce((a,b)=>a+b)).split`.`[0]}.${(''+c.reduce((a,b)=>a+b)).split`.`[1].slice(0,2)}`
Code
Diff
  • public static class Kata 
    {
        public static int SameCase(char a, char b) =>
            (a >= 65 && a <= 90 || a >= 97 && a <= 122)
                ? (b >= 65 && b <= 90 || b >= 97 && b <= 122)
                    ? (a >= 97 && b >= 97 || a <= 90 && b <= 90)
                        ? 1
                        : 0
                    : -1
                : -1;
    }
    • public static class Kata
    • {
    • public static int SameCase(char a, char b) =>
    • (!(char.IsLetter(a) && char.IsLetter(b)))
    • ? -1
    • : (char.IsLower(a) == char.IsLower(b))
    • ? 1
    • : 0;
    • public static int SameCase(char a, char b) =>
    • (a >= 65 && a <= 90 || a >= 97 && a <= 122)
    • ? (b >= 65 && b <= 90 || b >= 97 && b <= 122)
    • ? (a >= 97 && b >= 97 || a <= 90 && b <= 90)
    • ? 1
    • : 0
    • : -1
    • : -1;
    • }
Code
Diff
  • import re
    def is_palindrome(s: str) -> bool:
        s = re.sub('[^a-z]', '', s.lower())
        return s == s[::-1]
    
    • import re
    • def is_palindrome(s: str) -> bool:
    • return re.sub('[^a-z]', '', s.lower())[::-1] == re.sub('[^a-z]', '', s.lower())
    • s = re.sub('[^a-z]', '', s.lower())
    • return s == s[::-1]
Code
Diff
  • const reverse = str => str.split('').reduce((acc, char) => char + acc, '');
    • const reverse = str => [...str].reverse().join('');
    • const reverse = str => str.split('').reduce((acc, char) => char + acc, '');
Code
Diff
  • package kata
    
    func Multiple3And5(n int) bool {
    	return n-3*(n/3) == 0 && n-5*(n/5) == 0
    }
    
    • package kata
    • func Multiple3And5(n int) bool {
    • return n - 15 * (n / 15) == 0
    • }
    • return n-3*(n/3) == 0 && n-5*(n/5) == 0
    • }
Code
Diff
  • def verify_sum(a, b)
      return a.sum == b.sum unless a.nil? || b.nil?
    
      'a' == 'b'
    end
    
    • def verify_sum(a,b)
    • a.sum == b.sum
    • end
    • def verify_sum(a, b)
    • return a.sum == b.sum unless a.nil? || b.nil?
    • class NilClass
    • def sum
    • return false
    • end
    • end
    • 'a' == 'b'
    • end
Code
Diff
  • class TemperatureConverter:
        def __init__(self, temp: float):
            self.temp = temp
    
        def fahrenheit_to_celsius(self) -> float:
            return round((self.temp - 32) * (5 / 9), 2)
    
        def celsius_to_fahrenheit(self) -> float:
            return round((self.temp * 9 / 5) + 32, 2)
    
    • class TemperatureConverter:
    • def __init__(self, temp: float) -> None:
    • def __init__(self, temp: float):
    • self.temp = temp
    • self._celsius_to_fahrenheit_factor = 9/5
    • self._celsius_to_fahrenheit_offset = 32
    • def fahrenheit_to_celsius(self) -> float:
    • celsius = (self.temp - 32) * (5/9)
    • return round(celsius, 2)
    • return round((self.temp - 32) * (5 / 9), 2)
    • def celsius_to_fahrenheit(self) -> float:
    • fahrenheit = (self.temp * self._celsius_to_fahrenheit_factor) + self._celsius_to_fahrenheit_offset
    • return round(fahrenheit, 2)
    • return round((self.temp * 9 / 5) + 32, 2)
Code
Diff
  • binary=lambda n: bin(n).replace("0b", "")
    • binary=lambda n: '{:b}'.format(n)
    • binary=lambda n: bin(n).replace("0b", "")
Code
Diff
  • def decompose(num):
        return [int(i) for i in ''.join(map(str, num))]
    
    
    def greatest(num):
        return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
    • def decompose(num):
    • return [int(i) for i in ''.join(map(str, num))]
    • def greatest(num):
    • return int(''.join(sorted([str(y) for x in [[int(z) for z in str(n)] for n in num] for y in x], reverse=True)))
    • return int(''.join(sorted(''.join(map(str, decompose(num))), reverse=True)))
Code
Diff
  • using System.Linq;
    
    public class Kata
    {
      public static bool ContainsCommonItem(char[]a, char[]b) => a?.Any(x => b?.Contains(x) ?? false) ?? false;
    }
    • //Given 2 Arrays, Return True if arrays contain common item, else false.
    • //e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
    • //input : 2 arrays
    • //output: bool
    • using System.Linq;
    • using System.Linq;public class Kata{public static bool ContainsCommonItem(char[]a,char[]b)=>a!=null&&b!=null&&a.Intersect(b).Any();}
    • public class Kata
    • {
    • public static bool ContainsCommonItem(char[]a, char[]b) => a?.Any(x => b?.Contains(x) ?? false) ?? false;
    • }
Loading more items...