Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Golden Ratio Φ ✨

"""
What do the Pyramids of Giza and Da Vinci’s Mona Lisa have in common with Twitter and Pepsi?
Quick answer: They are all designed using the Golden Ratio.
The Golden Ratio is a mathematical ratio. It is commonly found in nature, and when used in a design,
it fosters organic and natural-looking compositions that are aesthetically pleasing to the eye.
Many processes in nature can be described by the Fibonacci. and the quotient
of successive elements of the Fibonacci sequence result in the golden ratio also associated with beauty

Putting it as simply as we can (eek!), the Golden Ratio
(also known as the Golden Section, Golden Mean, Divine Proportion or Greek letter Phi)
exists when a line is divided into two parts and the longer part (a) divided by the smaller part (b)
is equal to the sum of (a) + (b) divided by (a), which both equal 1.618.... with endless decimals
The larger the numbers in the Fibonacci sequence that are used for the quotient, the more accurate the result

Write a Programm that calculates the golden ratio from the Fibonacci sequence
giving as input the largest number in the Fibonacci sequence to be used for the quotient
Hint: create first a class Fibonacci that iterate over the sequence
then create another class Golden_ratio that inherits from Fibonacci

Example Input:
n = 9
Example output:
Fibonacci sequence for 9 as the largest Number in the sequence
1 1 2 3 5 8 13 21 34
Golden Ratio approach:
1.000000
2.000000
1.500000
1.666667
1.600000
1.625000
1.615385
1.619048
1.617647
"""

``````n = 9

class Fibonacci:
def __init__(self, max_n):
self.Max_n = max_n
self.N = 0
self.A = 0
self.B = 0

def __iter__(self):
self.N = 0
self.A = 0
self.B = 1
return self

def __next__(self):
if self.N < self.Max_n:
self.N += 1
self.A, self.B = self.B, self.A + self.B
return self.A
else:
raise StopIteration

class Golden_ratio(Fibonacci):
def __next__(self):
Fibonacci.__next__(self)
return self.B / self.A

print(f"Fibonacci sequence for {n} as the largest Number in sequence")
for f in Fibonacci(n):
print(f, end=" ")
print("\nGolden Ratio approach:")
for g in Golden_ratio(n):
print(f"{g:.6f}")``````

turkeyncheese's Kumite #11

This is the McCarthy 91 function. It's pretty cool see if you can reduce it any further.

McCarthy 91 Function info: https://en.wikipedia.org/wiki/McCarthy_91_function

``def f(n): return n - 10 if n > 100 else f(f(n + 11))``
Failed Tests

Rock Paper Scissors Game

Fundamentals
Games

Implement function for Rock Paper Scissors game, players submits his/her shape and cpu gets random draw between the 3 shapes, the two data are compared and winner is decided.

I'm in learning fundamental JavaScript phase, tried to challenge my self to comeup with the code from syntax I know up till now, this is why its probably so long, tried the switch statement, i also did it in if/else statement, but liked this switch way cause i could include the shapes of players in the alert msg.

I checked the code and it works, but somehow cant figure out how to setup 'Test Cases'section for it on this website, appreciate if you guys could let me know how to set test cases for it or any other suggestions about my long & probably stupid code.

``````let player;
let cpu;

const rpsGame = function (player, cpu) {
player = prompt(`Rock Paper Scissors Game, which shape you go with:`);
cpu = Math.trunc(Math.random() * 3 + 1);
switch (player) {
case 'Rock':
if (cpu === 2)
if (cpu === 3)
if (cpu === 1)
return alert(`Both players choose \${player}: ITS A TIE...!`);
break;
case 'Paper':
if (cpu === 1)
if (cpu === 2)
return alert(`Both players choose \${player}: ITS A TIE...!`);
if (cpu === 3)
break;
case 'Scissors':
if (cpu === 1)
if (cpu === 2)
if (cpu === 3)
return alert(`Both players choose \${player}: ITS A TIE...!`);
break;
default:
break;
}
};``````

Basic arithmetic operations

Parsing
Algorithms
Logic
Strings
Data Types

Given an expression as a string, calculate its value. For example, given the string "1+2+3", return 6.

Order of operations should be respected: multiplication happens before addition.

Possible avenues for future exploration:

• Adding support for subtraction and division
• Stripping whitespace
``````using System;
using System.Linq;

