Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.

You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.

A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.

Ad
Ad

I used variable name abbreviations and removed some unnecessary lines. I also eliminated intermediate variables that were not necessary and condensed the return statement into a single line.

Code
Diff
  • class KumiteFoo:
        def __init__(self, p):
            self.p = p
        
        def solution(self):
            f = self.p.lower().count('f')
            o = self.p.lower().count('o')
            return 'No' if not self.p or 2 * f != o else 'Yes'
    
    • class KumiteFoo:
    • def __init__(self, param):
    • self.param = param
    • def __init__(self, p):
    • self.p = p
    • def solution(self):
    • f = self.param.lower().count('f')
    • o = self.param.lower().count('o')
    • oo = 2 * f == o
    • if not self.param or not oo:
    • return 'No'
    • return 'Yes'
    • f = self.p.lower().count('f')
    • o = self.p.lower().count('o')
    • return 'No' if not self.p or 2 * f != o else 'Yes'
Code
Diff
  • using System.Collections.Generic;
    using System.Linq;
    
    public class Kata
    {
        /// <summary>
        /// Checks if two char arrays contain at least one common item.
        /// </summary>
        /// <param name="a">First char array</param>
        /// <param name="b">Second char array</param>
        /// <returns>True if the arrays have at least one common item, false otherwise</returns>
        public static bool ContainsCommonItem(char[] a, char[] b)
        {
            // If either input array is null, return false
            if (a == null || b == null) return false;
    
            // Create a HashSet from the first array to optimize lookup
            HashSet<char> setA = new HashSet<char>(a);
    
            // Use LINQ's Any method to check if any item in the second array is present in the HashSet
            return b.Any(item => setA.Contains(item));
        }
    }
    
    • using System.Collections.Generic;
    • using System.Linq;
    • public class Kata
    • {
    • /// <summary>
    • /// Checks if two char arrays contain at least one common item.
    • /// </summary>
    • /// <param name="a">First char array</param>
    • /// <param name="b">Second char array</param>
    • /// <returns>True if the arrays have at least one common item, false otherwise</returns>
    • public static bool ContainsCommonItem(char[] a, char[] b)
    • {
    • // If either input array is null, return false
    • if (a == null || b == null) return false;
    • return new HashSet<char>(a).Overlaps(b);
    • // Create a HashSet from the first array to optimize lookup
    • HashSet<char> setA = new HashSet<char>(a);
    • // Use LINQ's Any method to check if any item in the second array is present in the HashSet
    • return b.Any(item => setA.Contains(item));
    • }
    • }
Debugging
Image Processing
Code
Diff
  • import shutil
    import os
    
    class MoveFiles:
        def __init__(self):    
            self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]
            
    
        def move_image_files(self):
            for img in self.images:
                new_path = os.path.join('folderB', img)            
                shutil.move(os.path.join('folderA', img), new_path)
    
    • import shutil
    • import os
    • class MoveFiles:
    • def __init__(self):
    • self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.txt'))]
    • self.images = [img for img in os.listdir('folderA') if img.endswith(('.png', '.jpg', '.jpeg'))]
    • def move_image_files(self):
    • for img in images:
    • new_path = os.path.join('folderA', img)
    • shutil.move(os.join('folderB', img), img.new_path)
    • for img in self.images:
    • new_path = os.path.join('folderB', img)
    • shutil.move(os.path.join('folderA', img), new_path)
Code
Diff
  • binary = lambda n: bin(n)[2:]
    • binary=lambda n:f'{n:b}'
    • binary = lambda n: bin(n)[2:]

The changes were made to improve the simplicity, readability, and efficiency of the code, which in turn enhances its quality and maintainability. They were also done with the aim of optimizing the code for use in situations where large amounts of data are handled or high performance in data processing is required.

Code
Diff
  • class Solution:
        def __init__(self, data, filename='kumite776.txt'): self.data, self.filename, self.file = data, filename, open(filename, 'w')
        def __del__(self): self.file.close()
        write_to_file = lambda self: self.file.write(self.data)
    
    
    • class Solution:
    • def __init__(self, data, filename='kumite776.txt', preopen=False):
    • self.data = data
    • self.filename = filename
    • self.file = None
    • if preopen:
    • self.file = open(self.filename, 'w')
    • def write_to_file(self):
    • if not self.file:
    • self.file = open(self.filename, 'w')
    • self.file.write(self.data)
    • def __init__(self, data, filename='kumite776.txt'): self.data, self.filename, self.file = data, filename, open(filename, 'w')
    • def __del__(self): self.file.close()
    • write_to_file = lambda self: self.file.write(self.data)