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.
reinstituted the usefull mean
function and still kept it to ONE LINE!!!1!
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")