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

Saved some brackets :)

Code
Diff
  • function add(a, b){
      return a- -b;
    }
    • function add(a, b){
    • return a - (-b);
    • return a- -b;
    • }
Numbers
Data Types
Integers
Algorithms
Logic

Find length formatting string in stack allocated buffer.

Code
Diff
  • use std::io::{Write, Cursor};
    
    fn digits(mut n: u64) -> usize {
      let mut b = [0u8; 20];
      let mut c = Cursor::new(&mut b[..]);
      write!(c, "{}", n).unwrap();
      c.position() as usize
    }
    • use std::io::{Write, Cursor};
    • fn digits(mut n: u64) -> usize {
    • let mut l = 1;
    • while n >= 10 {
    • n /= 10;
    • l += 1;
    • }
    • l
    • let mut b = [0u8; 20];
    • let mut c = Cursor::new(&mut b[..]);
    • write!(c, "{}", n).unwrap();
    • c.position() as usize
    • }
Code
Diff
  • {-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies #-}
    {-# LANGUAGE OverloadedStrings, GADTs, FlexibleContexts, MultiParamTypeClasses #-}
    {-# LANGUAGE NoMonomorphismRestriction, GeneralizedNewtypeDeriving #-}
    module Movies where
    import Database.Persist (insertMany)
    import Database.Persist.Sqlite (runSqlite, runMigration)
    import Database.Persist.TH (mkPersist, mkMigrate, persistUpperCase, share, sqlSettings)
    share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistUpperCase|
    Movies
       title    String
       year     Int
       rating   Int
       deriving Eq Show
    |]
    
    mkMoviesDB :: IO ()
    mkMoviesDB = runSqlite "/tmp/movies.db" $ do
      runMigration migrateTables
      insertMany
        [ Movies "Rise of the Planet of the Apes" 2011 77
        , Movies "Dawn of the Planet of the Apes" 2014 91
        , Movies "Alien" 1979 97
        , Movies "Aliens" 1986 98
        , Movies "Mad Max" 1979 95
        , Movies "Mad Max 2: The Road Warrior" 1981 100
        ]
      return ()
    
    • {-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies #-}
    • {-# LANGUAGE OverloadedStrings, GADTs, FlexibleContexts, MultiParamTypeClasses #-}
    • {-# LANGUAGE NoMonomorphismRestriction, GeneralizedNewtypeDeriving #-}
    • module Movies where
    • import Database.Persist (insertMany)
    • import Database.Persist.Sqlite (runSqlite, runMigration)
    • import Database.Persist.TH (mkPersist, mkMigrate, persistUpperCase, share, sqlSettings)
    • share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistUpperCase|
    • Movies
    • title String
    • year Int
    • rating Int
    • deriving Eq Show
    • |]
    • mkMoviesDB :: IO ()
    • mkMoviesDB = runSqlite "/tmp/movies.db" $ do
    • runMigration migrateTables
    • insertMany
    • [ Movies "Rise of the Planet of the Apes" 2011 77
    • , Movies "Dawn of the Planet of the Apes" 2014 91
    • , Movies "Alien" 1979 97
    • , Movies "Aliens" 1986 98
    • , Movies "Mad Max" 1979 95
    • , Movies "Mad Max 2: The Road Warrior" 1981 100
    • ]
    • return ()
Code
Diff
  • def is_prime(n)
       n.prime?
    end
    • def is_prime(n)
    • return false if n < 2
    • for x in 2.. Math.sqrt(n).round
    • return false if n % x == 0
    • end
    • return true
    • n.prime?
    • end
Code
Diff
  • def is_prime(n):
        return n == 2 or n > 1 and all(n % i for i in range(3, int(n**0.5)+1, 2))
    • def is_prime(n):
    • return n > 1 and all(n % i for i in range(2, int(n**0.5)+1))
    • return n == 2 or n > 1 and all(n % i for i in range(3, int(n**0.5)+1, 2))
Code
Diff
  • def distance_count(x, y):
        return sum((xi-yi)**2 for xi, yi in zip(x, y))**0.5
    
    • def distance_count(a,b):
    • return sum([(i-j)**2 for (i,j) in zip(a,b)])**0.5
    • def distance_count(x, y):
    • return sum((xi-yi)**2 for xi, yi in zip(x, y))**0.5
Code
Diff
  • def get_list(l):
        return ' '.join(l)
    • def get_list(may):
    • new_str = ''
    • for i in may:
    • new_str += i + ' '
    • return new_str[:-1]
    • def get_list(l):
    • return ' '.join(l)
Code
Diff
  • using System;
    class Kata {
        public static string Main(string greeting, string language) {
        	var g = Greeting(greeting, language);
          Console.WriteLine(g);
          return g;
        }
        
        public static string Greeting(string greeting, string language) => $"{greeting}, {language}!";
    }
    • using System;
    • class Kata {
    • public static string Main(string greeting, string language) {
    • Console.Write("{0}, {1}!\n", greeting, language);
    • return greeting + ", " + language + "!";
    • var g = Greeting(greeting, language);
    • Console.WriteLine(g);
    • return g;
    • }
    • public static string Greeting(string greeting, string language) => $"{greeting}, {language}!";
    • }
Ruby on Rails
Frameworks
rails
Ruby Gems

In this varation, I have refactored the code so that the execute helper wraps up the transaction rollback as part of its method call. It also will try to parse the response as json and provide that as the 2nd argument, DRYing up the code as more tests are added.