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

Write an implementation of a method:

  • @param a - array of numbers, array length can be greater than 10 million.
  • @return - array of numbers with no duplicates. The order of numbers in the original array must be preserved. The last element of the duplicates must be kept, e.g. for {2.0, 1.0, 4.0, 2.0, 3.0} the correct solution is {1.0, 4.0, 2.0, 3.0}, not {2.0, 1.0, 4.0, 3.0}!

In case there is an element less than 0.0 in the input array, output array{-1.0} should be given.
For example, for {2.0, 3.0, -1.0, 5.0} the processing should result {-1.0}.

Good luck...

import java.util.*;

class DeleteDuplicates {
  public static double[] delete(double[] a) { 
    
    for(int i = 0; i < a.length / 2; i++) {
      double temp = a[i];
      a[i] = a[a.length - i - 1];
      a[a.length - i - 1] = temp;
    }

    Set<Double> set = new LinkedHashSet<>();
    for (double v : a) {
      set.add(v);
      if(v < 0.0)
        return new double[]{-1.0};
    }

    List<Double> list = new ArrayList<>(set);
    Collections.reverse(list);

    double[] array_here = list.stream().mapToDouble(Double::doubleValue).toArray();
    
    //incorrect (too long and witout accuracy)
    
    return array_here;
  }
}
Fundamentals
Strings
Data Types
Logic

Write a function that returns string:

"Fizz" when the number is divisible by 3.
"Buzz" when the number is divisible by 5.
"FizzBuzz" when the number is divisible by 3 and 5.

public class FizzBuzz
 {
   public string GetOutput(int number)
   {
     if ((number % 3 == 0) && (number % 5 == 0))
       return "FizzBuzz";

     else if (number % 3 == 0)
       return "Fizz";

     else if (number % 5 == 0)
       return "Buzz";

    else return number.ToString(); 
   }
}

Write the function optimal_gifts(gifts: int, recipients: int) -> int
You are given gifts number of gifts and recipients number of recipients.

Return the maximum number of recipients that can receive 8 gifts under the following conditions:

  • No recipient can recieve no gifts
  • No recipient can recieve 4 gifts
  • No recipient can receive more than 8 gifts
  • All gifts must be distibuted unless all recipients are already recveiving 8 gifts

Examples:

  • optimal_gifts(8, 2) returns 0
  • optimal_gifts(12, 2) returns 0
  • optimal_gifts(8, 1) returns 1
  • optimal_gifts(24, 2) returns 2
  • optimal_gifts(24, 3) returns 3
  • optimal_gifts(24, 4) returns 2
def optimal_gifts(gifts: int, recipients: int) -> int:
    kids = [1 for _ in range(gifts)]
    gifts -= recipients
    for i in range(recipients):
        while (gifts > 0 and kids[i] < 8):
            kids[i] += 1
            gifts -= 1

    eigths = sum([1 if kid == 8 else 0 for kid in kids])

    if 4 in kids:
        eigths -= 1
        
    return eigths

Always forget how to exact determine programmer's day. Some code may help do it exactly and without heavy calculations.

# How to check that target date is Programmer's day?

def is_programmers_day(date):
    return date.timetuple().tm_yday == 256
package kata



func Solution(str string) []string {
  var res []string
  if len(str) % 2 != 0 {
    str += "_"
  }
  for i := 0; i < len(str); i+=2 {
    res = append(res, str[i:i+2])
  }
  return res
}
import random

def approximate_pi(n):
    # n - number of generated points, more points => more accuracy
    number_of_points_in_circle = 0
    total_number_of_points = 0

    for _ in range(n):
        x = random.uniform(0, 1)
        y = random.uniform(0, 1)

        # sqrt(x^2 + y^2) < 1 => (x,y) inside circle with r = 1; x^2 + y^2 < 1 => (x,y) inside circle
        if (x**2 + y**2 < 1):
            number_of_points_in_circle += 1

        total_number_of_points += 1

    # Pi * r^2 / (2r)^2 = number_of_points_in_circle / total_number_of_points (ratio of the area of a circle with radius r to the area of a square with side = 2r)
    # r=1 => Pi = number_of_points_in_circle * 4 / total_number_of_points
    return (number_of_points_in_circle * 4) / total_number_of_points

Simple test to see how creating Kumites work

This function should return the sum of a and b.

(1,2) => 3
(5,9) => 14
(-3,8) => 5

def add(a, b):
    return a + b
import re
def remove_numbers(string):
    return re.sub(r"[0-9]","",string)
const input = ["a", 1, 2, false, "b"];
const output = input.reduce((acc, el) => {
  const type = typeof el;
  acc[type] = acc[type] || [];
  acc[type].push(el);
  return acc;
}, {});
console.log(output);

Your job is to group the words in anagrams.

What is an anagram ?

star and tsar are anagram of each other because you can rearrange the letters for star to obtain tsar.

Example

A typical test could be :

// input
groupAnagrams(["tsar", "rat", "tar", "star", "tars", "cheese"]);

// output
[
  ["tsar", "star", "tars"],
  ["rat", "tar"],
  ["cheese"]
]
## Helpers

The method `assertSimilarUnsorted` has been preloaded for you **in the Solution Sandbox only** to compare to arrays without relying on the sorting of the elements.

`assertSimilarUnsorted([[1,2], [3]], [[3], [1,2]]); // returns true`

Hvae unf !

I'd advise you to find an efficient way for grouping the words in anagrams otherwise you'll probably won't pass the heavy superhero test cases

def group_anagrams(words):
    def sort_word(word):
        charlist = list(word)
        charlist.sort()
        return "".join(charlist)
    
    anagrams = {}
    for word in words:
        sorted = sort_word(word)
        if sorted in anagrams:
            anagrams[sorted].append(word)
        else:
            anagrams[sorted] = [word]
            
    return list(anagrams.values())