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.
function wordCount(str) { return str.trim().split(" ").length; }
function wordCount(str) {var words = 1;for(var i = 1; i < str.length; i++) {if(str[i] == " " && str[i - 1] !== " "&& str[i + 1] !== " ") {words++;}}return words;- function wordCount(str) {
- return str.trim().split(" ").length;
- }
Read solution.txt
in preloaded section so the user's solution is read before it's modified.
// write a add function that doesn't use the plus symbol function add(a, b){ return a + b; } // Make sure to view the test cases to see how this test fails // Rewrite solution.txt require('fs').writeFileSync('/home/codewarrior/solution.txt', 'no pluses here!')
- // write a add function that doesn't use the plus symbol
- function add(a, b){
- return a + b;
- }
// Make sure to view the test cases to see how this test fails- // Make sure to view the test cases to see how this test fails
- // Rewrite solution.txt
- require('fs').writeFileSync('/home/codewarrior/solution.txt', 'no pluses here!')
const fs = require('fs'); const solution = fs.readFileSync('/home/codewarrior/solution.txt', 'utf8'); describe("Check Solution", function(){ it("should prevent the '+' symbol from being used anywhere in the code", function(){ Test.expect(solution.indexOf('+') == -1, "Your code isn't allowed to include the + symbol!"); }); }); describe("Check Real Solution", function(){ it("should prevent the '+' symbol from being used anywhere in the code", function(){ Test.expect(realSolution.indexOf('+') == -1, "Your code isn't allowed to include the + symbol!"); }); });
- const fs = require('fs');
- const solution = fs.readFileSync('/home/codewarrior/solution.txt', 'utf8');
- describe("Check Solution", function(){
- it("should prevent the '+' symbol from being used anywhere in the code", function(){
- Test.expect(solution.indexOf('+') == -1, "Your code isn't allowed to include the + symbol!");
- });
- });
- describe("Check Real Solution", function(){
- it("should prevent the '+' symbol from being used anywhere in the code", function(){
- Test.expect(realSolution.indexOf('+') == -1, "Your code isn't allowed to include the + symbol!");
- });
- });
The println function was removed in Swift 3, in favor of just print with the optional terminator: argument, which defaults to "\n".
import XCTest // XCTest Spec Example: // TODO: replace with your own tests (TDD), these are just how-to examples to get you started class SolutionTest: XCTestCase { static var allTests = [ ("Test Example", testExample), ] func testExample() { let actual = 1 XCTAssertEqual(actual, 1) } } XCTMain([ testCase(SolutionTest.allTests) ])
- import XCTest
- // XCTest Spec Example:
- // TODO: replace with your own tests (TDD), these are just how-to examples to get you started
- class SolutionTest: XCTestCase {
- static var allTests = [
- ("Test Example", testExample),
- ]
- func testExample() {
- let actual = 1
- XCTAssertEqual(actual, 1)
- }
- }
- XCTMain([
- testCase(SolutionTest.allTests)
- ])
import java.util.*; import java.util.stream.*; class Solution { public static String largestNumber(Integer[] nums) { final StringBuilder sb = new StringBuilder(); return Arrays.stream(nums) .parallel() .map((n) -> n.toString()) .sorted(Solution::compareNumberString) .collect(Collectors.joining()) .toString(); } private static int compareNumberString(String s1, String s2) { if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1); if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2); return s2.compareTo(s1); } }
- import java.util.*;
- import java.util.stream.*;
- class Solution {
- public static String largestNumber(Integer[] nums) {
Arrays.sort( nums, new Comparator<Integer>() {@Overridepublic int compare(Integer a, Integer b) {String aStr = a.toString();String bStr = b.toString();return (aStr + bStr).compareTo(bStr + aStr) * -1;}} );String result = "";for(Integer num : nums) {result += num.toString();}return result;- final StringBuilder sb = new StringBuilder();
- return Arrays.stream(nums)
- .parallel()
- .map((n) -> n.toString())
- .sorted(Solution::compareNumberString)
- .collect(Collectors.joining())
- .toString();
- }
- private static int compareNumberString(String s1, String s2) {
- if (s2.startsWith(s1)) return compareNumberString(s2.substring(s1.length()), s1);
- if (s1.startsWith(s2)) return compareNumberString(s1.substring(s2.length()), s2);
- return s2.compareTo(s1);
- }
- }
cats :: [Integer]
cats = 1 : do
(c_n, n) <- zip cats [0..]
return $ c_n * 2 * (2 * n + 1) `div` (2 + n)
main = putStrLn $ show $ take 10 cats
def Complicated_Greetings(name): if name == "": return 'Hello, World!!' return f'Hello {name}'
- def Complicated_Greetings(name):
h=["H","e","l","l","o"]c=","w=["W","o","r","l","d"]e="!"k=""for i in h:k+=iif name=="":k+=ck+=" "for i in w:k+=ik=k+e+eelse:k+=" "k+=namereturn k- if name == "":
- return 'Hello, World!!'
- return f'Hello {name}'
import java.util.Arrays; import java.util.Scanner; public class MaxNumber { public static long print(long number) { char[] digits = Long.toString(number).toCharArray(); Arrays.sort(digits); return Long.parseLong(new StringBuilder(new String(digits)).reverse().toString()); } }
- import java.util.Arrays;
- import java.util.Scanner;
- public class MaxNumber {
- public static long print(long number) {
String numeroString = Long.toString(number);char[] digitos = numeroString.toCharArray();Arrays.sort(digitos);StringBuilder numeroOrdenadoStr = new StringBuilder(new String(digitos));numeroOrdenadoStr.reverse();return Long.parseLong(numeroOrdenadoStr.toString());- char[] digits = Long.toString(number).toCharArray();
- Arrays.sort(digits);
- return Long.parseLong(new StringBuilder(new String(digits)).reverse().toString());
- }
public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.print("Ingrese un numero: ");long number = scanner.nextLong();long maxNumber = print(number);System.out.println("El número más alto que se puede formar con estos dígitos es: " + maxNumber);}- }
dumbRockPaperScissors(player1:str, player2:str) -> str:
A la hora del uso diario, agregar información de las variables que recibe la función y su salida. Es una de las mejores prácticas que podemos realizar
Rock, Paper, Scissors -> Los nombres de las variables expresan correctamente su contenido. Al ser tan simple, podemos realizar las declaraciónes en una línea dando igual legibilidad, reduciendo líneas de código y dando mejor apariencia al código.
def dumbRockPaperScissors(player1:str, player2:str) -> str: Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"} if player1 == player2: return "Draw" #we use 'eval' once for two results and implicit return return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins" #This is the same code in one line #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
def dumbRockPaperScissors(player1, player2):Rock = {"Paper"}Paper = {"Scissors"}Scissors = {"Rock"}if player1 in eval(player2):return "Player 1 wins"elif player2 in eval(player1):return "Player 2 wins"else:- def dumbRockPaperScissors(player1:str, player2:str) -> str:
- Rock, Paper, Scissors = {"Paper"}, {"Scissors"}, {"Rock"}
- if player1 == player2:
- return "Draw"
- #we use 'eval' once for two results and implicit return
- return "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"
- #This is the same code in one line
- #return "Draw" if player1 == player2 else "Player 1 wins" if player1 in eval(player2) else "Player 2 wins"