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 a class named Student which takes arguments:first_name, last_name, grade, avg_marks(average marks).
and can return: first_name, full_name, grade,and be able to assess perfomance by using avg_marks.
grading scheme:
0-25:B-
26-50:B+
51-75:A-
76-100:A+

class Student:
    def __init__(self, first_name, last_name, grade, avg_marks):
        self.first_name=first_name
        self.full_name=first_name+" "+last_name
        self.grade=grade
        self.avg_marks=avg_marks
    
    def assess(self):
        if 0<=self.avg_marks<=25:
            return "B-"
        if 26<=self.avg_marks<=50:
            return "B+"
        if 51<=self.avg_marks<=75:
            return "A-"
        if 76<=self.avg_marks<=100:
            return "A+"
import codewars_test as test
# TODO Write tests
import solution # or from solution import example

# test.assert_equals(actual, expected, [optional] message)
@test.describe("Student")
def test_group():
    j=Student('John','McCandy',10,50)
    k=Student('Karen','Gomez',2,95)
    
    @test.it("First Name")
    def fi_test():
        test.assert_equals(j.first_name, 'John')
        test.assert_equals(k.first_name,'Karen')
    @test.it('Full Name')
    def fu_test():
        test.assert_equals(j.full_name,'John McCandy')
        test.assert_equals(k.full_name,'Karen Gomez')
    @test.it("Grade")
    def cl_test():
        test.assert_equals(j.grade,10)
        test.assert_equals(k.grade,2)
    @test.it(" Assess Average Marks")
    def av_test():
        test.assert_equals(j.assess(),'B+')
        test.assert_equals(k.assess(),'A+')
def is_num(num):
    return type(num) in (int,float)
#     return type(num).__name__=="int" or type(num).__name__=="float"

def used_num(num):
    return isinstance(num,(int,float))
#     return isinstance(num,int) or isinstance(num,float)
from math import floor
def how_many_bucks(buy,sold,tax):
    return max(1,floor(sold-(tax/100)))-buy

:)

def count_arr(arr):
    mn=min(arr)
    mx=max(arr)
    d={}
    for _ in range(mn,mx+1):
        d[_]=0
    for val in arr:
        d[val]+=1
    acc=[]
    for num in range(mn,mx+1):
        for _ in range(d[num]):
            acc.append(num)
    return acc

works for empty array too

#returns the index of val if val is in the array, else -1 if val is not in the array.
#precondition: arr must be sorted in ascending order
def binary_search(arr,val):
    i=-1
    j=len(arr)
    while i+1!=j:
        m=i+(j-i)//2
        if arr[m]<val:
            i=m
        elif arr[m]>val:
            j=m
        else:
            return m
    return -1
class Solution{
  public static int linear_search(int[] arr,int val){
    int i=0;
    while (i<arr.length){
      if (arr[i]==val){
        return i;
      }
      i++;
    }
    return -1;
  }
  
}

beHOLD! a recursive selection sort! will take tons of extra time and space for no good reason (seriously do not fork this,it is bad practice on all levels)

i should probably try to make this tail recursive lol

def isMin(val,arr):
    match arr:
        case []:
            return True
        case _:
            return val<=arr[0] and isMin(val,arr[1:])

def findMin(i,arr):
    match isMin(arr[i],arr):
        case True:
            return arr[i]
        case _:
            return findMin(i+1,arr)    
    
def remove(target,arr):
    match arr:
        case []:
            return []
        case _:
            return arr[1:] if target==arr[0] else [arr[0]]+remove(target,arr[1:])
            
def select(arr):
    match arr:
        case []:
            return []
        case _:
            m=findMin(0,arr)
            arr=remove(m,arr)
            return [m]+select(arr)

Given an array of random numbers. Return the number of even numbers in the array.

function calculateEvenNumbers(array $numbers): int {
  $result = [];
  
  foreach ($numbers as $number) {
    if ($number % 2 === 0) {
      $result[] = $number;
    }
  }
    
  return count($result);
}
def counter():
    n=-1
    def closure():
        nonlocal n
        print(n)
        n+=1
    return closure

Format in value value with fixed decimal places numberOfPlaces if it is a number, if it's not - return input as is.

function formatIfNumber(value, numberOfPlaces) {
  return "";
}