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.
You have to create a function that given an array of integers returns the largest product that can be made by multiplying any 3 integers in the array.
Example:
[-4, -4, 2, 8]
should return 128 as the largest product can be made by multiplying -4 * -4 * 8 = 128.
def maximum_product_of_three(lst):
max_pr = 0
num_num = 0
for num in lst:
for i in range(0,len(lst)):
if i != lst[num_num] and num_num+2 < len(lst):
try:
if (num*lst[i+1]*lst[i+2])>max_pr:
max_num = num*lst[i+1]*lst[i+2]
except:
pass
num_num =+ 1
return max_num
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
test.assert_equals(maximum_product_of_three([-4,-4,2,8]), 128)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
using System;
public class Sum
{
public int GetSum(int a, int b)
{
return a + b;
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD development by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual("expected", "actual");
}
}
}
You have two lists you need to know what is in list two, that is not in list one:
missing file1.list file2.list
Two Lists
MacBook-Air:codewar dusty$ cat one
one
two
three
four
six
MacBook-Air:codewar dusty$ cat two
one
two
three
four
five
What is in list two, but not in list one:
MacBook-Air:codewar dusty$ missing one two
five
function missing() { cat $1 <(cat $1 $2 ) <(cat $2 $1 | sort | uniq -c | tr -d ' ' | grep '^1' | sed 's/1//') | sort | uniq -c | tr -d ' ' | grep '^2' | sed 's/2//'; }
# TODO: replace with your own tests (TDD). An example to get you started is included below.
# run the solution and store its result
# output = run_shell args: ['my_arg']
# describe "Solution" do
# it "should return the argument passed in" do
# expect(output).to include('my_arg')
# end
# end
USING: math ;
IN: multiplier
: multiply ( a b -- a*b ) * ;
USING: multiplier tools.testest ;
IN: multiplier.tests
: run-tests ( -- )
"Multiply" describe#{
"Basic tests" it#{
<{ 1 1 multiply -> 1 }>
<{ 1 2 multiply -> 2 }>
<{ 2 2 multiply -> 4 }>
<{ 3 5 multiply -> 15 }>
}#
}#
;
MAIN: run-tests
In JavaScript the most popular way of inverting strings would be something, similar to [...str].reverse().join('')
.
And what would be your unusual way?
const invert = str => str.replace(/./g, (_,o,s) => s.charAt(s.length-1-o));
const seed = Array.from({length:10}, (rnd,char) => (rnd=Math.random(), char=String.fromCharCode(Math.round(rnd*25)+97), rnd > 0.8 ? char.toUpperCase() : char)),
str = seed.join(''),
strInv = seed.reverse().join('');
Test.assertEquals(invert(str),strInv);
print(2+4)
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
# test.assert_equals(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
When asked about closest to N
integer divisible by n
, you might think of a neat and simple n*Math.round(N/n)
.
But, is there anything even more concise and fast?
closestMultiple=(N,n)=>n*(N/n+0.5>>0)
describe("Solution", function() {
it('must be rocket fast', function() {
Array.from({length:50000}, (_,i) => i).forEach(n => Test.expect((res=closestMultiple(n,7),!(res%7)&&Math.abs(n-res)<7), `There's a closer to ${n} multiple of 7 than ${res}`))
});
it('has to be short', function(){
Test.expect(solution.length<50)
})
});
Your task is to write a function sortWithoutSort()
that accepts an array
of arbitrary length n
with integer values v
as an argument. sortWithoutSort()
should return the sorted array in ascending order. You should not use Array.sort()
to achieve this.
function sortWithoutSort(array) {
for (let i = 0; i < array.length; i++) {
if (i < array.length - 1) {
if (array[i] > array[i+1]) {
var sortVal = array.splice(i,1)[0];
array.splice(i+1, 0, sortVal);
sortWithoutSort(array);
}
}
}
return array;
}
Test.describe("Solution", function() {
Test.it("should sort fixed arrays in ascending order", function() {
Test.assertSimilar(sortWithoutSort([]),[]);
Test.assertSimilar(sortWithoutSort([1]),[1]);
Test.assertSimilar(sortWithoutSort([2,4,3,1]),[1,2,3,4]);
Test.assertSimilar(sortWithoutSort([2,4,3,1,10,5,6,9,8,7]),[1,2,3,4,5,6,7,8,9,10]);
Test.assertSimilar(sortWithoutSort([2,2,2,2]),[2,2,2,2]);
Test.assertSimilar(sortWithoutSort([-1,-2,-3,-4]),[-4,-3,-2,-1]);
Test.assertSimilar(sortWithoutSort([-1,2,-3,4]),[-3,-1,2,4]);
});
});
Test.describe("Solution", function() {
Test.it("should sort random arrays in ascending order", function() {
function sort(array) {
for (let i = 0; i < array.length; i++) {
if (i < array.length - 1) {
if (array[i] > array[i+1]) {
var sortVal = array.splice(i,1)[0];
array.splice(i+1, 0, sortVal);
sort(array);
}
}
}
return array;
}
for (let i = 0; i < 25; i++) {
let randLength = Math.random(25) * 100 + 1;
let array = [];
let min = Math.ceil(-100);
let max = Math.floor(100);
for (let j = 0; j < randLength; j++) {
let randVal = Math.floor(Math.random() * (max - min + 1)) + min;
array.push(randVal)
}
Test.assertSimilar(sortWithoutSort(array), sort(array));
}
});
});
The totient function of a number is defined as the number of numbers less than that number that do not share a factor with that number.
Define a function totient(a) that computes the totient of a number.
def totient(a):
out = 0
for b in range(a):
if(gcd(a, b) == 1):
out += 1
return out
def gcd(a, b):
while b != 0:
(a, b) = (b, a % b)
return a
test.assert_equals(totient(1), 1)
test.assert_equals(totient(2), 1)
test.assert_equals(totient(3), 2)
test.assert_equals(totient(4), 2)
test.assert_equals(totient(5), 4)
test.assert_equals(totient(6), 2)
test.assert_equals(totient(7), 6)
test.assert_equals(totient(8), 4)
test.assert_equals(totient(9), 6)
You get a sentence in a string. Convert every word that has 4 letters or is longer to the word "yeet". If the sentence is longer than 4, it should replace the word with "yeet" but with as many "e"s as there are other letters except the ones on the ends.
It should return the sentence with the words that were changed and the words that weren't changed at the same place as they were before. It should also keep the punctations.
Have fun yeeting words
public class yeet {
public static String yeetWords(String Words){
String[] s = Words.split(" ");
String end = "";
String r = "";
if(s[s.length-1].endsWith(".") || s[s.length-1].endsWith("!") || s[s.length-1].endsWith("?")){
end = s[s.length-1].substring(s[s.length-1].length()-1);
}
for(int i = 0; i<s.length; i++){
String st = s[i];
String rs = "";
int le = st.length()-1;
if(st.length() >= 4){
if(st.endsWith(end)){
le = le-1;
}
rs = "y" + st.substring(1,1);
for(int e = 1; e<le; e++){
rs = rs + "e";
}
rs = rs + "t";
} else {
rs = st;
}
r = r + rs + " ";
}
return r.trim() + end;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals("I yeet to yeet yeet yeeet yeet yeeeeeeeeeeeeeeet!",yeet.yeetWords("I like to yeet long words like facetrackingdrone!"));
}
}