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.
const firstNonRepeatingCharacter = (str) => { console.log("haha"); for (let i = 0; i < str.length; i++) { let seenDuplicate = false; for (let j = 0; j < str.length; j++) { if (str[i] === str[j] && i !== j) { seenDuplicate = true; break; } } if (!seenDuplicate) { return str[i]; } } return null; // return null if no unique character is found };
- const firstNonRepeatingCharacter = (str) => {
- console.log("haha");
- for (let i = 0; i < str.length; i++) {
- let seenDuplicate = false;
- for (let j = 0; j < str.length; j++) {
- if (str[i] === str[j] && i !== j) {
- seenDuplicate = true;
- break;
- }
- }
- if (!seenDuplicate) {
- return str[i];
- }
- }
- return null; // return null if no unique character is found
- };
import java.util.Arrays; public class MaxNumber { public static long print(long number) { String numberStr = Long.toString(number); char[] digits = numberStr.toCharArray(); Arrays.sort(digits); for (int i = 0; i < digits.length / 2; i++) { char temp = digits[i]; digits[i] = digits[digits.length - i - 1]; digits[digits.length - i - 1] = temp; } String maxNumberStr = new String(digits); number = Long.parseLong(maxNumberStr); return number; } }
- import java.util.Arrays;
- public class MaxNumber {
- public static long print(long number) {
return number- String numberStr = Long.toString(number);
- char[] digits = numberStr.toCharArray();
- Arrays.sort(digits);
- for (int i = 0; i < digits.length / 2; i++) {
- char temp = digits[i];
- digits[i] = digits[digits.length - i - 1];
- digits[digits.length - i - 1] = temp;
- }
- String maxNumberStr = new String(digits);
- number = Long.parseLong(maxNumberStr);
- return number;
- }
- }
Hi
local solution = {} function solution.initperson(name, iq) return {name=name,iq=iq} end local you = solution.initperson("you",0) print(string.format("%s have %s IQ!", you.name, 1/you.iq)) -- String placeholder since 1/0 returns "inf" lol return solution
- local solution = {}
- function solution.initperson(name, iq)
- return {name=name,iq=iq}
- end
- local you = solution.initperson("you",0)
print(you.name.." have "..1/you.iq.." IQ!")- print(string.format("%s have %s IQ!", you.name, 1/you.iq)) -- String placeholder since 1/0 returns "inf" lol
- return solution
struct Developer { language: Language /* left out the rest because it would just generate unused warnings */ } enum Language { Python, Ruby, JavaScript } fn is_language_diverse(list: &[Developer]) -> bool { let (mut python, mut ruby, mut javascript) = (0, 0, 0); for developer in list { match developer.language { Language::Python => python += 1, Language::Ruby => ruby += 1, Language::JavaScript => javascript += 1, } } python.max(ruby).max(javascript) <= 2 * python.min(ruby).min(javascript) }
function isLanguageDiverse(list) {const counts = {};for (let i = 0; i < list.length; i++) { // ho usato un ciclo for per contare quante volte appare un linguaggioconst language = list[i].language; // ho assegnato il linguaggio corrente a una variabilecounts[language] = counts[language] ? counts[language] + 1 : 1; // ho usato un operatore ternario per incrementare il contatore}const countsValues = Object.values(counts); // ho usato Object.values per ottenere i valori dell'oggetto countsconst maxCount = Math.max(...countsValues); // ho usato Math.max per trovare il valore massimoconst minCount = Math.min(...countsValues); // ho usato Math.min per trovare il valore minimoreturn maxCount <= 2 * minCount; // ho usato un operatore ternario per restituire true o false}//Test cases- struct Developer {
- language: Language
- /* left out the rest because it would just generate unused warnings */
- }
const list1 = [{ firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },{ firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },{ firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },{ firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },{ firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },{ firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }];- enum Language {
- Python,
- Ruby,
- JavaScript
- }
const list2 = [{ firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },{ firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },{ firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },{ firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },{ firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },{ firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' },{ firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }];- fn is_language_diverse(list: &[Developer]) -> bool {
- let (mut python, mut ruby, mut javascript) = (0, 0, 0);
- for developer in list {
- match developer.language {
- Language::Python => python += 1,
- Language::Ruby => ruby += 1,
- Language::JavaScript => javascript += 1,
- }
- }
- python.max(ruby).max(javascript) <= 2 * python.min(ruby).min(javascript)
- }
console.log(isLanguageDiverse(list1)); // falseconsole.log(isLanguageDiverse(list2)); // true
#[cfg(test)] mod tests { use super::{is_language_diverse, Developer, Language::{self, *}}; fn d(language: Language) -> Developer { Developer { language } } #[test] fn test_true() { assert!(is_language_diverse(&[d(Python), d(Ruby), d(JavaScript)])); assert!(is_language_diverse(&[d(Python), d(Python), d(Ruby), d(Ruby), d(JavaScript)])); assert!(is_language_diverse(&[d(Python), d(Python), d(Ruby), d(Ruby), d(Ruby), d(Ruby), d(JavaScript), d(JavaScript)])); } #[test] fn test_false() { assert!(!is_language_diverse(&[d(Python), d(Ruby), d(Ruby), d(JavaScript), d(JavaScript), d(JavaScript)])); assert!(!is_language_diverse(&[d(Python), d(Python), d(Python), d(JavaScript), d(JavaScript), d(JavaScript)])); assert!(!is_language_diverse(&[d(Python)])); } }
// 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");- #[cfg(test)]
- mod tests {
- use super::{is_language_diverse, Developer, Language::{self, *}};
- fn d(language: Language) -> Developer {
- Developer { language }
- }
- #[test]
- fn test_true() {
- assert!(is_language_diverse(&[d(Python), d(Ruby), d(JavaScript)]));
- assert!(is_language_diverse(&[d(Python), d(Python), d(Ruby), d(Ruby), d(JavaScript)]));
- assert!(is_language_diverse(&[d(Python), d(Python), d(Ruby), d(Ruby), d(Ruby), d(Ruby), d(JavaScript), d(JavaScript)]));
- }
describe("Solution", function() {it("should test for something", function() {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);});});- #[test]
- fn test_false() {
- assert!(!is_language_diverse(&[d(Python), d(Ruby), d(Ruby), d(JavaScript), d(JavaScript), d(JavaScript)]));
- assert!(!is_language_diverse(&[d(Python), d(Python), d(Python), d(JavaScript), d(JavaScript), d(JavaScript)]));
- assert!(!is_language_diverse(&[d(Python)]));
- }
- }
trait HasAge { fn age(&self) -> i32; } fn find_oldest<T: HasAge + Clone>(list: &[T]) -> Vec<T> { if let Some(max_age) = list.iter().map(T::age).max() { list.iter().filter(|e| e.age() == max_age).cloned().collect() } else { Vec::new() } }
mod preloaded;use preloaded::Developer;- trait HasAge {
- fn age(&self) -> i32;
- }
fn find_senior(list: &[Developer]) -> Vec<Developer> {let max_age = list.iter().map(|d| d.age).max().unwrap();list.iter().filter(|d| d.age == max_age).copied().collect()- fn find_oldest<T: HasAge + Clone>(list: &[T]) -> Vec<T> {
- if let Some(max_age) = list.iter().map(T::age).max() {
- list.iter().filter(|e| e.age() == max_age).cloned().collect()
- } else {
- Vec::new()
- }
- }
#[cfg(test)] mod tests { use super::{HasAge, find_oldest}; #[test] fn test_custom_metric() { impl HasAge for &str { fn age(&self) -> i32 { self.len() as i32 } } assert_eq!(find_oldest(&["young"]), ["young"]); assert_eq!(find_oldest(&["much older", "young"]), ["much older"]); assert_eq!(find_oldest(&[" 1 ", "99", "999", "442"]), [" 1 ", "999", "442"]); } #[test] fn test_wrapper() { #[derive(Debug, Copy, Clone, PartialEq, Eq)] struct Age(i32); impl HasAge for Age { fn age(&self) -> i32 { self.0 } } assert_eq!(find_oldest::<Age>(&[]), []); assert_eq!(find_oldest(&[Age(10)]), [Age(10)]); assert_eq!(find_oldest(&[Age(10), Age(20), Age(30)]), [Age(30)]); assert_eq!(find_oldest(&[Age(30), Age(20), Age(10)]), [Age(30)]); assert_eq!(find_oldest(&[Age(30), Age(20), Age(30)]), [Age(30), Age(30)]); } #[test] fn test_developer() { #[derive(Debug, Copy, Clone, PartialEq, Eq)] struct Developer { first_name: &'static str, age: u8, language: &'static str } impl HasAge for Developer { fn age(&self) -> i32 { self.age.into() } } const LIST1: [Developer;4] = [ Developer { first_name: "Gabriel", age: 49, language: "PHP", }, Developer { first_name: "Odval", age: 38, language: "Python", }, Developer { first_name: "Guea", age: 24, language: "Java", }, Developer { first_name: "Sou", age: 49, language: "PHP", } ]; const LIST2: [Developer;5] = [ Developer { first_name: "Gabriel", age: 49, language: "PHP", }, Developer { first_name: "Odval", age: 38, language: "Python", }, Developer { first_name: "Emilija", age: 19, language: "Python", }, Developer { first_name: "Sou", age: 49, language: "PHP", }, Developer { first_name: "Sou", age: 49, language: "PHP", } ]; assert_eq!(find_oldest(&LIST1), [ Developer { first_name: "Gabriel", age: 49, language: "PHP", }, Developer { first_name: "Sou", age: 49, language: "PHP", }, ]); assert_eq!(find_oldest(&LIST2), [ Developer { first_name: "Gabriel", age: 49, language: "PHP", }, Developer { first_name: "Sou", age: 49, language: "PHP", }, Developer { first_name: "Sou", age: 49, language: "PHP", } ]); } }
#[test]fn test() {assert_eq!(find_senior(&LIST1), [Developer {first_name: "Gabriel",last_name: "X.",country: "Monaco",continent: "Europe",age: 49,language: "PHP",},Developer {first_name: "Sou",last_name: "Bocc.",country: "Japan",continent: "Asia",age: 49,language: "PHP",},]);- #[cfg(test)]
- mod tests {
- use super::{HasAge, find_oldest};
assert_eq!(find_senior(&LIST2), [Developer {first_name: "Gabriel",last_name: "X.",country: "Monaco",continent: "Europe",age: 49,language: "PHP",},Developer {first_name: "Sou",last_name: "B.",country: "Japan",continent: "Asia",age: 49,language: "PHP",},Developer {first_name: "Sou",last_name: "B.",country: "Japan",continent: "Asia",age: 49,language: "PHP",- #[test]
- fn test_custom_metric() {
- impl HasAge for &str {
- fn age(&self) -> i32 {
- self.len() as i32
- }
- }
]);}const LIST1: [Developer;4] = [Developer {first_name: "Gabriel",last_name: "X.",country: "Monaco",continent: "Europe",age: 49,language: "PHP",},Developer {first_name: "Odval",last_name: "Fabio.",country: "Mongolia",continent: "Asia",age: 38,language: "Python",},Developer {first_name: "Guea",last_name: "Serge.",country: "Italy",continent: "Europe",age: 24,language: "Java",},Developer {first_name: "Sou",last_name: "Bocc.",country: "Japan",continent: "Asia",age: 49,language: "PHP",- assert_eq!(find_oldest(&["young"]), ["young"]);
- assert_eq!(find_oldest(&["much older", "young"]), ["much older"]);
- assert_eq!(find_oldest(&[" 1 ", "99", "999", "442"]), [" 1 ", "999", "442"]);
- }
];- #[test]
- fn test_wrapper() {
- #[derive(Debug, Copy, Clone, PartialEq, Eq)]
- struct Age(i32);
- impl HasAge for Age {
- fn age(&self) -> i32 {
- self.0
- }
- }
- assert_eq!(find_oldest::<Age>(&[]), []);
- assert_eq!(find_oldest(&[Age(10)]), [Age(10)]);
- assert_eq!(find_oldest(&[Age(10), Age(20), Age(30)]), [Age(30)]);
- assert_eq!(find_oldest(&[Age(30), Age(20), Age(10)]), [Age(30)]);
- assert_eq!(find_oldest(&[Age(30), Age(20), Age(30)]), [Age(30), Age(30)]);
- }
- #[test]
- fn test_developer() {
- #[derive(Debug, Copy, Clone, PartialEq, Eq)]
- struct Developer {
- first_name: &'static str,
- age: u8,
- language: &'static str
- }
- impl HasAge for Developer {
- fn age(&self) -> i32 {
- self.age.into()
- }
- }
- const LIST1: [Developer;4] = [
- Developer {
- first_name: "Gabriel",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Odval",
- age: 38,
- language: "Python",
- },
- Developer {
- first_name: "Guea",
- age: 24,
- language: "Java",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- }
- ];
const LIST2: [Developer;5] = [Developer {first_name: "Gabriel",last_name: "X.",country: "Monaco",continent: "Europe",age: 49,language: "PHP",},Developer {first_name: "Odval",last_name: "F.",country: "Mongolia",continent: "Asia",age: 38,language: "Python",},Developer {first_name: "Emilija",last_name: "S.",country: "Lithuania",continent: "Europe",age: 19,language: "Python",},Developer {first_name: "Sou",last_name: "B.",country: "Japan",continent: "Asia",age: 49,language: "PHP",},Developer {first_name: "Sou",last_name: "B.",country: "Japan",continent: "Asia",age: 49,language: "PHP",- const LIST2: [Developer;5] = [
- Developer {
- first_name: "Gabriel",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Odval",
- age: 38,
- language: "Python",
- },
- Developer {
- first_name: "Emilija",
- age: 19,
- language: "Python",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- }
- ];
- assert_eq!(find_oldest(&LIST1), [
- Developer {
- first_name: "Gabriel",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- },
- ]);
- assert_eq!(find_oldest(&LIST2), [
- Developer {
- first_name: "Gabriel",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- },
- Developer {
- first_name: "Sou",
- age: 49,
- language: "PHP",
- }
- ]);
- }
];- }
function calculateEvenNumbers(array $numbers): int { return count(array_filter($numbers, function($num) { return $num % 2 === 0; })); }
- function calculateEvenNumbers(array $numbers): int {
$count = 0;foreach ($numbers as $number) {if ($number % 2 === 0) {$count++;}}return $count;- return count(array_filter($numbers, function($num) { return $num % 2 === 0; }));
- }
fix the code lol
#include <stdio.h> int prnt_mltply(int m, int n) { int i = 1; while(i <= m) { int j = 1; while(j <= n) { printf("%d * %d = %d \n", i, j, i * j); j++; } i++; printf("\n"); } return m - n; }
#include<stdio.h>int main(){int i=1;while(i<=5){int j=1;while(j<=12){printf("%d * %d =%d", i,j, i*j);j++;- #include <stdio.h>
- int prnt_mltply(int m, int n) {
- int i = 1;
- while(i <= m) {
- int j = 1;
- while(j <= n) {
- printf("%d * %d = %d
- ", i, j, i * j);
- j++;
- }
- i++;
- printf("\n");
- }
i++;printf("\n");}return(0);- return m - n;
- }
#include <criterion/criterion.h> int prnt_mltply(int m, int n); void tester(int m, int n, int expected); Test(prnt_mltply, Sample_Test) { tester(5, 12, 60); } void tester(int m, int n, int expected) { int submitted = prnt_mltply(m, n); cr_assert_eq( submitted, expected, "< Incorrect Result >\n \nm = %d\nn = %d\n \nSubmitted: %d\nExpected: %d", m, n, submitted, expected ); }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.- #include <criterion/criterion.h>
// replace with the actual method being testedint foo(int,int);- int prnt_mltply(int m, int n);
- void tester(int m, int n, int expected);
Test(the_multiply_function, should_pass_all_the_tests_provided) {cr_assert_eq(foo(1, 1), 1);- Test(prnt_mltply, Sample_Test)
- {
- tester(5, 12, 60);
- }
- void tester(int m, int n, int expected) {
- int submitted = prnt_mltply(m, n);
- cr_assert_eq( submitted, expected,
- "< Incorrect Result >\n \nm = %d\nn = %d\n \nSubmitted: %d\nExpected: %d",
- m, n, submitted, expected
- );
- }
Greeting=lambda name,rank="",formal=0: f"He{('y','llo')[formal]}, {rank*formal}{' '*bool(rank and formal)}{name}{'!.'[formal]}"
greeting=Greeting=lambda name,rank='',formal=False:"He{0}, {1}{2}{3}{4}".format(('y','llo')[formal],rank*formal,' '*bool(rank and formal),name,'!.'[formal])- Greeting=lambda name,rank="",formal=0: f"He{('y','llo')[formal]}, {rank*formal}{' '*bool(rank and formal)}{name}{'!.'[formal]}"