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.
Return a the number in the nth position of the Fibonacci sequence.
Example:
// Returns 34
get_fibonacci_n(9);
#define PI 3.14159265358979323846
#include <stddef.h>
#include <math.h>
size_t get_fibonacci_n(double n) {
if (n < 0) return -1;
double PHI = (1 + sqrt(5)) / 2;
double a = pow(PHI, n) - pow(-PHI, -n);
return (size_t)floor(a / sqrt(5));
}
#include <criterion/criterion.h>
// replace with the actual method being tested
size_t get_fibonacci_n(double);
Test(fibonacci_n, example_solution) {
cr_assert(get_fibonacci_n(9) == 34, "Expected 9th Fibonacci to be 34.");
}
Test(fibonacci_n, bigger_n) {
cr_assert(get_fibonacci_n(69) == 117669030460994, "Expected 69th Fibonnaci to be 117,669,030,460,994");
}
Convert a string into a math operation and return the result.
If the operator is '=', return 1 for true or 0 for false depending if those numbers are equal
!No false strings that have only one value or more operators!
You only have to worry about positive numbers
Example
"10+10" => 20
"10 + 100" => 110
"50- 10" => 40
"10 *21" => 210
"50=50" => 1
"1=2" => 0
fn math(e: &str) -> i32 {
let mut ope = '\0';
let mut first = 0;
let mut secon = 0;
for c in e.chars() {
match c {
'+' => {
ope = '+';
},
'-' => {
ope = '-';
},
'*' => {
ope = '*';
},
'/' => {
ope = '/';
},
'=' => {
ope = '='
}
'0'..='9' => {
if ope == '\0' {
first *= 10;
first += c as i32 - '0' as i32;
} else {
secon *= 10;
secon += c as i32 - '0' as i32;
}
}
' ' => {},
_ => {panic!("wrong value");}
}
}
return match ope {
'+' => first + secon,
'-' => first - secon,
'*' => first * secon,
'/' => first / secon,
'=' => (first == secon) as i32,
_ => panic!("no operator")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
assert_eq!(math("1 + 2"), 3);
assert_eq!(math("12+ 3456789"), 3456801);
assert_eq!(math("50 + 10 0"), 150);
}
#[test]
fn test_sub() {
assert_eq!(math("1-3"), -2);
assert_eq!(math("500 - 150"), 350);
assert_eq!(math("0-2"), -2);
}
#[test]
fn test_multiply() {
assert_eq!(math("1* 30"), 30);
assert_eq!(math("20 *5"), 100);
}
#[test]
fn test_divide() {
assert_eq!(math("10/5"), 2);
assert_eq!(math("500 / 2"), 250);
}
#[test]
fn test_equal() {
assert_eq!(math("10 = 10"), 1);
assert_eq!(math("2 =50"), 0);
assert_eq!(math("0=0"), 1);
}
}
Write a Python program to display the current date and time.
Sample Output :
Current date and time :
2014-07-05 14:34:14
import datetime
now = datetime.datetime.now()
print("Current date and time:")
print(now.strftime("%Y-%m-%d %H:%M:%S"))
import datetime
is it big?
def p_e_n_1_s():
print('yes')
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)
def thirty_seven(n)-> int:
"""This function must always return the integer 37"""
return n / sum([int(i) for i in str(n)])
import codewars_test as test
from solution import thirty_seven
@test.describe("Example")
def test_group():
@test.it("test case: True")
def test_case():
samples = (111, 222, 333, 444, 555, 666, 777, 888, 999)
for s in samples:
test.assert_equals(thirty_seven(s), 37)
@test.it("test case: False")
def test_case():
samples = (101, 2023, 33, 440, 551, 6666, 1776, 18, 1980)
for s in samples:
test.assert_not_equals(thirty_seven(s), 37)
Challenge: Write a program that generates a strong password from a phrase entered by the user.
Rules:
The program should prompt the user to enter a phrase to use as the basis for the password.
The program should validate the input to ensure that it contains at least 12 characters and at least one of each of the following types: uppercase letters, lowercase letters, digits, and symbols (punctuation marks and special characters).
If the input is valid, the program should generate a strong password using the following steps:
Remove any non-alphanumeric characters from the input phrase and convert it to lowercase.
Shuffle the characters in the phrase to create a randomized version of it.
Generate a random string of digits and symbols with a length of at least 6 and at most 10 characters.
Combine the shuffled phrase and the random string of digits and symbols to form the password.
The program should print the generated password to the console.
import random
import string
def password_from_phrase(phrase):
# Remove any non-alphabetic characters and convert to lowercase
phrase = ''.join(filter(str.isalpha, phrase)).lower()
# Shuffle the characters in the phrase
phrase_chars = list(phrase)
random.shuffle(phrase_chars)
shuffled_phrase = ''.join(phrase_chars)
# Generate a random string of numbers and symbols
num_symbols = random.randint(6, 10)
symbols = ''.join(random.choices(string.punctuation, k=num_symbols))
# Combine the shuffled phrase and symbols to form the password
password = shuffled_phrase[:6] + symbols + shuffled_phrase[6:]
return password
# Example usage:
phrase = "The quick brown fox"
password = password_from_phrase(phrase)
print("Password:", password)
"How I wish I could calculate pi"
The length of each word in the sentence constructs the first seven digits of pi
π.
- 3.141592
def memorizing_pi():
"""Returns the first sven digits of pi"""
memory = [str(len(i)) for i in 'How I wish I could calculate pi'.split()]
memory.insert(1, '.')
return float(''.join(memory))
import codewars_test as test
from solution import memorizing_pi
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(memorizing_pi(), 3.141592)
Write a function that takes two strings as arguments and returns true if they are anagrams of each other, and false otherwise. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
For example, the strings "iceman" and "cinema" are anagrams of each other.
Function Signature: function isAnagram(str1, str2)
Input:
Two strings str1 and str2 of length n (1 ≤ n ≤ 10^3) containing only lowercase letters.
Output:
A boolean value true if the two input strings are anagrams of each other, and false otherwise.
Example:
isAnagram('listen', 'silent'); // true
isAnagram('race', 'care'); // true
isAnagram('night', 'thing'); // false
function isAnagram(str1, str2) {
if (str1.length !== str2.length) {
return false;
}
const frequency = {};
for (let i = 0; i < str1.length; i++) {
const char = str1[i];
if (frequency[char]) {
frequency[char]++;
} else {
frequency[char] = 1;
}
}
for (let i = 0; i < str2.length; i++) {
const char = str2[i];
if (!frequency[char]) {
return false;
} else {
frequency[char]--;
}
}
return true;
}
const chai = require("chai");
const assert = chai.assert;
const Test = require("@codewars/test-compat");
describe('isAnagram', () => {
it('should return true for anagrams', () => {
assert.strictEqual(isAnagram('listen', 'silent'), true);
assert.strictEqual(isAnagram('race', 'care'), true);
});
it('should return false for non-anagrams', () => {
assert.strictEqual(isAnagram('night', 'things'), false);
assert.strictEqual(isAnagram('hello', 'world'), false);
});
it('should return false if input strings have different lengths', () => {
assert.strictEqual(isAnagram('abc', 'abcd'), false);
assert.strictEqual(isAnagram('abcd', 'abc'), false);
assert.strictEqual(isAnagram('anagram', 'nag a ram'), false);
});
});
SELECT TOP(50) qs.execution_count AS [Execution Count], (qs.total_logical_reads)/1000.0 AS [Total Logical Reads in ms], (qs.total_logical_reads/qs.execution_count)/1000.0 AS [Avg Logical Reads in ms], (qs.total_worker_time)/1000.0 AS [Total Worker Time in ms], (qs.total_worker_time/qs.execution_count)/1000.0 AS [Avg Worker Time in ms], (qs.total_elapsed_time)/1000.0 AS [Total Elapsed Time in ms], (qs.total_elapsed_time/qs.execution_count)/1000.0 AS [Avg Elapsed Time in ms], qs.creation_time AS [Creation Time] ,t.text AS [Complete Query Text], qp.query_plan AS [Query Plan] FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK) CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp WHERE t.dbid = DB_ID() ORDER BY qs.execution_count DESC OPTION (RECOMPILE);-- for frequently ran query -- ORDER BY [Avg Logical Reads in ms] DESC OPTION (RECOMPILE);-- for High Disk Reading query -- ORDER BY [Avg Worker Time in ms] DESC OPTION (RECOMPILE);-- for High CPU query -- ORDER BY [Avg Elapsed Time in ms] DESC OPTION (RECOMPILE);-- for Long Running query
# TODO: replace with your own tests (TDD), these are just how-to examples to get you started.
# Ruby/Rspec/Sequel Example:
# While the code section is pure SQL, for testing we use Ruby & Rspec.
# Sequel (https://github.com/jeremyevans/sequel) is used to setup the database and run queries.
# The connection is already made for you, use DB to access.
DB.create_table :items do
primary_key :id
String :name
Float :price
end
items = DB[:items] # Create a dataset
# Populate the table
items.insert(:name => 'a', :price => 10)
items.insert(:name => 'b', :price => 35)
items.insert(:name => 'c', :price => 20)
# calling run_sql will print the results and return them so that you can test data within them.
# if you want to test different sets of data, then its best to move this code into its own top level describe
# block. If you are only testing one set though, its better to set the results before you enter a describe block
# so that the results are presented at the top of the output.
results = run_sql
describe :items do
it "should return 3 items" do
expect(results.count).to eq 3
end
end
# Other tips about using run_sql:
# The SQL/code section supports multiple statements, seperated of course by a ";".
# When multiple SELECT statements are issued:
# run_sql will return an array of arrays, unless only one SELECT statement returned results
# INSERT and UPDATE results will not be included in the list
# SELECT statements that return no results will not be included in the list
Olá!
let hello = 'hello world!'
console.log(hello)
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});