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

Description

You will be given a String which will be composed of different groups of letters and numbers separated by a blank space. You will have to calculate for each group whether the value of the sum of the letters is greater, equal or less than the multiplication of the numbers. The value of each letter corresponds to its position in the alphabet so a=1, b=2, c=3 ... x=24, y=25 and z=26. If there are more groups that have a greater numeric value you will return 1. If the alphabetic value is greater for more groups, you will return -1. If there are the same number of groups with greater numeric and alphabetic values, you will return 0.

Example:

("12345 9812") -> 1
("abc def") -> -1
("abcdef 12345") -> 0 since the first group has a greater letter value and the second group has a greater numeric value
("a1b2c3") -> 0 since the sum of the letters (1(a)+2(b)+3(c)) is equal to the multiplication of the numbers (1*2*3)

Notes:

  • There won't be any uppercase letters
  • Special characters such as # or $ do not have any value
  • There might be empty Strings

Task:

Write a program that takes as input an array of integers representing the durations in seconds of the songs in a concert, and returns the maximum number of seconds whose total duration approximates or equals a minimum of 50 minutes and a maximum of 60 minutes (including the additional minute between each song).

Input: An array of integers representing the durations in seconds of the songs in the concert.

Output: An integer representing the maximum number of songs that can be included in the concert, according to the criteria mentioned above.

Example:

1º Array with song durations: [240, 300, 180, 360, 120, 240, 300, 240, 180, 240]. Total duration: 49 minutes (Does not meet the minimum of 50 minutes)

2º Array with song durations: [420, 180, 360, 240, 120, 240, 300, 180]. Total duration: 59 minutes and 15 seconds (Meets the criteria)

3º Array with song durations: [300, 240, 480, 180, 240, 240, 300, 360]. Total duration: 57 minutes and 40 seconds (Meets the criteria)

Note:

  • The input array must not be null or empty.
  • The song durations must be positive integers.
  • The program must consider the additional minute between each song when calculating the total duration of the concert.

Good luck!

Code
Diff
  • public class HowManySongYouCanPlay {
    
    	public static String playSongs(Integer[] songDuration) {
    		return "";
    	}
    }
Code
Diff
  • class KumiteFoo:
        def __init__(self, p):
            self.p = p
            self.condition = ['No', 'Yes'][len(self.p) and not sum(map(ord, self.p.lower())) % 324]
    
        def solution(self):
            return self.condition
    • class KumiteFoo:
    • def __init__(self, p):
    • self.p = p
    • self.condition = 'Yes' if len(self.p) and not sum(map(ord, self.p.lower())) % 324 else 'No'
    • self.condition = ['No', 'Yes'][len(self.p) and not sum(map(ord, self.p.lower())) % 324]
    • def solution(self):
    • return self.condition
Code
Diff
  • class TemperatureConverter:
        def __init__(self, temp):
            self.temp = temp
            self._k1 = 5 / 9
            self._k2 = self._k1 * 32
            
        def fahrenheit_to_celsius(self):
            return round(self.temp * self._k1 - self._k2, 2)
        
        def celsius_to_fahrenheit(self):
            return round((self.temp + self._k2) / self._k1, 2)
    • class TemperatureConverter:
    • def __init__(self, temp):
    • self.temp = temp
    • self._k1 = 5 / 9
    • self._k2 = self._k1 * 32
    • def fahrenheit_to_celsius(self):
    • return round((self.temp - 32) * 5 / 9, 2)
    • return round(self.temp * self._k1 - self._k2, 2)
    • def celsius_to_fahrenheit(self):
    • return round((self.temp * 9 / 5) + 32, 2)
    • return round((self.temp + self._k2) / self._k1, 2)
Code
Diff
  • def flat_the_list(lst):
        def flatten(l):
            for i in l:
                if isinstance(i, (list, tuple)):
                    for j in flat_the_list(i):
                        yield j
                else:
                    yield i
        return list(flatten(lst))
    • def flat_the_list(item_list):
    • return [subitem for item in item_list for subitem in item]
    • def flat_the_list(lst):
    • def flatten(l):
    • for i in l:
    • if isinstance(i, (list, tuple)):
    • for j in flat_the_list(i):
    • yield j
    • else:
    • yield i
    • return list(flatten(lst))
