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.
Got rid of the useless mean function from some obscure python library and replaced it with the greatest custom lambda making the code less readable and unmaintainable fitting it all in JUST ONE LINE!!!
Also no static typing, this is python which is known about it's dynamic goodness making this unholy code achievable
;>
One liner let's gooooooooooooooooooooooooooooooooooooooooooooo
rewritten in the best programming language, Python
please add random tests, i am to dumb to build them.
str_opt = lambda s:s if len(s) == 1 else None if len({s.count(i) for i in {*s}}) <= 1 else sorted([*s], key=lambda x: s.count(x))[0]
const firstNonRepeatingCharacter = (str) => {let chars = [], counts = [];for(const char of str) {let index = chars.indexOf(char);if(index < 0) {index = counts.length;chars.push(char);counts.push(0);}counts[index]++;}for(let index = 0; index < chars.length; index++) {if(counts[index] === 1) {return chars[index];}}return null;};- str_opt = lambda s:s if len(s) == 1 else None if len({s.count(i) for i in {*s}}) <= 1 else sorted([*s], key=lambda x: s.count(x))[0]
import codewars_test as test from solution import str_opt import random # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test cases") def test_case(): test.assert_equals(str_opt("abbcc"), "a", "returns the value that repeats the least") test.assert_equals(str_opt("bacc"), "b", "returns the value that repeats the least and goes first") test.assert_equals(str_opt("aabbcc"), None, " returns None if all characters repeat equally") test.assert_equals(str_opt("c"), "c", "returns the value if it is the only one") test.assert_equals(str_opt(""), None, "if it is empty, it returns None") test.assert_equals(str_opt(f"{'a'*10000}{'b'*10000}c"), "c", "shall work with large numbers") test.assert_equals(str_opt(f"{'a'*10000}{'b'*10000}{'c'*10000}"), None, "should handle very long strings with all characters repeating")
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");const assert = chai.assert;// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:// const Test = require("@codewars/test-compat");describe("Solution", function() {it('should return the first non-repeating character', function() {assert.strictEqual(firstNonRepeatingCharacter('abcd'), 'a');assert.strictEqual(firstNonRepeatingCharacter('aabbcdc'), 'd');});it('should return the first non-repeating character when special characters are included', function() {assert.strictEqual(firstNonRepeatingCharacter('a@b@bc'), 'a');});it('should return null when all characters are repeating', function() {assert.strictEqual(firstNonRepeatingCharacter('aabbcc'), null);});it('should return the first character if it is the only one', function() {assert.strictEqual(firstNonRepeatingCharacter('z'), 'z');});it('should handle an empty string correctly', function() {assert.strictEqual(firstNonRepeatingCharacter(''), null);});it('should handle strings with numbers', function() {assert.strictEqual(firstNonRepeatingCharacter('1122a'), 'a');});it('should handle very long strings with the non-repeating character at the end', function() {const longString = 'a'.repeat(10000) + 'b'.repeat(10000) + 'c';assert.strictEqual(firstNonRepeatingCharacter(longString), 'c');});it('should handle very long strings with all characters repeating', function() {const longString = 'a'.repeat(20000) + 'b'.repeat(20000);assert.strictEqual(firstNonRepeatingCharacter(longString), null);});});- import codewars_test as test
- from solution import str_opt
- import random
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test cases")
- def test_case():
- test.assert_equals(str_opt("abbcc"), "a", "returns the value that repeats the least")
- test.assert_equals(str_opt("bacc"), "b", "returns the value that repeats the least and goes first")
- test.assert_equals(str_opt("aabbcc"), None, " returns None if all characters repeat equally")
- test.assert_equals(str_opt("c"), "c", "returns the value if it is the only one")
- test.assert_equals(str_opt(""), None, "if it is empty, it returns None")
- test.assert_equals(str_opt(f"{'a'*10000}{'b'*10000}c"), "c", "shall work with large numbers")
- test.assert_equals(str_opt(f"{'a'*10000}{'b'*10000}{'c'*10000}"), None, "should handle very long strings with all characters repeating")
module MaxNum (maxNum) where import Data.List import Control.Monad import Data.Char maxNum :: Int -> Int maxNum = read . join . map show . reverse . sort . map digitToInt . show
maxnum=lambda n:int(''.join(sorted(str(n),reverse=1)))- module MaxNum (maxNum) where
- import Data.List
- import Control.Monad
- import Data.Char
- maxNum :: Int -> Int
- maxNum = read . join . map show . reverse . sort . map digitToInt . show
module MaxNumSpec where import Test.Hspec import Text.Printf import MaxNum spec :: Spec spec = do describe "Example Test" $ do it ("Simple Tests") $ do let tests = zip [4,12,101,4,13213] [4,21,110,4,33211] in mapM_ (\(x,y) -> (maxNum x) `shouldBe` y) tests
import codewars_test as testfrom solution import maxnumimport random- module MaxNumSpec where
- import Test.Hspec
- import Text.Printf
@test.describe('Example Tests')def example_tests():- import MaxNum
- spec :: Spec
- spec = do
- describe "Example Test" $ do
- it ("Simple Tests") $ do
- let tests = zip [4,12,101,4,13213] [4,21,110,4,33211] in mapM_ (\(x,y) -> (maxNum x) `shouldBe` y) tests
@test.it('Simple Tests')def example_test_case():test.assert_equals(maxnum(4), 4)test.assert_equals(maxnum(12), 21)test.assert_equals(maxnum(101), 110)test.assert_equals(maxnum(4), 4)test.assert_equals(maxnum(13213), 33211)@test.it('random tests')def random_test_case():for i in range(1, 607):i = random.randint(1, 10000)test.assert_equals(sorted([*str(maxnum(i))]), sorted([*str(i)]), str(i))