public class ArtihmeticParser
{
public static int Evaluate(string input)
{
return input.Split("+").Select(EvaluateProduct).Aggregate(0,(a,b) => a+b);
}

private static int EvaluateProduct(string input)
{
return input.Split("*").Select(EvaluateInteger).Aggregate(1,(a,b) => a*b);
}

private static int EvaluateInteger(string input)
{
return int.Parse(input);
}
}``````
Failed Tests

olimejj's Kumite #4

``````#just woke up from a random dream where I had a student explained to me this very simple algorythm.
#Seems pretty usless to me unless anybody can think of an actually use??
#crazy simple but the dream was so vivid I just had to put it down hahahaha
def power_rooter(num):
total = 1
while num > 1 and num//2 == num/2:
num = num / 2
total *= num
Failed Tests

Error message not fully shown

``````unit module Foo;
error-here``````

To Upper First

To Upper First

write a function that capitalize only the first letter of a string.

for example:
toUpperFirst "" == ""
toUpperFirst "finn the human" == "Finn the human"
toUpperFirst "alice" == "Alice"

``````module ToupperFirst where
import Data.Char

toUpperFirst ""    = ""
toUpperFirst xs    = [toUpper (x) | x <- xs, x == head (xs)] ++ tail (xs)``````

Python #1: Hello World

This is the start of a linear series of kata for learning Python. In this kata, you have to print "Hello World" to the screen.

Hint: Use the return keyword!

Rate 8 kyu!

``````def hello_world():
return "Hello World"``````

TimeSlotFinder

Dates/Time
Data Types

You have a starting time and duration of some activity and you have to find out if it fits in a given timeslot.

``````package com.codewars;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.function.Predicate;

public class TimeSlotFinder {

public boolean isSuitable(TimeSlot slot, String startTimeString, long durationInSecodns) {
LocalDateTime startTime = LocalDateTime.parse(startTimeString);
return Optional.of(slot)
.filter(startsBefore(startTime))
.filter(hasEnoughTimeLeftInSlot(startTime, durationInSecodns))
.isPresent();
}

public Predicate<TimeSlot> startsBefore(LocalDateTime startTime) {
return slot -> slot.startTime.isBefore(startTime) || slot.startTime.isEqual(startTime);
}

public Predicate<TimeSlot> hasEnoughTimeLeftInSlot(LocalDateTime startTime, long durationInSecodns) {
return slot -> ChronoUnit.SECONDS.between(startTime, slot.endTime) >= durationInSecodns;
}

public static class TimeSlot {
public final LocalDateTime startTime;
public final LocalDateTime endTime;
public final long durationInSeconds;

public TimeSlot(String dateTimeString, long durationInSeconds) {
this.startTime = LocalDateTime.parse(dateTimeString);
this.endTime = startTime.plus(durationInSeconds, ChronoUnit.SECONDS);
this.durationInSeconds = durationInSeconds;
}
}
}``````

Sort By Week

Dates/Time
Data Types

You are given an array of dates. Your task is group the dates into seperate weeks. The week starts on Monday, and ends on Sunday.

[
3/24/2021,
3/25/2021,
3/1/2021,
3/6/2021,
3/10/2021
]

expected output

[
[3/1/2021, 3/6/2021],
[3/10/2021],
[3/24/2021, 3/25/2021],
]

``````function groupByWeek(days) {
var dates = days.map(a => new Date(a)).sort((a, b) => b - a);

console.log(dates.map(a => (a.getMonth()+1) + "/" + a.getDate() + "/" + a.getFullYear()))

var currentMonday = new Date();
currentMonday.setDate(dates[0].getDate() - dates[0].getDay())

var currentSunday = new Date()
currentSunday.setDate(currentMonday.getDate() + 6);

//console.log(firstMonday.getDay())
//console.log(firstSunday.getDay())

var weeks = []
var currentWeek = []
for(var date of dates) {
if(date >= currentMonday && date <= currentSunday) {
currentWeek.push((date.getMonth()+1) + "/" + date.getDate() + "/" + date.getFullYear())
} else {
if(currentWeek.length > 0) {
weeks.push(currentWeek)
}
currentWeek = [(date.getMonth()+1) + "/" + date.getDate() + "/" + date.getFullYear()]
currentMonday.setDate(date.getDate() - date.getDay())
currentSunday.setDate(currentMonday.getDate() + 6);
}

}
if(currentWeek.length > 0) {
weeks.push(currentWeek)
}

return weeks

}``````