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.
export interface iType{ id: number, name: string, } const datas: iType[] = [ { id: 1, name: "Manny" }, { id: 2, name: "Danny" }, { id: 3, name: "Socciella" }, ]; export function findData ( data: iType[],selectedData: number): iType | undefined { return data.find(item => item.id === selectedData); } findData(datas,1); findData(datas,2);
- export interface iType{
id: number,name: string,}export function findData (data: iType[], selectedData: number): iType {// You Can Code Here- id: number,
- name: string,
- }
}- const datas: iType[] = [
- {
- id: 1,
- name: "Manny"
- },
- {
- id: 2,
- name: "Danny"
- },
- {
- id: 3,
- name: "Socciella"
- },
- ];
- export function findData ( data: iType[],selectedData: number): iType | undefined {
- return data.find(item => item.id === selectedData);
- }
- findData(datas,1);
- findData(datas,2);
export function takeANumber (text: string): number { // Don't Change This Variable let result: number = parseInt(text.slice(1)); return result; } takeANumber("B0002") takeANumber("B0000001") takeANumber("B0000004")
- export function takeANumber (text: string): number {
- // Don't Change This Variable
let result: number = 0;// You Can Code Below Here- let result: number = parseInt(text.slice(1));
- return result;
}- }
- takeANumber("B0002")
- takeANumber("B0000001")
- takeANumber("B0000004")
fn sum(arr: &[i32]) -> i32 { arr.iter().sum() }
- fn sum(arr: &[i32]) -> i32 {
match arr.is_empty() {true => 0,false => arr[..].iter().sum::<i32>(),}- arr.iter().sum()
- }
#[cfg(test)] mod tests { use super::sum; #[test] fn test_sum() { assert_eq!(sum(&[1, 2, 3]), 6); } #[test] fn test_empty_sum() { assert_eq!(sum(&[]), 0); } }
- #[cfg(test)]
mod test {use super::*;- mod tests {
- use super::sum;
- #[test]
- fn test_sum() {
- assert_eq!(sum(&[1, 2, 3]), 6);
- }
- #[test]
- fn test_empty_sum() {
- assert_eq!(sum(&[]), 0);
- }
}- }
use itertools::Itertools; fn print(n: u64) -> u64 { n.to_string() .chars() .map(|c| c.to_digit(10).unwrap() as u64) .sorted() .rev() .fold(0, |acc, digit| acc * 10 + digit) }
- use itertools::Itertools;
- fn print(n: u64) -> u64 {
let mut digits = n.to_string()- n.to_string()
- .chars()
- .map(|c| c.to_digit(10).unwrap() as u64)
.collect::<Vec<u64>>();digits.sort();digits.into_iter()- .sorted()
- .rev()
- .fold(0, |acc, digit| acc * 10 + digit)
- }
#[cfg(test)] mod tests { use super::print; fn dotest(n: u64, expected: u64) { let actual = print(n); assert!(actual == expected, "print({n}) should return {expected}, but returned {actual}"); } #[test] fn simple_test() { dotest(4, 4); dotest(12, 21); dotest(101, 110); dotest(400000005000007000, 754000000000000000); dotest(307778062924466824, 988777666444322200); } }
- #[cfg(test)]
- mod tests {
use super::*;use rand::Rng;- use super::print;
fn dotest(n: u64, exp: u64) -> () {assert_eq!(print(n), exp, "{}", format!("{} should return {} ", n, exp));- fn dotest(n: u64, expected: u64) {
- let actual = print(n);
- assert!(actual == expected, "print({n}) should return {expected}, but returned {actual}");
- }
- #[test]
- fn simple_test() {
- dotest(4, 4);
- dotest(12, 21);
- dotest(101, 110);
- dotest(400000005000007000, 754000000000000000);
- dotest(307778062924466824, 988777666444322200);
}#[test]fn random_test() {let mut rng = rand::thread_rng();for _ in 0..10 {let n = rng.gen_range(1..100000);let exp = print(n);dotest(n, exp);}}- }
- }
The Train Driver is the most famous train driver of all Skyport. It is said they are the fastest and most handsome train driver. But they have a problem, they do not know hot to calculate the time properly.
As his/her assistant, your job is to figure out at what time they will arrive at their final destination, taking into account that they have to wait some time to prepare everytime before they start a trip.
You will be provided with a list of The Train Driver's destinations in order and the departure time from his starting station in Skyport.
Sometimes, the machine that prints the itinerary will give an empty list. In that case, that means The Train Driver has a day off.
If two identical cities a listed in a row, The Train Driver must wait there an hour in order to complain to his superior, The Mighty Boss.
ORIGIN | DESTINATION | STANDBY TIME | TRIP DURATION |
---|---|---|---|
Skyport | Crystalium | 15 min | 2 hours |
Crystalium | Skyport | 10 min | 2 hours |
Skyport | Oasis | 20 min | 3 hours |
Oasis | Skyport | 15 min | 3 hours |
Oasis | Crystalium | 15 min | 1.5 hours |
Crystalium | Oasis | 10 min | 1.5 hours |
Skyport | Nexus | 15 min | 4 hours |
Nexus | Skyport | 10 min | 4 hours |
EXAMPLES
["Crystalium"], "10:00" -> should return "12:15"
Skyport -> Crystalium: 15 minutes + 2 hours -> 12:15
["Crystalium", "Skyport", "Oasis"], "10:00" -> should return "17:45"
Skyport -> Crystalium: 15 minutes + 2 hours -> 12:15
Crystalium -> Skyport: 10 minutes + 2 hours -> 14:25
Skyport -> Oasis: 20 minutes + 3 hours -> 17:45
["Nexus", "Skyport", "Oasis"], "21:30" -> should return "09:15"
Skyport -> Nexus: 15 minutes + 4 hours -> 02:45
Nexus -> Skyport: 10 minutes + 4 hours -> 06:55
Skyport -> Oasis: 20 minutes + 3 hours -> 09:15
["Skyport"], "22:00" -> should return "23:00"
Skyport -> Skyport: 1 hour wait -> 23:00
["Crystalium", "Nexus"], "12:00" -> should return "20:40"
Skyport -> Crystalium: 15 minutes + 2 hours -> 14:15
Crystalium -> Skyport: 10 minutes + 2 hours -> 16:25
Skyport -> Nexus: 15 minutes + 4 hours -> 20:40
SPECIAL CASES
- If there are no destinations, return "The Train Driver has the day off".
- The Train Driver always starts his shift at Skyport.
- Whenever a train is taken, the waiting time must be added, even if it's the last destination.
- If there is no direct connection to his next destination, The Train Driver must return to Skyport as SkyPort has connection to all the other cities and then continue their journey from there. The time it takes to return to Skyport and the waiting time also count.
- If the next destination is the same city The Train Driver is already at, they must wait an hour before continuing.
- The expected format for the output is 'HH:mm'. '8:00' is not a valid format; instead, '08:00' should be returned.
import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; public class Kata { public static String arrivalTime(final String[] route, final String departureTime) { if (route.length == 0) return "The Train Driver has the day off"; LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm")); String origin = "Skyport"; int index = 0; while (index < route.length) { String destination = route[index]; Map<String, double[]> destinationMap = tableTime.get(origin); if (destinationMap != null && destinationMap.containsKey(destination)) { double[] times = destinationMap.get(destination); timeResult = calculateTime(timeResult, times); origin = destination; index++; } else if (origin.equals(destination)) { timeResult = timeResult.plusHours(1); index++; } else { String transfer = "Skyport"; double[] times = tableTime.get(origin).get(transfer); timeResult = calculateTime(timeResult, times); origin = transfer; } } return timeResult.format(DateTimeFormatter.ofPattern("HH:mm")); } private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() { { addRecord("Skyport", "Crystalium", 15, 2); addRecord("Skyport", "Oasis", 20, 3); addRecord("Oasis", "Crystalium", 15, 1.5); addRecord("Skyport", "Nexus", 15, 4); } private void addRecord(final String origin, final String destiny, final double minutesWait, final double hoursTravel) { putIfAbsent(origin, new HashMap<>()); get(origin).put(destiny, new double[] { minutesWait, hoursTravel }); putIfAbsent(destiny, new HashMap<>()); get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel }); } }; private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) { int minutes = (int) times[0]; int remainingMinutes = (int) (times[1] * 60); return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes); } }
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.HashMap;
- import java.util.Map;
- public class Kata {
- public static String arrivalTime(final String[] route, final String departureTime) {
- if (route.length == 0) return "The Train Driver has the day off";
- LocalTime timeResult = LocalTime.parse(departureTime, DateTimeFormatter.ofPattern("HH:mm"));
- String origin = "Skyport";
- int index = 0;
- while (index < route.length) {
- String destination = route[index];
- Map<String, double[]> destinationMap = tableTime.get(origin);
- if (destinationMap != null && destinationMap.containsKey(destination)) {
- double[] times = destinationMap.get(destination);
- timeResult = calculateTime(timeResult, times);
- origin = destination;
- index++;
- } else if (origin.equals(destination)) {
- timeResult = timeResult.plusHours(1);
- index++;
- } else {
- String transfer = "Skyport";
- double[] times = tableTime.get(origin).get(transfer);
- timeResult = calculateTime(timeResult, times);
- origin = transfer;
- }
- }
- return timeResult.format(DateTimeFormatter.ofPattern("HH:mm"));
- }
- private static Map<String, Map<String, double[]>> tableTime = new HashMap<String, Map<String, double[]>>() {
- {
- addRecord("Skyport", "Crystalium", 15, 2);
- addRecord("Skyport", "Oasis", 20, 3);
- addRecord("Oasis", "Crystalium", 15, 1.5);
- addRecord("Skyport", "Nexus", 15, 4);
- }
private void addRecord(final String origin, final String destiny, final double minutesWait,- private void addRecord(final String origin, final String destiny, final double minutesWait,
- final double hoursTravel) {
- putIfAbsent(origin, new HashMap<>());
- get(origin).put(destiny, new double[] { minutesWait, hoursTravel });
- putIfAbsent(destiny, new HashMap<>());
- get(destiny).put(origin, new double[] { minutesWait - 5, hoursTravel });
- }
- };
- private static LocalTime calculateTime(final LocalTime currentTime, final double[] times) {
- int minutes = (int) times[0];
- int remainingMinutes = (int) (times[1] * 60);
- return currentTime.plusMinutes(minutes).plusMinutes(remainingMinutes);
- }
- }