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.
Readable RGB to HSV, with the fog machine turned off.
Same algorithm, fewer riddles. This fork names the moving parts instead of asking the reader to spelunk through nested ternaries and magic constants:
- normalized RGB channels
- value, minimum, and chroma
- hue sector calculation
- saturation and value percentages
No shade to the ancestors; the math was already there. I just made it stop whispering and start explaining itself.
const RGB_MAX = 255; const HUE_SECTOR_DEGREES = 60; const PERCENT = 100; function rgbToHsv(rgb) { const [red, green, blue] = rgb.map(normalizeChannel); const value = Math.max(red, green, blue); const minimum = Math.min(red, green, blue); const chroma = value - minimum; const hue = chroma === 0 ? 0 : hueSector(red, green, blue, chroma, value) * HUE_SECTOR_DEGREES; const saturation = value === 0 ? 0 : chroma / value; return [ roundDegrees(hue), roundPercent(saturation), roundPercent(value) ]; } function normalizeChannel(channel) { return channel / RGB_MAX; } function hueSector(red, green, blue, chroma, value) { if (value === red) return ((green - blue) / chroma + 6) % 6; if (value === green) return (blue - red) / chroma + 2; return (red - green) / chroma + 4; } function roundDegrees(degrees) { return Math.round(degrees) % 360; } function roundPercent(ratio) { return Math.round(ratio * PERCENT); }function rgbToHsv([r,g,b]){[r,g,b] = [r,g,b].map(x => x/255);let v = Math.max(r,g,b),d = v - Math.min(r,g,b),h = d ? (v == r ? (g - b) / d:v == g ?(b - r) / d + 2:(r - g)/d + 4):0;return [Math.round((h * 60 + 360) %360),Math.round(v ? d / v * 100 : 0),Math.round(v * 100)]- const RGB_MAX = 255;
- const HUE_SECTOR_DEGREES = 60;
- const PERCENT = 100;
- function rgbToHsv(rgb) {
- const [red, green, blue] = rgb.map(normalizeChannel);
- const value = Math.max(red, green, blue);
- const minimum = Math.min(red, green, blue);
- const chroma = value - minimum;
- const hue = chroma === 0
- ? 0
- : hueSector(red, green, blue, chroma, value) * HUE_SECTOR_DEGREES;
- const saturation = value === 0 ? 0 : chroma / value;
- return [
- roundDegrees(hue),
- roundPercent(saturation),
- roundPercent(value)
- ];
- }
- function normalizeChannel(channel) {
- return channel / RGB_MAX;
- }
- function hueSector(red, green, blue, chroma, value) {
- if (value === red) return ((green - blue) / chroma + 6) % 6;
- if (value === green) return (blue - red) / chroma + 2;
- return (red - green) / chroma + 4;
- }
- function roundDegrees(degrees) {
- return Math.round(degrees) % 360;
- }
- function roundPercent(ratio) {
- return Math.round(ratio * PERCENT);
- }
dumbRockPaperScissors = lambda a,b: ["Draw","Player 1 wins","Player 2 wins"][("RPS".index(a[0])- "RPS".index(b[0]))%3]dumbRockPaperScissors=lambda a,b:('Draw','Player 1 wins','Player 2 wins')['RPS'.find(a[0])-'RPS'.find(b[0])]def rps (p1,p2):retval= {'R':{'R': 0, 'S':-1, "P": 1},'S':{'R': 1, 'S': 0, 'P':-1},'P':{'R':-1, 'S': 1, 'P':0}}return retval[p1][p2]- dumbRockPaperScissors = lambda a,b: ["Draw","Player 1 wins","Player 2 wins"][("RPS".index(a[0])- "RPS".index(b[0]))%3]
some may have failed
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class SolutionTest { @Test void basicTests() { assertEquals(true, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution"}, 2)); assertEquals(false, WordChain.validate(new String[] {"sune", "number", "revolution", "nonaggressive", "evolution"}, 1)); assertEquals(false, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution", "number"}, 1)); assertEquals(false, WordChain.validate(new String[] {"sune", "number", "revolution", "nonaggressive", "evolution", "number"}, 1)); } @Test void nWordsTests() { assertEquals(false, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution"}, 2)); assertEquals(true, WordChain.validate(new String[] {"sun", "under", "erosion", "once", "center"}, 2)); } @Test void emptyArrayTest() { assertEquals(false, WordChain.validate(new String[] {}, 2)); } @Test void containsNullArrayTest() { assertEquals(false, WordChain.validate(new String[] {"A", "AB", null, "CCA"}, 2)); } @Test void wordChainWithOneWordTest() { assertEquals(false, WordChain.validate(new String[] {"ABC"}, 2)); assertEquals(true, WordChain.validate(new String[] {"ABC", "BCA"}, 1)); } @Test void numberCantBeNegativeTest() { assertEquals(false, WordChain.validate(new String[] {"sun", "under", "erosion", "once", "center"}, -2)); } }- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- class SolutionTest {
- @Test
- void basicTests() {
assertEquals(true, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution"}, 1));- assertEquals(true, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution"}, 2));
- assertEquals(false, WordChain.validate(new String[] {"sune", "number", "revolution", "nonaggressive", "evolution"}, 1));
- assertEquals(false, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution", "number"}, 1));
- assertEquals(false, WordChain.validate(new String[] {"sune", "number", "revolution", "nonaggressive", "evolution", "number"}, 1));
- }
- @Test
void nLettersTests() {- void nWordsTests() {
- assertEquals(false, WordChain.validate(new String[] {"sun", "number", "revolution", "nonaggressive", "evolution"}, 2));
- assertEquals(true, WordChain.validate(new String[] {"sun", "under", "erosion", "once", "center"}, 2));
- }
- @Test
- void emptyArrayTest() {
- assertEquals(false, WordChain.validate(new String[] {}, 2));
- }
- @Test
- void containsNullArrayTest() {
- assertEquals(false, WordChain.validate(new String[] {"A", "AB", null, "CCA"}, 2));
- }
- @Test
- void wordChainWithOneWordTest() {
- assertEquals(false, WordChain.validate(new String[] {"ABC"}, 2));
assertEquals(true, WordChain.validate(new String[] {"ABC", "BCA"}, 2));- assertEquals(true, WordChain.validate(new String[] {"ABC", "BCA"}, 1));
- }
- @Test
- void numberCantBeNegativeTest() {
- assertEquals(false, WordChain.validate(new String[] {"sun", "under", "erosion", "once", "center"}, -2));
- }
- }
console.log("testing 1 2 3");const canvas = document.getElementById("gameCanvas");const ctx = canvas.getContext("2d");- console.log("testing 1 2 3");
const gridSize = 20;const tileCount = canvas.width / gridSize;let snake = [{ x: 10, y: 10 }];let direction = { x: 1, y: 0 };let nextDirection = { x: 1, y: 0 };let food = spawnFood();let score = 0;function spawnFood() {let newFood;while (true) {newFood = {x: Math.floor(Math.random() * tileCount),y: Math.floor(Math.random() * tileCount)};if (!snake.some(part => part.x === newFood.x && part.y === newFood.y)) {return newFood;}}}function draw() {ctx.clearRect(0, 0, canvas.width, canvas.height);ctx.fillStyle = "red";ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize, gridSize);// Draw snakesnake.forEach((part, index) => {ctx.fillStyle = index === 0 ? "lime" : "green";ctx.fillRect(part.x * gridSize, part.y * gridSize, gridSize, gridSize);});}function update() {direction = nextDirection;const head = {x: snake[0].x + direction.x,y: snake[0].y + direction.y};// Wall collisionif (head.x < 0 || head.x >= tileCount ||head.y < 0 || head.y >= tileCount) {resetGame();return;}// Self collisionif (snake.some(part => part.x === head.x && part.y === head.y)) {resetGame();return;}snake.unshift(head);// Eat foodif (head.x === food.x && head.y === food.y) {score++;document.getElementById("score").textContent = score;food = spawnFood();} else {snake.pop();}draw();}function resetGame() {snake = [{ x: 10, y: 10 }];direction = { x: 1, y: 0 };nextDirection = { x: 1, y: 0 };food = spawnFood();score = 0;document.getElementById("score").textContent = score;}draw();setInterval(update, 120);