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.
using System; namespace Solution { class FizzBuzz { public static string Convert(int input) { var divisableBy3 = input % 3 == 0; var divisableBy5 = input % 5 == 0; return (!divisableBy3 & !divisableBy5) ? input.ToString() : (divisableBy3 ? "Fizz" : string.Empty) + (divisableBy5 ? "Buzz" : string.Empty); } } }
- using System;
- namespace Solution {
- class FizzBuzz {
- public static string Convert(int input)
- {
var divisableBy3 = (input % 3 == 0);var divisableBy5 = (input % 5 == 0);- var divisableBy3 = input % 3 == 0;
- var divisableBy5 = input % 5 == 0;
- return (!divisableBy3 & !divisableBy5) ? input.ToString()
- : (divisableBy3 ? "Fizz" : string.Empty) + (divisableBy5 ? "Buzz" : string.Empty);
- }
- }
- }
import java.util.stream.IntStream; public class Area { public static long[] workOutArea(final long[] values){ return values.length % 2 != 0? null: IntStream.range(0, values.length).filter(x -> x % 2 == 0).mapToLong(x -> values[x] * values[x+1]).toArray(); } }
- import java.util.stream.IntStream;
- public class Area {
- public static long[] workOutArea(final long[] values){
if (values.length % 2 != 0) {return null; // This is ugly!} else {final long[] areas = new long[values.length / 2];for (int i = 0; i < values.length; i += 2) {areas[i / 2] = values[i] * values[i + 1];}return areas;}- return values.length % 2 != 0? null: IntStream.range(0, values.length).filter(x -> x % 2 == 0).mapToLong(x -> values[x] * values[x+1]).toArray();
- }
- }
Show optimization of code. Instead 4 passs throught array (max,min,count double time), use only one pass durring sorting.
# Find stray number def find_stray(n) n.count(n.min) > n.count(n.max) ? n.max : n.min end # Find stray optimization def find_stray_o(n) n.sort! n[0] == n[1] ? n[-1] : n[0] end require "benchmark" array = (Array.new(1000_000,7) + [1]).shuffle Benchmark.bm(10) do |x| x.report("Find stray") { 10.times{ find_stray(array.clone.shuffle) }} x.report("Optimized") { 10.times{find_stray_o(array.clone.shuffle) }} end
- # Find stray number
- def find_stray(n)
- n.count(n.min) > n.count(n.max) ? n.max : n.min
- end
- # Find stray optimization
- def find_stray_o(n)
- n.sort!
- n[0] == n[1] ? n[-1] : n[0]
- end
- require "benchmark"
- array = (Array.new(1000_000,7) + [1]).shuffle
- Benchmark.bm(10) do |x|
- x.report("Find stray") { 10.times{ find_stray(array.clone.shuffle) }}
- x.report("Optimized") { 10.times{find_stray_o(array.clone.shuffle) }}
- end
x = rand(1..100) y = rand(1..100) describe "Solution" do it "find stray" do Test.assert_equals(find_stray([x,y,y]), x, "[x,y,y] works") Test.assert_equals(find_stray([x,y,y,y]), x, "[x,y,y,y] DOSE NOT works") Test.assert_equals(find_stray([x,y,y,y,y]), x, "[x,y,y,y,y] works") end it "find stray optimized" do Test.assert_equals(find_stray_o([x,y,y]), x, "[x,y,y] works") Test.assert_equals(find_stray_o([x,y,y,y]), x, "[x,y,y,y] DOSE NOT works") Test.assert_equals(find_stray_o([x,y,y,y,y]), x, "[x,y,y,y,y] works") end end
- x = rand(1..100)
- y = rand(1..100)
- describe "Solution" do
it "should test for something" do- it "find stray" do
- Test.assert_equals(find_stray([x,y,y]), x, "[x,y,y] works")
- Test.assert_equals(find_stray([x,y,y,y]), x, "[x,y,y,y] DOSE NOT works")
- Test.assert_equals(find_stray([x,y,y,y,y]), x, "[x,y,y,y,y] works")
- end
- it "find stray optimized" do
- Test.assert_equals(find_stray_o([x,y,y]), x, "[x,y,y] works")
- Test.assert_equals(find_stray_o([x,y,y,y]), x, "[x,y,y,y] DOSE NOT works")
- Test.assert_equals(find_stray_o([x,y,y,y,y]), x, "[x,y,y,y,y] works")
- end
- end
++++++[>++++++<-]>[->+>++>+++>+++<<<<]>>.>-------.>..+++.<<<----.>-.>----.+.>+++.<+++++++.----.>------.
-[------->+<]>-.-[->+++++<]>++.+++++++..+++.[--->+<]>-----.+++[->++<]>+.-[------>+<]>.+.[--->+<]>----.---------.----.+++++++.- +++++++[>++++++<-]>[->+>++>+++>+++<<<<]>>.>-------.>..+++.<<<----.>-.>----.+.>+++.<+++++++.----.>------.
Missing what is it about. Just simplyfing things :)
COLORS = set("RGB") def blend(c1, c2): colors = {c1, c2} return c1 if len(colors) == 1 else (COLORS - colors).pop() def preprocess(row): check = "" for r in row: if r != check: yield r check = r def triangle(row): row = list(preprocess(row)) while len(row) > 1: for i,r in enumerate(row[:-1]): row[i] = blend(r, row[i+1]) row.pop() return row[0]
import re- COLORS = set("RGB")
- def blend(c1, c2):
if c1 == c2: return c1colors = c1 + c2if colors == "RB" or colors == "BR": return "G"if colors == "RG" or colors == "GR": return "B"if colors == "GB" or colors == "BG": return "R"- colors = {c1, c2}
- return c1 if len(colors) == 1 else (COLORS - colors).pop()
- def preprocess(row):
orig = rowrow,_ = re.subn('RR+', 'R', row)row,_ = re.subn('BB+', 'B', row)row,_ = re.subn('GG+', 'G', row)print(orig, row)return row- check = ""
- for r in row:
- if r != check:
- yield r
- check = r
- def triangle(row):
if len(row) == 1: return rowrow = preprocess(row)row = list(row)for j in range(len(row)-1,0,-1):for i in range(j):row[i] = blend(row[i], row[i+1])return row[0]- row = list(preprocess(row))
- while len(row) > 1:
- for i,r in enumerate(row[:-1]):
- row[i] = blend(r, row[i+1])
- row.pop()
- return row[0]
Looks familiar?
Expected: equal to [unsupported type]
Actual: [unsupported type]
No more!
template <class... Args> bool alwaysTrue(Args&&...) { return true; } template <class T> T id(T&& x) { return x; }
- template <class... Args>
- bool alwaysTrue(Args&&...) {
- return true;
}- }
- template <class T>
- T id(T&& x) {
- return x;
- }
#include <list> #include <tuple> #include <utility> #include <vector> template <class... Args> void printInput(const char* name, const Args&... args); #define alwaysTrue(...) (printInput("alwaysTrue", __VA_ARGS__), alwaysTrue(__VA_ARGS__)) Describe(codewarriors) { It(do_print_arguments) { using vi = std::vector<int>; using li = std::list<int>; using vvi = std::vector<std::vector<int>>; using vs = std::vector<std::string>; using pii = std::pair<int, int>; Assert::That(alwaysTrue(vi{0, 1, 2}), Is().True()); Assert::That(alwaysTrue(li{0, 1, 2}), Is().True()); Assert::That(alwaysTrue((int[]){0, 1, 2}), Is().True()); Assert::That(alwaysTrue(vvi{{0, 1, 2}, {0, 1}, {1}}), Is().True()); Assert::That(alwaysTrue("012"), Is().True()); Assert::That(alwaysTrue((const char*)"012"), Is().True()); Assert::That(alwaysTrue(std::string{"012"}), Is().True()); Assert::That(alwaysTrue(vi{0, 1, 2}, "012", 123), Is().True()); Assert::That(alwaysTrue(vs{"a", "b", ""}, 'c'), Is().True()); Assert::That(alwaysTrue("pair", std::make_pair(1, "2")), Is().True()); Assert::That(alwaysTrue("tuple", std::make_tuple(1, "2", '3', vi{1})), Is().True()); Assert::That(id(pii{0, 1}), Equals(pii{0, 1})); } }; #include <cstddef> #include <algorithm> #include <iostream> #include <iterator> #include <ostream> #include <type_traits> #include <utility> #include <tuple> template <class... Ts> struct make_void { using type = void; }; template <class... Ts> using void_t = typename make_void<Ts...>::type; template <class, class = void> struct is_container : std::false_type { }; template <class T> struct is_container<T, void_t<decltype(std::cbegin(std::declval<T>()))>> : std::true_type { }; template <class, class = void> struct is_string : std::false_type { }; template <class T> struct is_string<T, std::enable_if_t<std::is_same<decltype(*std::cbegin(std::declval<T>())), const char&>::value>> : std::true_type { }; struct ArgumentPrinter { std::ostream& os; template <class Arg, std::enable_if_t<!is_container<Arg>::value && !is_string<Arg>::value>* = nullptr> void printArg(const Arg& arg) { os << arg; } void printArg(const char arg) { os << "'" << arg << "'"; } void printArg(const char* const arg) { os << '"' << arg << '"'; } template <class Arg, std::enable_if_t<is_string<Arg>::value>* = nullptr> void printArg(const Arg& arg) { os << '"'; std::copy(std::cbegin(arg), std::cend(arg), std::ostreambuf_iterator<char>(os)); os << '"'; } template <class T1, class T2> void printArg(const std::pair<T1, T2>& arg) { os << "{"; printArgs(arg.first); os << ", "; printArgs(arg.second); os << "}"; } #include <tuple> template <typename T, std::size_t... Is> void printArgsApplyImpl(const T& arg, std::index_sequence<Is...>) { printArgs(std::get<Is>(arg)...); } template <typename... Ts> void printArgsApply(const std::tuple<Ts...>& arg) { printArgsApplyImpl(arg, std::make_index_sequence<std::tuple_size<std::tuple<Ts...>>::value>()); } template <class... Ts> void printArg(const std::tuple<Ts...>& arg) { os << "{"; printArgsApply(arg); os << "}"; } template <class Arg, std::enable_if_t<is_container<Arg>::value && !is_string<Arg>::value>* = nullptr> void printArg(const Arg& arg) { const auto b = std::cbegin(arg), e = std::end(arg); os << "{"; for (auto i = b; i != e; ++i) { if (i != b) os << ", "; printArgs(*i); } os << "}"; } template <class Arg> void printArgs(const Arg& arg) { printArg(arg); } template <class Arg, class... Args> void printArgs(const Arg& arg, const Args&... args) { printArgs(arg); os << ", "; printArgs(args...); } }; template <class... Args> void printInput(const char* name, const Args&... args) { std::cout << name << "("; ArgumentPrinter{std::cout}.printArgs(args...); std::cout << ")\n"; } #define DEFINE_STRINGIZER(type) \ namespace snowhouse {\ template <> struct Stringizer<type> {\ static std::string ToString(const type& x) {\ std::ostringstream oss;\ ArgumentPrinter{oss}.printArg(x);\ return oss.str();\ }\ };\ } #define COMMA , DEFINE_STRINGIZER(std::pair<int COMMA int>)
- #include <list>
- #include <tuple>
- #include <utility>
- #include <vector>
- template <class... Args> void printInput(const char* name, const Args&... args);
- #define alwaysTrue(...) (printInput("alwaysTrue", __VA_ARGS__), alwaysTrue(__VA_ARGS__))
- Describe(codewarriors) {
- It(do_print_arguments) {
- using vi = std::vector<int>;
- using li = std::list<int>;
- using vvi = std::vector<std::vector<int>>;
- using vs = std::vector<std::string>;
- using pii = std::pair<int, int>;
- Assert::That(alwaysTrue(vi{0, 1, 2}), Is().True());
- Assert::That(alwaysTrue(li{0, 1, 2}), Is().True());
- Assert::That(alwaysTrue((int[]){0, 1, 2}), Is().True());
- Assert::That(alwaysTrue(vvi{{0, 1, 2}, {0, 1}, {1}}), Is().True());
- Assert::That(alwaysTrue("012"), Is().True());
- Assert::That(alwaysTrue((const char*)"012"), Is().True());
- Assert::That(alwaysTrue(std::string{"012"}), Is().True());
- Assert::That(alwaysTrue(vi{0, 1, 2}, "012", 123), Is().True());
- Assert::That(alwaysTrue(vs{"a", "b", ""}, 'c'), Is().True());
- Assert::That(alwaysTrue("pair", std::make_pair(1, "2")), Is().True());
- Assert::That(alwaysTrue("tuple", std::make_tuple(1, "2", '3', vi{1})), Is().True());
- Assert::That(id(pii{0, 1}), Equals(pii{0, 1}));
- }
- };
- #include <cstddef>
- #include <algorithm>
- #include <iostream>
- #include <iterator>
- #include <ostream>
- #include <type_traits>
- #include <utility>
- #include <tuple>
- template <class... Ts> struct make_void { using type = void; };
- template <class... Ts> using void_t = typename make_void<Ts...>::type;
- template <class, class = void> struct is_container : std::false_type { };
- template <class T> struct is_container<T, void_t<decltype(std::cbegin(std::declval<T>()))>> : std::true_type { };
- template <class, class = void> struct is_string : std::false_type { };
- template <class T> struct is_string<T, std::enable_if_t<std::is_same<decltype(*std::cbegin(std::declval<T>())), const char&>::value>> : std::true_type { };
- struct ArgumentPrinter {
- std::ostream& os;
- template <class Arg, std::enable_if_t<!is_container<Arg>::value && !is_string<Arg>::value>* = nullptr>
- void printArg(const Arg& arg) {
- os << arg;
- }
- void printArg(const char arg) {
- os << "'" << arg << "'";
- }
- void printArg(const char* const arg) {
- os << '"' << arg << '"';
- }
- template <class Arg, std::enable_if_t<is_string<Arg>::value>* = nullptr>
- void printArg(const Arg& arg) {
- os << '"';
- std::copy(std::cbegin(arg), std::cend(arg), std::ostreambuf_iterator<char>(os));
- os << '"';
- }
- template <class T1, class T2>
- void printArg(const std::pair<T1, T2>& arg) {
- os << "{";
- printArgs(arg.first);
- os << ", ";
- printArgs(arg.second);
- os << "}";
- }
- #include <tuple>
- template <typename T, std::size_t... Is>
- void printArgsApplyImpl(const T& arg, std::index_sequence<Is...>) {
- printArgs(std::get<Is>(arg)...);
- }
- template <typename... Ts>
- void printArgsApply(const std::tuple<Ts...>& arg) {
- printArgsApplyImpl(arg, std::make_index_sequence<std::tuple_size<std::tuple<Ts...>>::value>());
- }
- template <class... Ts>
- void printArg(const std::tuple<Ts...>& arg) {
- os << "{";
- printArgsApply(arg);
- os << "}";
- }
- template <class Arg, std::enable_if_t<is_container<Arg>::value && !is_string<Arg>::value>* = nullptr>
- void printArg(const Arg& arg) {
- const auto b = std::cbegin(arg), e = std::end(arg);
- os << "{";
- for (auto i = b; i != e; ++i) {
- if (i != b)
- os << ", ";
- printArgs(*i);
- }
- os << "}";
- }
- template <class Arg>
- void printArgs(const Arg& arg) {
- printArg(arg);
- }
- template <class Arg, class... Args>
- void printArgs(const Arg& arg, const Args&... args) {
- printArgs(arg);
- os << ", ";
- printArgs(args...);
- }
- };
- template <class... Args>
- void printInput(const char* name, const Args&... args) {
- std::cout << name << "(";
- ArgumentPrinter{std::cout}.printArgs(args...);
- std::cout << ")\n";
- }
- #define DEFINE_STRINGIZER(type) \
- namespace snowhouse {\
- template <> struct Stringizer<type> {\
- static std::string ToString(const type& x) {\
- std::ostringstream oss;\
- ArgumentPrinter{oss}.printArg(x);\
- return oss.str();\
- }\
- };\
- }
- #define COMMA ,
- DEFINE_STRINGIZER(std::pair<int COMMA int>)