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.
caring about {[( and ingredinents with numbers like "vitamin B1"
function glutenDetector(ingredients){ const gluten = [ "wheat", "wheat flour", "triticale", "barley", "rye", "brewer's yeast", "malt", "wheatberries", "durum", "emmer", "semolina", "spelt", "farina", "farro", "graham", "kamut", "einkorn" ]; return ingredients .toLowerCase() .split(/[^\w\d]{2,}/) .some(x => gluten.includes(x)); }
- function glutenDetector(ingredients){
- const gluten = [
- "wheat",
- "wheat flour",
- "triticale",
- "barley",
- "rye",
- "brewer's yeast",
- "malt",
- "wheatberries",
- "durum",
- "emmer",
- "semolina",
- "spelt",
- "farina",
- "farro",
- "graham",
- "kamut",
- "einkorn"
- ];
- return ingredients
- .toLowerCase()
.split(/[,\s]+/)- .split(/[^\w\d]{2,}/)
- .some(x => gluten.includes(x));
- }
Data.Set is better. It's safer than head/tail and faster than nub
(O(n^2)). For instance, size
is O(1) and fromList
is O(n*log n).
module AllEqual where import Data.Set (fromList, size) allEqual :: [Int] -> Bool allEqual xs = (size $ fromList xs) <= 1
- module AllEqual where
import Data.List- import Data.Set (fromList, size)
- allEqual :: [Int] -> Bool
allEqual xs = length (nub xs) <= 1- allEqual xs = (size $ fromList xs) <= 1
You can declare Array with running numbers up by using [...Array(n).keys]
. Then if you want it start from 1
, you just increase array size then slice it of.
const isPerfect = n => [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n
- const isPerfect = n =>
Array(n - 1).fill(1).map((e, i) => e + i).filter(e => n % e === 0).reduce((a, b) => a + b) === n- [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n
# Method with three named arguments # https://robots.thoughtbot.com/ruby-2-keyword-arguments def c one: "one", two: "tow", three: "three" p "one: %s two: %s three: %s" % [one,two,three] end c # calling without arguments c two: "TWO2" # calling with one argument c two: "2", one: 1111111 # Calling with 2 arguments with no order c(one: 1, two: 2, three: 3) # Passing 3 Named arguments c(two: 22, three: 333, one: 1 ) # Passing 3 Named arguments (mess the order) begin c fore: "4" # calling with wrong argument rescue Exception => e p e.message p e.class end begin #c (fore:"4") # calling with wrong argument # this lead to syntaxix error rescue Exception => e puts("#{e.message}\n#{e.class}") end hash = {one: 'One', two: 'Two', three: 'Three'} c hash # calling with hash hash = {two: 'Two', three: 'Three', one: 'One', } c hash # calling with hash mess in order hash = { one: 'One', } c hash # calling with hash where not all argumetns listed # Super syntax hash = { two: '222', } c one: 1, **hash # c one: 1, hash # <== leads to error begin hash = { one: 'One', fore: "4" } c hash # calling with hash that contain pair unlisetd in named arguments rescue Exception => e puts("#{e.message}\n#{e.class}") end
- # Method with three named arguments
- # https://robots.thoughtbot.com/ruby-2-keyword-arguments
- def c one: "one", two: "tow", three: "three"
- p "one: %s two: %s three: %s" % [one,two,three]
- end
- c # calling without arguments
- c two: "TWO2" # calling with one argument
- c two: "2", one: 1111111 # Calling with 2 arguments with no order
- c(one: 1, two: 2, three: 3) # Passing 3 Named arguments
- c(two: 22, three: 333, one: 1 ) # Passing 3 Named arguments (mess the order)
- begin
- c fore: "4" # calling with wrong argument
- rescue Exception => e
- p e.message
- p e.class
- end
- begin
- #c (fore:"4") # calling with wrong argument
- # this lead to syntaxix error
- rescue Exception => e
p e.messagep e.class- puts("#{e.message}\n#{e.class}")
- end
- hash = {one: 'One', two: 'Two', three: 'Three'}
- c hash # calling with hash
- hash = {two: 'Two', three: 'Three', one: 'One', }
- c hash # calling with hash mess in order
- hash = { one: 'One', }
- c hash # calling with hash where not all argumetns listed
- # Super syntax
- hash = { two: '222', }
- c one: 1, **hash
- # c one: 1, hash # <== leads to error
- begin
- hash = { one: 'One', fore: "4" }
- c hash # calling with hash that contain pair unlisetd in named arguments
- rescue Exception => e
p e.messagep e.class- puts("#{e.message}\n#{e.class}")
- end
This is a response to the kumite https://www.codewars.com/kumite/5a4edf17d8e145968c00015e to show that it has an elegant solution for ruby using the compiled bash utility "tr"
It's my first kumite so I'm not sure if this is how to use it. Don't mind if I do!
def pattern a,b a.tr(a,b)==b && b.tr(b,a)==a end
def pattern(p,st):def encode(s):dic={} # dictionary to hold values from the input stringnum=0sn="" # a numerical string to hold the encodingfor i in s:if i not in dic:dic[i]=numnum+=1sn+=str(dic[i])return snreturn encode(st)==encode(p)- def pattern a,b
- a.tr(a,b)==b && b.tr(b,a)==a
- end
describe "Basic Tests" do it "should pass basic tests" do Test.assert_equals(pattern("abab", "1010"), true); Test.assert_equals(pattern("mmmm", "0000"), true); Test.assert_equals(pattern("a", "1"), true); Test.assert_equals(pattern("1010111", "0101000"), true); Test.assert_equals(pattern("777a9", "aba"), false); Test.assert_equals(pattern("123au", "00000"), false); end end
test.assert_equals(pattern("abab", "1010"), True )test.assert_equals(pattern("mmmm", "0000"), True )test.assert_equals(pattern("a", "1"), True )test.assert_equals(pattern("1010111", "0101000"), True )test.assert_equals(pattern("777a9", "aba"), False )test.assert_equals(pattern("123au", "00000"), False )- describe "Basic Tests" do
- it "should pass basic tests" do
- Test.assert_equals(pattern("abab", "1010"), true);
- Test.assert_equals(pattern("mmmm", "0000"), true);
- Test.assert_equals(pattern("a", "1"), true);
- Test.assert_equals(pattern("1010111", "0101000"), true);
- Test.assert_equals(pattern("777a9", "aba"), false);
- Test.assert_equals(pattern("123au", "00000"), false);
- end
- end