Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

Algorithms
Mathematics
Numbers

I want to show you task from Russian EGE exam

Given an array containing positive integers that do not exceed 15000. Find the number of even elements in the array that are not multiples of 3, replace all odd elements that are multiples of 3 with this number, and output the modified array. For example, for a source array of five elements 20, 89, 27, 92, 48, the program must output numbers 20, 89, 2, 92, 48.

using System;
 public class RussianExam
  {
    public static int[] ExamTask(int[] array)
        {
            int count = 0;
            for(int i = 0; i < array.Length; i++)
            {
                if (array[i] % 3 != 0 && array[i] % 2 == 0) count++;
            }
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] % 3 == 0 && array[i] % 2 != 0) array[i] = count;
            }
            return array;
        }
  }
Fundamentals
Numbers
Mathematics
Algorithms
Code
Diff
  • def temperature_convert(temperature):
        
        if temperature[1] == temperature[2]:
            return temperature[0]
        
        converter = {'ck': '{} + 273.15',
                     'cr': '({} * 1.8) + 491.67',
                     'cf': '({} * 1.8) + 32',
                     'rc': '({} - 491.67) * (5/9)',
                     'rk': '{} * (5/9)',
                     'rf': '{} - 459.67',
                     'kc': '{} - 273.15',
                     'kr': '{} * 1.8',
                     'kf': '(({} - 273.15) * 1.8) + 32',
                     'fc': '({} - 32) * (5/9)',
                     'fk': '(({} - 32) * (5/9)) + 273.15',
                     'fr': '{} + 459.67'}
        
        value = temperature[0]
        formula = converter[str(temperature[1] + temperature[2])]
        
        return int(eval(formula.format(value)))
  • 1
    # Fastest way is to convert everything to celsius and then convert to final temperature
    
    2
    import math
    
    33
    def temperature_convert(temperature):
    
    4
        z = 0
    
    5
        # list of if clauses to figure out steps based on 2nd value of list
    
    6
        if temperature[1] == 'r':
    
    7
            z = (temperature[0] - 491.67) * 5 / 9
    
    8
        elif temperature[1] == 'f':
    
    2+
        
    
    3+
        if temperature[1] == temperature[2]:
    
    4+
            return temperature[0]
    
    5+
        
    
    6+
        converter = {'ck': '{} + 273.15',
    
    7+
                     'cr': '({} * 1.8) + 491.67',
    
    8+
                     'cf': '({} * 1.8) + 32',
    

Recent Moves:

Algorithms
Fundamentals

Save 1 byte on the boolean logic. Expected to save more, but oh well... !a&&!b&&!c ==> !(a||b||c)

Combine two isNaNs together.

Why do we need dash between 333 444 555 etc.?

Save on long method names

Code
Diff
  • validateKey=(k,s=k.split('-'))=>k[l='length']+s[0][l]==14&&!(isNaN(s[0]+s[1])||'333444555666777888999'[i='includes'](s[0])||s[1]%7!=0||'089'[i](k[k[l]-1]))
  • 1
    validateKey=(k,s=k.split('-'))=>k.length+s[0].length==14&&!isNaN(s[0])&&!isNaN(s[1])&&!'333-444-555-666-777-888-999'.includes(s[0])&&s[1]%7==0&&!'089'.includes(k.slice(-1))
    
    1+
    validateKey=(k,s=k.split('-'))=>k[l='length']+s[0][l]==14&&!(isNaN(s[0]+s[1])||'333444555666777888999'[i='includes'](s[0])||s[1]%7!=0||'089'[i](k[k[l]-1]))
    

Recent Moves:

Performance
Puzzles
Games
Fundamentals

6 chars saved ( without removing "const " )

Code
Diff
  • f=lambda x:sum(map(sum,x))
  • 1
    f=lambda x:sum(sum(y)for y in x)
    
    1+
    f=lambda x:sum(map(sum,x))
    

Recent Moves:

Code
Diff
  • package orderedcount
    
    // Use the preloaded Tuple struct as return type
    // type Tuple struct {
    //	Char  rune
    //	Count int
    // }
    
    func OrderedCount(text string) []Tuple {
      tuples := make([]Tuple, 0)
     for _, c := range text {
         exists := false
         for _, t := range tuples {
           if(t.Char == rune(c)) {
             exists = true
           }
         }
         if (!exists) {
           tuples = append(tuples, Tuple{rune(c), 0})
         }
     }
     for _, c := range text {
         for i := range tuples {
           if(tuples[i].Char == rune(c)) {
             tuples[i].Count++
           }
         }
     }
     return tuples
    }
  • 11
    package orderedcount
    
    22
    33
    // Use the preloaded Tuple struct as return type
    
    44
    // type Tuple struct {
    
    55
    //	Char  rune
    
    66
    //	Count int
    
    77
    // }
    
    88
    99
    func OrderedCount(text string) []Tuple {
    
    10
     // to implement
    
    10+
      tuples := make([]Tuple, 0)
    
    11+
     for _, c := range text {
    
    12+
         exists := false
    
    13+
         for _, t := range tuples {
    
    14+
           if(t.Char == rune(c)) {
    
    15+
             exists = true
    
    16+
           }
    
    17+
         }
    
    18+
         if (!exists) {
    
    19+
           tuples = append(tuples, Tuple{rune(c), 0})
    
    20+
         }
    
    21+
     }
    
    22+
     for _, c := range text {
    
    23+
         for i := range tuples {
    
    24+
           if(tuples[i].Char == rune(c)) {
    
    25+
             tuples[i].Count++
    
    26+
           }
    
    27+
         }
    
    28+
     }
    
    29+
     return tuples
    
    1111
    }
    

Recent Moves: