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
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.

Fundamentals
Code
Diff
  • #include <iostream>
    #include <string>
    using namespace std ;
    
    int helloCplusplus(){
      string str("Hello, C++!");
      cout << str << endl;
      return 0;
    }
    • #include <iostream>
    • #include <string>
    • using namespace std ;
    • int helloCplusplus(){
    • string str = "Hello, C++!";
    • cout << str << '\n';
    • string str("Hello, C++!");
    • cout << str << endl;
    • return 0;
    • }
Code
Diff
  • import java.util.Arrays;
    class Solution {
      
    	   
         public static int retSmallestPositiveInteger() {
             for(int i=1; true ; i++) {
                if (i % 10 == 0)
                    continue;
                if(hasSameDigits(i, i*2, i*3, i*4 , i*5, i*6))
                    return i; 
             }
         }
      
    	    private static boolean hasSameDigits(int a, int b, int c, int d, int e, int f) {
          
    		      char[] aDigits = Integer.toString(a).toCharArray();
    		      char[] bDigits = Integer.toString(b).toCharArray();
              char[] cDigits = Integer.toString(c).toCharArray();
              char[] dDigits = Integer.toString(d).toCharArray();
              char[] eDigits = Integer.toString(e).toCharArray();
              char[] fDigits = Integer.toString(f).toCharArray();
              
    		      Arrays.sort(aDigits);
    		      Arrays.sort(bDigits);
              Arrays.sort(cDigits);
              Arrays.sort(dDigits);
              Arrays.sort(eDigits);
              Arrays.sort(fDigits);
              
    		      return (Arrays.equals(aDigits, bDigits) && Arrays.equals(aDigits, cDigits) && Arrays.equals(aDigits, dDigits) && Arrays.equals(aDigits, eDigits) && Arrays.equals(aDigits, fDigits));
              
          }
    }
    • import java.util.*;
    • import java.util.Arrays;
    • class Solution {
    • public static int retSmallestPositiveInteger() {
    • for(int i=1; ; i++) {
    • if(hasSameDigits(i, i*2) && hasSameDigits(i, i*3) && hasSameDigits(i, i*4) && hasSameDigits(i, i*5) && hasSameDigits(i, i*6))
    • return i;
    • for(int i=1; true ; i++) {
    • if (i % 10 == 0)
    • continue;
    • if(hasSameDigits(i, i*2, i*3, i*4 , i*5, i*6))
    • return i;
    • }
    • }
    • private static boolean hasSameDigits(int x, int y) {
    • char[] xdigits = Integer.toString(x).toCharArray();
    • char[] ydigits = Integer.toString(y).toCharArray();
    • Arrays.sort(xdigits);
    • Arrays.sort(ydigits);
    • return Arrays.equals(xdigits, ydigits);
    • private static boolean hasSameDigits(int a, int b, int c, int d, int e, int f) {
    • char[] aDigits = Integer.toString(a).toCharArray();
    • char[] bDigits = Integer.toString(b).toCharArray();
    • char[] cDigits = Integer.toString(c).toCharArray();
    • char[] dDigits = Integer.toString(d).toCharArray();
    • char[] eDigits = Integer.toString(e).toCharArray();
    • char[] fDigits = Integer.toString(f).toCharArray();
    • Arrays.sort(aDigits);
    • Arrays.sort(bDigits);
    • Arrays.sort(cDigits);
    • Arrays.sort(dDigits);
    • Arrays.sort(eDigits);
    • Arrays.sort(fDigits);
    • return (Arrays.equals(aDigits, bDigits) && Arrays.equals(aDigits, cDigits) && Arrays.equals(aDigits, dDigits) && Arrays.equals(aDigits, eDigits) && Arrays.equals(aDigits, fDigits));
    • }
    • }

In the study of math, we usually assert (x,y) to set the point in 2-D condition. (x,y,z) to set the point in 3-D condition. As so on.
When we count the distance of two points in 2-D condition, like (x1,y1) and (x2,y2) . We do:
sqrt[(x1-x2)**2+(y1-y2)**2]

The same idea to apply in N-dimensions.

Code
Diff
  • def distance_count(a,b):
        return sum([(i-j)**2 for (i,j) in zip(a,b)])**0.5
            
    
    • import numpy as np
    • # calculate the distance between two points in 2d,3d ... nD
    • def distanceND(pA, pB, nD = None):
    • return np.linalg.norm(np.array(pA) - np.array(pB))
    • distance2D = distanceND
    • distance3D =distanceND
    • def distance_count(a,b):
    • return sum([(i-j)**2 for (i,j) in zip(a,b)])**0.5
Code
Diff
  • puts `gem list`
    • from subprocess import call
    • call(["pip", "freeze"])
    • puts `gem list`
Code
Diff
  • from math import sqrt
    def is_prime(n):
        return n > 1 and all(n % i for i in range(2, int(sqrt(n))+1))
    • import math
    • from math import sqrt
    • def is_prime(n):
    • if n % 2 == 0 and n > 2:
    • return False
    • for i in range(3, int(math.sqrt(n)) + 1, 2):
    • if n % i == 0:
    • return False
    • return True
    • return n > 1 and all(n % i for i in range(2, int(sqrt(n))+1))
Code
Diff
  • print("Hello World")
    • cat("Hello World!\n")
    • print("Hello World")
Code
Diff
  • # write a add function that doesn't use the plus symbol
    def add(a, b)
      a - -b
    end
    
    # Make sure to view the test cases to see how this test now passes
    • # write a add function that doesn't use the plus symbol
    • def add(a, b)
    • a + b
    • a - -b
    • end
    • # 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 now passes