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.

At this task you need to use destructuring to find cookie strings into object 'findAllCookies'.
console.log(cookie1); must show 'cookie1'
console.log(cookie2); must show 'cookie2'

For example:

let findAllCookies = {
  here: {
    that: ['cookie']
  }
}

let {here: {that: [cookie]}} = findAllCookies;

console.log(cookie); //cookie
let findAllCookies = {
  level1: {
    hello: ['not here',
      {
        almost: 'cookie1'
      }
    ]
  },

  level2: [
    {
      where : [
        {},
        {},
        {
          here: [
            [
              {
                itsNotCookie: 'caakie'
              },
              {
                second:
                {
                  isItCookie: 'cookie2'
                }
              }
            ]
          ]
        }
      ]
    },
  ],
};

let /* Put your code */ = findAllCookies;
let /* Put your code */ = findAllCookies;

console.log(cookie1);
console.log(cookie2);

very slight performance difference (sometimes)

Code
Diff
  • require 'benchmark'
    
    strings = []
    
    10000.times do
      string = Array.new(rand(500..1000)) do rand(10) end.join
      strings << string
    end
    
    def solution1(s) s.chars.sum(&:to_i) end
    def solution2(s) s.sum - s.size * 48 end
    def solution3(s) s.sum do |x| x - 48 end end
    def solution4(s) s.sum do |x| x - '0' end end
    def solution5(s) s.sum { |x| x - '0' } end
    def solution6(s) s.sum { |x| x - ?0 } end
    
    Benchmark.bmbm do |x|
      x.report do strings.each(&method(:solution1)) end # farekkusu
      x.report do strings.each(&method(:solution2)) end # ttakuru88
      x.report do strings.each(&method(:solution3)) end # steffan153 (test code author)
      x.report do strings.each(&method(:solution4)) end # rowcased
      x.report do strings.each(&method(:solution5)) end # pawptart
      x.report do strings.each(&method(:solution6)) end # steffan153
    end
    
    puts "<PASSED::>" # prevent from saying failed tests
  • 99
    1010 def solution1(s) s.chars.sum(&:to_i) end
    1111 def solution2(s) s.sum - s.size * 48 end
    1212 def solution3(s) s.sum do |x| x - 48 end end
    1313 def solution4(s) s.sum do |x| x - '0' end end
    1414 def solution5(s) s.sum { |x| x - '0' } end
    15+def solution6(s) s.sum { |x| x - ?0 } end
    1515
    1616 Benchmark.bmbm do |x|
    1717 x.report do strings.each(&method(:solution1)) end # farekkusu
    1818 x.report do strings.each(&method(:solution2)) end # ttakuru88
    1919 x.report do strings.each(&method(:solution3)) end # steffan153 (test code author)
    2020 x.report do strings.each(&method(:solution4)) end # rowcased
    2121 x.report do strings.each(&method(:solution5)) end # pawptart
    23+ x.report do strings.each(&method(:solution6)) end # steffan153
    2222 end
    2323
    2424 puts "<PASSED::>" # prevent from saying failed tests
anatollkoFailed Tests

Koliunua

console.log('hey hop')
Code
Diff
  • def rotateLeft(array):
        return [[x[-i-1] for x in array] for i in range(len(array[0]))]
    
    def rotateRight(array):
        return [[x[i] for x in array][::-1] for i in range(len(array[0]))]
  • 1-const rotateLeft = (arr) => {
    2- let retArr = [[],[],[]]
    3- for (let i = 0; i < arr.length; i++){
    4- for (let j = 0; j < arr[i].length; j++){
    5- retArr[i][j] = arr[j][arr.length - (i + 1)]
    6- }
    7- }
    8- return retArr
    9-}
    1+def rotateLeft(array):
    2+ return [[x[-i-1] for x in array] for i in range(len(array[0]))]
    1010
    11-const rotateRight = (arr) => {
    12- let retArr = [[],[],[]]
    13- for (let i = 0; i < arr.length; i++){
    14- for (let j = 0; j < arr[i].length; j++){
    15- retArr[i][j] = arr[arr.length - (j + 1)][i]
    16- }
    17- }
    18- return retArr
    19-}
    4+def rotateRight(array):
    5+ return [[x[i] for x in array][::-1] for i in range(len(array[0]))]
