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()
- }
Debugging
Image Processing
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"))]
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]
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(is_palindrome('manninggninnam'), True) test.assert_equals(is_palindrome('manning'), False) test.assert_equals(is_palindrome('emotionallanoitome'), True) test.assert_equals(is_palindrome('emotional'), False)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(1 + 1, 2)- test.assert_equals(is_palindrome('manninggninnam'), True)
- test.assert_equals(is_palindrome('manning'), False)
- test.assert_equals(is_palindrome('emotionallanoitome'), True)
- test.assert_equals(is_palindrome('emotional'), False)
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)}`
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;
- }
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/5self._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_offsetreturn round(fahrenheit, 2)- return round((self.temp * 9 / 5) + 32, 2)
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)))
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;
- }