Code
Diff
  • import java.util.regex.*;
    import java.util.Arrays;
    import java.util.Comparator;
    
    public class NamesAndNumbers{
      
      public static String run(int[]numbers, String[] names){
        
    		if(numbers == null || names == null) {
    			return "array is null";
    		} else if(numbers.length == 0 || names.length == 0) {
    			return "length is zero";
    		}
        
        Arrays.sort(names, Comparator.comparingInt(String::length));
    		Arrays.sort(numbers);
        
        StringBuilder cadenaValue = new StringBuilder();
        
        for(int i = 0; i<names.length; i++) {
    
    			cadenaValue.append(names[i]).append(":").append(numbers[i]).append(",");
    
    		}
        
        cadenaValue.deleteCharAt(cadenaValue.length() - 1);
    
    		String outputValue = cadenaValue.toString();
        
        return outputValue;
        
        
      }
      
    }//end class.
    • import java.util.regex.*;
    • import java.util.Arrays;
    • import java.util.Comparator;
    • public class NamesAndNumbers{
    • public static String run(int[]numbers, String[] names){
    • String outputValue = "error";
    • if(numbers == null || names == null) {
    • return "array is null";
    • } else if(numbers.length == 0 || names.length == 0) {
    • return "length is zero";
    • }
    • return outputValue;
    • Arrays.sort(names, Comparator.comparingInt(String::length));
    • Arrays.sort(numbers);
    • StringBuilder cadenaValue = new StringBuilder();
    • for(int i = 0; i<names.length; i++) {
    • cadenaValue.append(names[i]).append(":").append(numbers[i]).append(",");
    • }
    • cadenaValue.deleteCharAt(cadenaValue.length() - 1);
    • String outputValue = cadenaValue.toString();
    • return outputValue;
    • }
    • }//end class.
Strings
Code
Diff
  • public class ConfusedDouble {
      
    	public static String clearDouble(String str) {
    		if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
    			return ""; 
    		} 
    		String ret = str.replaceAll("[^0-9.]", "");
    		if(ret.length() == 1) return "";
    		return ret;
    	}
      
    }
    
    • //hacer que no funcione con una expresion regular con el caracter fin de cadena
    • public class ConfusedDouble {
    • public static String clearDouble(String str) {
    • public static String clearDouble(String str) {
    • if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
    • return "";
    • }
    • double num = Double.parseDouble(str.replaceAll("[^0-9.]", ""));
    • String result = Double.toString(num);
    • return result;
    • return "";
    • }
    • String ret = str.replaceAll("[^0-9.]", "");
    • if(ret.length() == 1) return "";
    • return ret;
    • }
    • }
Strings
Arrays

Replace Letter

Given a string and a number (n), generate an array in which each position will be that same string but modifying the letter of its first position (0) by the one in its n position.

Input:

hello, 2

Output:

[lello, hollo, hehlo, heleo, helll]

 Restrictions:

  • where n will always be a number between 0 and the length of the string.

  • It is case-insensitive and does not discriminate between letters, numbers, and special characters.

  • When current position + n is greater than the length of the string, it will return to start.

  • The spaces will be considered:

    • If there is a space, that position will not be replaced.
    • The space will not replace any letter.

For example

Given the string = "hello world" and n=1

Should return:

[eello world, Hlllo world, Hello world, Heloo world, Hello oorld, Hello wrrld, Hello wolld, Hello wordd, Hello worlH]

It would not admit:

hellowword

hell  word

Code
Diff
  • import java.text.ParseException;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Random;
    import java.util.concurrent.ThreadLocalRandom;
    
    public class Kata{
    public static String[] replaceLetter(String str, int n) {
    
    		ArrayList<String> arr = new ArrayList<>();
    		StringBuilder strFinal = new StringBuilder(str);
    
    		for (int i = 0; i < str.length(); i++) {
    			int nextIndex = (i + n) % str.length() ;
    
    			if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
    
    				nextIndex = (i + n) % str.length();
    				strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
    				arr.add(strFinal.toString());
    				strFinal.replace(0, str.length(), str);
    			}
    
    		}
    
    
    		return arr.toArray(new String[arr.size()]);
    
    	}
     }
    • import java.text.ParseException;
    • import java.util.ArrayList;
    • import java.util.Arrays;
    • import java.util.Random;
    • import java.util.concurrent.ThreadLocalRandom;
    • public class Kata{
    • public static String[] replaceLetter(String str, int n) {
    • ArrayList<String> arr = new ArrayList<>();
    • StringBuilder strFinal = new StringBuilder(str);
    • for (int i = 0; i < str.length(); i++) {
    • int nextIndex = (i + n) % str.length() ;
    • if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
    • nextIndex = (i + n) % str.length();
    • strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
    • arr.add(strFinal.toString());
    • strFinal.replace(0, str.length(), str);
    • }
    • }
    • String[] array = arr.toArray(new String[arr.size()]);
    • return array;
    • return arr.toArray(new String[arr.size()]);
    • }
    • }