Code
Diff
  • (ns fibonacci)
    
    (defn get-fibonacci-number [index]
      (cond (< index 10) (nth '(0 1 1 2 3 5 8 13 21 34) index 0)
            (odd? index) (let [k   (quot index 2)
                               fk  (get-fibonacci-number k)
                               fk1 (get-fibonacci-number (inc k))]
                           (+' (*' fk fk) (*' fk1 fk1))
                         )
            :else        (let [k   (quot index 2)
                               fk  (get-fibonacci-number k)
                               fk1 (get-fibonacci-number (inc k))]
                           (*' fk (-' (*' 2 fk1) fk))
                         )
      )
    )
  • 11 (ns fibonacci)
    22
    33 (defn get-fibonacci-number [index]
    4- "Finds fibonacci number by given index using iteration"
    5- (loop [x 0 y 1 z index]
    6- (if (< z 1) x (recur y (+ x y) (dec z)))))
    4+ (cond (< index 10) (nth '(0 1 1 2 3 5 8 13 21 34) index 0)
    5+ (odd? index) (let [k (quot index 2)
    6+ fk (get-fibonacci-number k)
    7+ fk1 (get-fibonacci-number (inc k))]
    8+ (+' (*' fk fk) (*' fk1 fk1))
    9+ )
    10+ :else (let [k (quot index 2)
    11+ fk (get-fibonacci-number k)
    12+ fk1 (get-fibonacci-number (inc k))]
    13+ (*' fk (-' (*' 2 fk1) fk))
    14+ )
    15+ )
    16+)

This translation assumes that the first day of each month is a Sunday.

Code
Diff
  • def day_finder(day, month, year):
        week = ["Sunday", "Monday",  "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
        dates = {"Jan":[31, 0], "Feb":[28, 31], "Mar":[31, 59], "Apr":[30, 90],
        "May":[31, 120], "Jun":[30, 151], "Jul":[31, 181], "Aug":[31, 212],
        "Sep":[30, 243], "Oct":[31, 273], "Nov":[30, 304], "Dec":[31, 334]}
        full_months = {"Jan":"January", "Feb":"February", "Mar":"March", "Apr":"April",
        "May":"May", "Jun":"June", "Jul":"July", "Aug":"August", "Sep":"September", 
        "Oct":"October", "Nov":"November", "Dec":"December"}
        def week_day(num):
            inc = -1
            for x in range(num):
                inc += 1
                if inc == 7:
                    inc = 0
            return week[inc]
        if month not in dates:
            return "Invalid Date"
        if [year % x for x in [4, 100, 40]] == [0, 0, 0]:
            dates["Feb"][0] = 29
            for x in dates:
                if x != "Jan":
                    dates[x][1] += 1
        if month in dates:
            if day >= 1 and day <= dates[month][0]:
                total_day = dates[month][1] + day
                day_type = week_day(day)
                total_mark = None
                mark = None
                if str(day).endswith("1") and str(day) != "11":
                    mark = "st"
                elif str(day).endswith("2") and str(day) != "12":
                    mark = "nd"
                elif str(day).endswith("3") and str(day) != "13":
                    mark = "rd"
                else:
                    mark = "th"
                if str(total_day).endswith("1") and str(day) != "11":
                    total_mark = "st"
                elif str(total_day).endswith("2") and str(day) != "12":
                    total_mark = "nd"
                elif str(total_day).endswith("3") and str(day) != "13":
                    total_mark = "rd"
                else:
                    total_mark = "th"
                return f"The {day}{mark} of {full_months[month]} is a {day_type} and the {total_day}{total_mark} day of {year}."
        return "Invalid Date"
  • 1-import java.io.*;
    2-class Date
    3-{
    4-
    5-public static void main()throws IOException
    6-{
    7-
    8-BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
    9-
    10-System.out.print("Enter the Date:(DD MM YYYY): ");
    11-String k=in.readLine();
    12-
    13-int d=Integer.parseInt(k.substring(0,2)), c,m=Integer.parseInt(k.substring(3,5)), y=Integer.parseInt(k.substring(6)), i, a1[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    14-String a2[]={"Sunday","Monday","Tuesday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    15-
    16-if((y%4==0 && y%100!=0)||y%400==0)
    17-a1[2]=29;
    18-
    19-if(m<1 || m>12 || d<1 || d>a1[m])
    20-System.out.println("Invalid Date..............");
    21-else
    22-{
    23-System.out.println("Valid Date.............");
    24-
    25-for(i=1;i<m;i++)
    26-d+=a1[i];
    27-
    28-c=d;
    29-
    30-for(i=1;i<y;i++)
    31-if((i%4==0 && i%100!=0)||i%400==0)
    32-d+=366;
    33-else
    34-d+=365;
    35-
    36-System.out.println("The day value is: "+c+" days and thr day is "+a2[d%7]);
    37-}
    38-}
    39-}
    1+def day_finder(day, month, year):
    2+ week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    3+ dates = {"Jan":[31, 0], "Feb":[28, 31], "Mar":[31, 59], "Apr":[30, 90],
    4+ "May":[31, 120], "Jun":[30, 151], "Jul":[31, 181], "Aug":[31, 212],
    5+ "Sep":[30, 243], "Oct":[31, 273], "Nov":[30, 304], "Dec":[31, 334]}
    6+ full_months = {"Jan":"January", "Feb":"February", "Mar":"March", "Apr":"April",
    7+ "May":"May", "Jun":"June", "Jul":"July", "Aug":"August", "Sep":"September",
    8+ "Oct":"October", "Nov":"November", "Dec":"December"}
    9+ def week_day(num):
    10+ inc = -1
    11+ for x in range(num):
    12+ inc += 1
    13+ if inc == 7:
    14+ inc = 0
    15+ return week[inc]
    16+ if month not in dates:
    17+ return "Invalid Date"
    18+ if [year % x for x in [4, 100, 40]] == [0, 0, 0]:
    19+ dates["Feb"][0] = 29
    20+ for x in dates:
    21+ if x != "Jan":
    22+ dates[x][1] += 1
    23+ if month in dates:
    24+ if day >= 1 and day <= dates[month][0]:
    25+ total_day = dates[month][1] + day
    26+ day_type = week_day(day)
    27+ total_mark = None
    28+ mark = None
    29+ if str(day).endswith("1") and str(day) != "11":
    30+ mark = "st"
    31+ elif str(day).endswith("2") and str(day) != "12":
    32+ mark = "nd"
    33+ elif str(day).endswith("3") and str(day) != "13":
    34+ mark = "rd"
    35+ else:
    36+ mark = "th"
    37+ if str(total_day).endswith("1") and str(day) != "11":
    38+ total_mark = "st"
    39+ elif str(total_day).endswith("2") and str(day) != "12":
    40+ total_mark = "nd"
    41+ elif str(total_day).endswith("3") and str(day) != "13":
    42+ total_mark = "rd"
    43+ else:
    44+ total_mark = "th"
    45+ return f"The {day}{mark} of {full_months[month]} is a {day_type} and the {total_day}{total_mark} day of {year}."
    46+ return "Invalid Date"
Code
Diff
  • (ns fizzbuzz.core)
    
    (defn fizz [_] "Fizz")
    
    (defn buzz [_] "Buzz")
    
    (defn fizz-buzz [_] "FizzBuzz")
    
    (defn self [x] x)
    
    (defn fizzbuzz [x]
      (map (comp eval list) 
        (cycle (list self self fizz self buzz fizz self self fizz buzz self fizz self self fizz-buzz)) 
        (range 1 (inc x))
      )
    )
    
  • 11 (ns fizzbuzz.core)
    22
    3-(defn divisible-by? [divisor number]
    4- (zero? (mod number divisor)))
    5-
    3+(defn fizz [_] "Fizz")
    4+
    5+(defn buzz [_] "Buzz")
    6+
    7+(defn fizz-buzz [_] "FizzBuzz")
    8+
    9+(defn self [x] x)
    10+
    66 (defn fizzbuzz [x]
    7- (map #(cond
    8- (divisible-by? 15 %) "FizzBuzz"
    9- (divisible-by? 5 %) "Buzz"
    10- (divisible-by? 3 %) "Fizz"
    11- :else %)
    12- (range 1 (inc x))))
    13-
    12+ (map (comp eval list)
    13+ (cycle (list self self fizz self buzz fizz self self fizz buzz self fizz self self fizz-buzz))
    14+ (range 1 (inc x))
    15+ )
    16+)
Code
Diff
  • function objectFreeze(a) {
      Object.getOwnPropertySymbols(a).concat(Object.getOwnPropertyNames(a)).forEach(key => {
        Object.defineProperty(a, key, {configurable: false, writable: false, value: a[key]})
      })
      return a
    }
  • 1-// TODO: Create method objectFreeze which works the same as native Object.freeze.
    2-// !IMPORTANT: You haven't use Object.freeze during your task
    3-
    4-function objectFreeze(obj) {
    5- return Object.freeze(obj);
    1+function objectFreeze(a) {
    2+ Object.getOwnPropertySymbols(a).concat(Object.getOwnPropertyNames(a)).forEach(key => {
    3+ Object.defineProperty(a, key, {configurable: false, writable: false, value: a[key]})
    4+ })
    5+ return a
    66 }