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.
Write a function that returns the fibonacci sequence starting at 1, and ending at the first number greater than n inclusive, with the sum of the sequence as a tuple. Assume all inputs are positive integers.
def fibthing(make=int): fibseq = [] while max(fibseq, default=0) < make: if len(fibseq) > 1: fibseq.append(fibseq[-1] + fibseq[-2]) else: fibseq.append(1) return fibseq, sum(fibseq)
- def fibthing(make=int):
- fibseq = []
n1 = 0n2 = 1cur = 0sum = 0while cur < make:fibseq.append(n2)cur = n2n2 = n1 + curn1 = curfor i in fibseq:sum += ireturn fibseq, sum- while max(fibseq, default=0) < make:
- if len(fibseq) > 1:
- fibseq.append(fibseq[-1] + fibseq[-2])
- else:
- fibseq.append(1)
- return fibseq, sum(fibseq)
import codewars_test as test from solution import fibthing import random def myfib(n): seq = [] while max(seq, default=0) < n: if len(seq) > 1: seq.append(seq[-1] + seq[-2]) else: seq.append(1) return seq, sum(seq) @test.describe("Base") def test_group(): @test.it("Base Cases") def test_case(): test.assert_equals(fibthing(199218), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811], 832039)) test.assert_equals(fibthing(199), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233], 609)) test.assert_equals(fibthing(55), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55], 143)) @test.it("Edge Cases") def edge_case(): test.assert_equals(fibthing(1), ([1], 1)) test.assert_equals(fibthing(2), ([1, 1, 2], 4)) @test.describe("Random") def random_group(): for _ in range(100): num = random.randrange(0, 1000000) @test.it(str(num)) def test_random(): test.assert_equals(fibthing(num), myfib(num))
- import codewars_test as test
# TODO Write testsfrom solution import fibthing# or from solution import example- from solution import fibthing
- import random
- def myfib(n):
- seq = []
- while max(seq, default=0) < n:
- if len(seq) > 1: seq.append(seq[-1] + seq[-2])
- else: seq.append(1)
- return seq, sum(seq)
# test.assert_equals(actual, expected, [optional] message)- @test.describe("Base")
- def test_group():
- @test.it("Base Cases")
- def test_case():
- test.assert_equals(fibthing(199218), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811], 832039))
- test.assert_equals(fibthing(199), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233], 609))
test.assert_equals(fibthing(55), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55], 143))- test.assert_equals(fibthing(55), ([1, 1, 2, 3, 5, 8, 13, 21, 34, 55], 143))
- @test.it("Edge Cases")
- def edge_case():
- test.assert_equals(fibthing(1), ([1], 1))
- test.assert_equals(fibthing(2), ([1, 1, 2], 4))
- @test.describe("Random")
- def random_group():
- for _ in range(100):
- num = random.randrange(0, 1000000)
- @test.it(str(num))
- def test_random():
- test.assert_equals(fibthing(num), myfib(num))
Goal: You have to print the string n times if a is True.
(added some tests, and a working function for the previous task you described. Not exactly sure what the goal is, so I just had it return the string + newline for n lines.)
def print_n(string, n, a): if isinstance(a, bool) and a is True: for _ in range(n): print(string) return '\n'.join([string for _ in range(n)]) return None
a = Trueif a == True:print("hi")- def print_n(string, n, a):
- if isinstance(a, bool) and a is True:
- for _ in range(n): print(string)
- return '\n'.join([string for _ in range(n)])
- return None
import codewars_test as test from solution import print_n import random # Working solution def my_print(string, n, a): if isinstance(a, bool) and a is True: return '\n'.join([string for _ in range(n)]) return None # Random greetings + random number + random true or false def get_random(): words = [ 'Hello', 'Hi', 'Hey', 'Greetings', 'Salutations', 'Howdy', 'Aloha', 'Hola', 'Bonjour', 'Ciao', 'Namaste', 'Salaam', 'Shalom', 'Konnichiwa', 'Ahoy', 'Sup', 'Yo', 'Good morning', 'Good afternoon', 'Good evening', 'Welcome', "How's it going?", "What's up?", 'How are you?', 'Nice to meet you', 'Pleasure to meet you', "How's everything?", 'Long time no see', 'Hey there, stranger', "What's the good word?", 'How have you been?', "How's your day?", 'Top of the morning to you', "How's life treating you?", "How's your day going?", "What's new?", "How's your week been?", "How's your family?", "It's been a while", 'Hey, buddy', "How's the weather?", "How's your health?", "How's your job?", "How's your weekend?", "How's your vacation?", "How's your trip?", "How's your project?", "How's your study?", "How's your hobby?", "How's your game?" ] selection = random.choice(words) num = random.randrange(0, 50) truth = random.randrange(10000, 100000) % 2 == 0 return (selection, num, truth) @test.describe("Example Tests") def test_group(): @test.it("Test with A = True") def test_true(): test.assert_equals(print_n('Hello', 1, True), 'Hello') test.assert_equals(print_n('.', 3, True), '.\n.\n.') test.assert_equals(print_n('hi', 9, True), 'hi\nhi\nhi\nhi\nhi\nhi\nhi\nhi\nhi') test.assert_equals(print_n('Nothing', 0, True), '') @test.it("Test with A = False") def test_false(): test.assert_equals(print_n('Hello', 1, False), None) test.assert_equals(print_n('.', 3, 0), None) test.assert_equals(print_n('hi', 9, 'True'), None) @test.describe('Random Tests') def test_random(): for _ in range(50): s, n, a = get_random() @test.it(f'String: {s} | Num: {n} | A: {a}') def test_rand(): test.assert_equals(print_n(s,n,a), my_print(s,n,a))
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import print_n
- import random
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")- # Working solution
- def my_print(string, n, a):
- if isinstance(a, bool) and a is True:
- return '\n'.join([string for _ in range(n)])
- return None
- # Random greetings + random number + random true or false
- def get_random():
- words = [
- 'Hello', 'Hi', 'Hey', 'Greetings', 'Salutations', 'Howdy', 'Aloha', 'Hola', 'Bonjour',
- 'Ciao', 'Namaste', 'Salaam', 'Shalom', 'Konnichiwa', 'Ahoy', 'Sup', 'Yo', 'Good morning',
- 'Good afternoon', 'Good evening', 'Welcome', "How's it going?", "What's up?", 'How are you?',
- 'Nice to meet you', 'Pleasure to meet you', "How's everything?", 'Long time no see',
- 'Hey there, stranger', "What's the good word?", 'How have you been?', "How's your day?",
- 'Top of the morning to you', "How's life treating you?", "How's your day going?", "What's new?",
- "How's your week been?", "How's your family?", "It's been a while", 'Hey, buddy', "How's the weather?",
- "How's your health?", "How's your job?", "How's your weekend?", "How's your vacation?", "How's your trip?",
- "How's your project?", "How's your study?", "How's your hobby?", "How's your game?"
- ]
- selection = random.choice(words)
- num = random.randrange(0, 50)
- truth = random.randrange(10000, 100000) % 2 == 0
- return (selection, num, truth)
- @test.describe("Example Tests")
- def test_group():
@test.it("test case")def test_case():test.assert_equals(1 + 1, 2)- @test.it("Test with A = True")
- def test_true():
- test.assert_equals(print_n('Hello', 1, True), 'Hello')
- test.assert_equals(print_n('.', 3, True), '.\n.\n.')
- test.assert_equals(print_n('hi', 9, True), 'hi\nhi\nhi\nhi\nhi\nhi\nhi\nhi\nhi')
- test.assert_equals(print_n('Nothing', 0, True), '')
- @test.it("Test with A = False")
- def test_false():
- test.assert_equals(print_n('Hello', 1, False), None)
- test.assert_equals(print_n('.', 3, 0), None)
- test.assert_equals(print_n('hi', 9, 'True'), None)
- @test.describe('Random Tests')
- def test_random():
- for _ in range(50):
- s, n, a = get_random()
- @test.it(f'String: {s} | Num: {n} | A: {a}')
- def test_rand():
- test.assert_equals(print_n(s,n,a), my_print(s,n,a))
module Magick where magick True = "abacradabra!" magick False = "codewarz"
const magick_message = x => ['codewarz', 'abracadabra!'][+x];- module Magick where
- magick True = "abacradabra!"
- magick False = "codewarz"
module MagickSpec where import Test.Hspec import Magick spec :: Spec spec = do it "simple case" $ do magick True `shouldBe` "abacradabra!" magick False `shouldBe` "codewarz" main = hspec spec
const Test = require('@codewars/test-compat');- module MagickSpec where
describe('Example', function() {it('test case', function() {Test.assertEquals(magick_message(true), 'abracadabra!')Test.assertEquals(magick_message(false), 'codewarz')});});- import Test.Hspec
- import Magick
- spec :: Spec
- spec = do
- it "simple case" $ do
- magick True `shouldBe` "abacradabra!"
- magick False `shouldBe` "codewarz"
- main = hspec spec
def sumi(arr): total = 0 for value in arr: total += value return total
def sumi(arr=[0]):total = [n for n in arr]return sum(total)- def sumi(arr):
- total = 0
- for value in arr:
- total += value
- return total
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(sumi([1, 2, 3, 4, 5]), 15) test.assert_equals(sumi([1, 1, 1, 1, 1]), 5) test.assert_equals(sumi([0]), 0) test.assert_equals(sumi([1]), 1) test.assert_equals(sumi([34, 45, 56]), 135)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(1 + 1, 2)- test.assert_equals(sumi([1, 2, 3, 4, 5]), 15)
- test.assert_equals(sumi([1, 1, 1, 1, 1]), 5)
- test.assert_equals(sumi([0]), 0)
- test.assert_equals(sumi([1]), 1)
- test.assert_equals(sumi([34, 45, 56]), 135)