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
const add = (a, b) => a + b + 1;

Ваша задача - написать тело функции которая будет вычислять формулы.

Формула передаётся через параметр forlmula. Формулы могут содержать в себе все значения, но также можно передать переменные вида $1, $2, $3 и т.д.
Значения переменных передаются вторым параметром в неограниченном кол-ве.

Посмотрите тесты что бы понять что от вас требуется.

Удачи! Она вам потребуется ;)

======

Your task is to write the body of a function that will calculate formulas.

The formula is passed through the forlmula parameter. Formulas can contain all values, but you can also pass variables like $1, $2, $3, etc.
Variable values are passed as the second parameter in an unlimited number.

Look at the tests to understand what is required of you.

Good luck! You will need it;)

using System;

public class Calculator
{
  public static float Calculate(string forlmula, params float[] values)
  {
    // your code
  }
}
module Kata where

add_ :: Int -> Int -> Int
add_ a b = a + b

I would love to see a generator which accepts [(Gen s, Int)] and uses a set of generators, generates n inputs from each of them, shuffles them, and uses the inputs to feed test cases.

For example, for "Is a number prime?" kata, I'd like to have a composite generator built like compositeGen([(genPrimes, 100), (genOddComposites, 100), (genNegativePrime, 10), (genSquareOfAPrime, 20)]) or something like this, and it would run test cases over 230 shuffled inputs.

Bonus points if such generator were able to generate not only Int, but also (Int, Bool) (input + expected answer) or even (Int, Bool, String) (input, expected answer, and assertion message).


The one thing I can't fix is that if it fails, it's always after 1 test. Because that's what it sees.

module Example (isPrime) where

isPrime :: Int -> Bool
isPrime = odd

give me two candy!

pekora(a,b)=> 'candy';
add(a)=> 'candy';

give me two candy

pekora(a,b)=> 'candy';
add(a)=> 'candy';
SouljaBoiFailed Tests

test

AWDawdawdawdawd

public class wdawd() {
  int dadaf = 1;
  
  
}
Algorithms
Logic
Search
Strings
Data Types

Write a function called findFirstSubString that accept two not null string(string and substring) and returns the index of the first occurrence of the substring in the string.

Examples

findFirstSubString("1234","12") => returns 0
findFirstSubString("012","12") => returns 1
findFirstSubString("4321","21") => returns 2
findFirstSubString("ABCDE","21") => returns null
findFirstSubString("","21") => returns null

Notes

  1. if no substring is found the function returns NULL
  2. the function returns only the index of the first occurrence of the string
fun findFirstSubString(string: String, subString: String): Int? {
    val stringArray = string.toList()
    val substringArray = subString.toList()

    if (stringArray.size < substringArray.size || stringArray.isEmpty() || substringArray.isEmpty()) {
        return null
    }

    var counter = 0
    var startIndex = 0

    var i = 0

    while (i < stringArray.size) {
        if (stringArray[i] == substringArray[counter]) {
            if(counter == 0) {
                startIndex = i
            }

            if ((counter + 1) == substringArray.size) {
                return startIndex
            }
            counter++
            i++
        }
        else {
            if (counter > 0) {
                i = startIndex + 1
            }
            else {
                i++
            }
            counter = 0
            startIndex = 0
        }

        println(i)
    }

    return null
}
Algorithms
Logic
Algebra
Mathematics

Summary

Given an integer number - let's call it N -, calculate the sum of the first positive integers up to N (inclusive) that are divisible by 3 or 7.

Example

Let's take N = 30:

Sum of integers divisible by 3 : 3 + 6 + 9 + 12 + 15 + 18 + 21 + 24 + 27 + 30 + 33 = 165 (#1)

Sum of integers divisible by 7 : 7 + 14 + 21 + 28 + 35 = 70 (#2)

Sum of integers divisible by 3 and 7 : 21 + 42 = 21 (#3)

Total : #1 + #2 - #3 = 165 + 70 - 21 = 214

Attention

Please be wary that N may be a large number (N larger than 1,000,000). This requires brushing up on optimization.

Caveat

There is one way of resolving this problem in O(1) complexity. For further details, please refer to this wiki.

using System;

namespace Kumite
{
  public class Problem
  {
    public static long Sum(int N)
    {
      // Add your code here.
      
      return 0;
    }
  }
}

Write a function that adds the digits of an integer. For example, the input receives a number: 10023. The result should be - 6 (1 + 0 + 0 + 2 + 3).

def digit_sum(number: int) -> int:
    return(sum([int(num) for num in str(abs(number))]))
from unittest import TestCase
from solution import digit_sum


import codewars_test as test
from solution import digit_sum

@test.describe('Tests')
def tests():

    @test.it('Test Cases')
    def test_sums():
        test.assert_equals(digit_sum(10000000000000000000000000000),1)
        test.assert_equals(digit_sum(55001),11)
        test.assert_equals(digit_sum(104),5)
        test.assert_equals(digit_sum(0),0)
        test.assert_equals(digit_sum(-1204),7)