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

An asymptoptic change.
I also decided to change the rest of the implementation a little to show a different way to do it.

Code
Diff
  • from functools import reduce
    from operator import add
    
    def ultimate_string_jumble_method(s):
        return reduce(add, (ord(c) for c in s if c != " "), 0)
    • from functools import reduce
    • from operator import add
    • def ultimate_string_jumble_method(s):
    • return sum(ord(c) for c in s.replace(' ', ''))
    • return reduce(add, (ord(c) for c in s if c != " "), 0)
Code
Diff
  • in_array=lambda a,b:sorted(filter(lambda e:any(e in i for i in b),a))
    • % check for Xs in As that exist in B, in sorted order
    • in_array(A, B, X) :-
    • msort(A, Sorted),
    • member(X, Sorted),
    • in_b(X, B).
    • in_b(A, B) :-
    • member(X, B),
    • sub_string(X, _, _, _, A), !.
    • in_array=lambda a,b:sorted(filter(lambda e:any(e in i for i in b),a))
Algorithms
Logic
Arrays
Data Types
Mathematics
Numbers

I had to use this for the kyu 3 binomial expansion kata since I have no clue how to use the BigInts library for Java. Instead of calculating the total value of each factorial, this finds the factors of the numerator and denominator, simplifies, and divides the results.

Note: The n-choose-k formula

        n!
  ------------
   k!(n - k)!
Code
Diff
  • import static java.util.stream.IntStream.rangeClosed;
    
    interface ArrayFactorial {
      static int factorial(int n, int k) {
        return rangeClosed(1, k).reduce(1, (r, i) -> r * (n + 1 - i) / i);
      }
    }
    • import java.util.stream.IntStream;
    • import static java.util.stream.IntStream.rangeClosed;
    • public class ArrayFactorial{
    • public static int factorial(int n, int k) {
    • return IntStream.rangeClosed(1, Math.min(k, n - k))
    • .reduce(1, (r, i) -> r * (n - i + 1) / i);
    • }
    • interface ArrayFactorial {
    • static int factorial(int n, int k) {
    • return rangeClosed(1, k).reduce(1, (r, i) -> r * (n + 1 - i) / i);
    • }
    • }

Removed that one testcase with o=3 because it's not well defined what the behaviour should be if o is 3, and I dislike writing hard-coding type solutions.

Code
Diff
  • // 
    int add(char*s,int o){return*s?*s%48*(!o|~*s+o&1)+add(s+1,o):0;}
    • # just squished your version a little more
    • add=lambda s,o:sum(filter(lambda n:o<1or~n+o&1,map(int,s)))
    • //
    • int add(char*s,int o){return*s?*s%48*(!o|~*s+o&1)+add(s+1,o):0;}
Code
Diff
  • def match(pattern):
        def matcher(string):
            return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string))
        return matcher
    • def match(pattern):
    • def matcher(string):
    • return len(pattern) == len(string) and all(a == b if a != '.' else True for a, b in zip(pattern, string))
    • return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string))
    • return matcher
Code
Diff
  • # A whopping 2 character saving.
    cipher_breaker=lambda s:"".join({c:chr(219-ord(c))," ":c}[c]for c in s)
    • cipher_breaker=lambda s:"".join(c==" "and" "or chr(219-ord(c))for c in s)
    • # A whopping 2 character saving.
    • cipher_breaker=lambda s:"".join({c:chr(219-ord(c))," ":c}[c]for c in s)
Numbers
Data Types
Integers
Algorithms
Logic
Code
Diff
  • #include <stdint.h>
    
    uint_fast8_t number_of_digits(uint64_t n)
    {
      uint_fast8_t digits = 1;
      while(n /= 10) digits++;
      return digits;
    }
    • #include <stdint.h>
    • uint_fast8_t number_of_digits(uint64_t n)
    • {
    • uint_fast8_t digits = 0;
    • for (; n > 0; n /= 10) digits++;
    • uint_fast8_t digits = 1;
    • while(n /= 10) digits++;
    • return digits;
    • }