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.

Okay.

Code
Diff
  • const yearlyElectricCosts = () => {
      // Create 11 more variables with the correct values
      let januaryBill = 43.11
      let februaryBill = 50.21
      let marchBill = 48.92
      let aprilBill = 62.36
      let mayBill = 54.64
      let juneBill = 49.30
      let julyBill = 61.93
      let augustBill = 68.54
      let septemberBill = 71.77
      let octoberBill = 70.28
      let novemberBill = 59.56
      let decemberBill = 62.04
    
      // Decide on a variable name and add all the monthly charges
      const totalCharges = januaryBill + februaryBill + marchBill + aprilBill + mayBill + juneBill + julyBill + augustBill + septemberBill + octoberBill + novemberBill + decemberBill
      
      // Return the value of the variable by typing it in after the `return` keyword below
      return +totalCharges.toFixed(2)
    }
  • 11
    const yearlyElectricCosts = () => {
    
    22
      // Create 11 more variables with the correct values
    
    33
      let januaryBill = 43.11
    
    4
      
    
    4+
      let februaryBill = 50.21
    
    5+
      let marchBill = 48.92
    
    6+
      let aprilBill = 62.36
    
    7+
      let mayBill = 54.64
    
    8+
      let juneBill = 49.30
    
    9+
      let julyBill = 61.93
    
    10+
      let augustBill = 68.54
    
    11+
      let septemberBill = 71.77
    
    12+
      let octoberBill = 70.28
    
    13+
      let novemberBill = 59.56
    
    14+
      let decemberBill = 62.04
    
    15+
    55
      // Decide on a variable name and add all the monthly charges
    
    6
      const
    
    17+
      const totalCharges = januaryBill + februaryBill + marchBill + aprilBill + mayBill + juneBill + julyBill + augustBill + septemberBill + octoberBill + novemberBill + decemberBill
    
    77
      
    
    88
      // Return the value of the variable by typing it in after the `return` keyword below
    
    9
      return 
    
    20+
      return +totalCharges.toFixed(2)
    
    1010
    }
    
Fundamentals
Numbers
Integers

Almost.

Code
Diff
  • public static class Kata
    {
        /// <summary>
        /// Validates if the given <paramref name="input"/> is an odd number
        /// </summary>
        /// <param name="input">Number to validate</param>
        /// <returns>True if the <paramref name="input"/> is an odd number</returns>
        public static bool IsOdd(this int input)
            => !(new System.Numerics.BigInteger(input)).IsEven;
    }
  • 11
    public static class Kata
    
    22
    {
    
    33
        /// <summary>
    
    44
        /// Validates if the given <paramref name="input"/> is an odd number
    
    55
        /// </summary>
    
    66
        /// <param name="input">Number to validate</param>
    
    77
        /// <returns>True if the <paramref name="input"/> is an odd number</returns>
    
    88
        public static bool IsOdd(this int input)
    
    9
            => (input & 1) == 1;
    
    9+
            => !(new System.Numerics.BigInteger(input)).IsEven;
    
    1010
    }
    

Recent Moves:

Fundamentals
Loops
Control Flow
Basic Language Features

What I feel is an interesting way to sort in Python.
Please don't fork this with assigning different letters to sorted, thank you for your cooperation.

Code
Diff
  • import heapq
    
    def sort_arr(arr):
        heapq.heapify(arr)
        return heapq.nsmallest(len(arr), arr)
    
  • 1+
    import heapq
    
    2+
    11
    def sort_arr(arr):
    
    2
        old_arr, new_arr, test = arr, [], 0
    
    3
        while len(old_arr) > 0:
    
    4
            for i in range(len(arr)):
    
    5
                test = i if old_arr[i] < old_arr[test] else test
    
    6
            new_arr.append(old_arr[test])
    
    7
            old_arr.pop(test)
    
    8
            test = 0
    
    9
        return new_arr
    
    4+
        heapq.heapify(arr)
    
    5+
        return heapq.nsmallest(len(arr), arr)
    
Lists
Data Structures

Break lists of lists into a simple list.

(flatten)

Code
Diff
  • def list_in_lists_while(input_list):
        while (all(isinstance(x, list) for x in input_list)):
            new_list = []
            for sublist in input_list:
                for i in sublist:
                    new_list.append(i)
            input_list = new_list
        return input_list
    
    from numpy import concatenate as con
    list_in_lists_numpy = lambda input_list: [*con(input_list).flat]
  • 1
    my_list = [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]
    
    2
    while (all(isinstance(x, list) for x in my_list)):
    
    3
        new_list = []
    
    4
        for sublist in my_list:
    
    5
            for i in sublist:
    
    6
                new_list.append(i)
    
    7
        my_list = new_list
    
    8
    print(my_list)
    
    1+
    def list_in_lists_while(input_list):
    
    2+
        while (all(isinstance(x, list) for x in input_list)):
    
    3+
            new_list = []
    
    4+
            for sublist in input_list:
    
    5+
                for i in sublist:
    
    6+
                    new_list.append(i)
    
    7+
            input_list = new_list
    
    8+
        return input_list
    
    9+
    10+
    from numpy import concatenate as con
    
    11+
    list_in_lists_numpy = lambda input_list: [*con(input_list).flat]
    

Recent Moves:

Fundamentals
Numbers
Mathematics
Algorithms

'a' and 'b' aren't great names IMHO.

Code
Diff
  • _UNIT_SCALE_FROM_KELVIN = {
        "c": 1,
        "k": 1,
        "f": 1.8,
        "r": 1.8
    }
    _ABSOLUTE_ZERO = {
        "c": -273.15,
        "k": 0,
        "f": -459.67,
        "r": 0
    }
    
    def temperature_convert(temp, source, target):
        temp -= _ABSOLUTE_ZERO[source]
        temp /= _UNIT_SCALE_FROM_KELVIN[source]
        temp *= _UNIT_SCALE_FROM_KELVIN[target]
        temp += _ABSOLUTE_ZERO[target]
        return int(temp)
  • 1
    from collections import namedtuple 
    
    1+
    _UNIT_SCALE_FROM_KELVIN = {
    
    2+
        "c": 1,
    
    3+
        "k": 1,
    
    4+
        "f": 1.8,
    
    5+
        "r": 1.8
    
    6+
    }
    
    7+
    _ABSOLUTE_ZERO = {
    
    8+
        "c": -273.15,
    
    9+
        "k": 0,
    
    10+
        "f": -459.67,
    
    11+
        "r": 0
    
    12+
    }
    
    22
    33
    def temperature_convert(temp, source, target):
    
    4
        # the affine transformations of the form "y = a*x + b"
    
    5
        # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F)
    
    6
        Pair = namedtuple('Pair', ['a','b'])
    
    7
        convert = {
    
    8
            "c": Pair(1.0, -273.15),
    
    9
            "r": Pair(1.8,    0.0 ),
    
    10
            "f": Pair(1.8, -459.67),
    
    11
            "k": Pair(1.0,    0.0 ),
    
    12
        }
    
    13
        # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a
    
    14
        temp = (temp - convert[source].b) / convert[source].a
    
    15
        # convert Kelvins to target unit, rounded to integer
    
    16
        return int(temp * convert[target].a + convert[target].b)
    
    15+
        temp -= _ABSOLUTE_ZERO[source]
    
    16+
        temp /= _UNIT_SCALE_FROM_KELVIN[source]
    
    17+
        temp *= _UNIT_SCALE_FROM_KELVIN[target]
    
    18+
        temp += _ABSOLUTE_ZERO[target]
    
    19+
        return int(temp)
    

Recent Moves: