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.

### Find maximum number that can be formed using digits of a given number

Skipped the string-building part and did a sum instead.

For an array of chars `[48+5, 48+6, 48+7]` you have an array of numeric values `[5, 6, 7]` which leads to `5 * 10^0 + 6 * 10^1 + 7 * 10^2 = 765` (which is the maximum and the equivalent of reversing the string)

Added a test for execution time performance (if that is a concern)
and a test for random values

Code
Diff
• ``````import java.util.Arrays;

public class MaxNumber {
public static long print(long number) {
long sum = 0;

String numStr = String.valueOf(number);
char[] digits = numStr.toCharArray();
Arrays.sort(digits);

// here the digits are sorted in ascending order
for (int i = 0; i < digits.length; i++) {
sum += Math.round( Character.getNumericValue(digits[i]) * Math.pow(10, i) );
}
return sum;
}
}``````
• import java.util.Arrays;
• public class MaxNumber {
• public static long print(long number) {
• long sum = 0;
• String numStr = String.valueOf(number);
• char[] digits = numStr.toCharArray();
• Arrays.sort(digits);
• StringBuilder sortedStr = new StringBuilder(new String(digits));
• return Long.parseLong(sortedStr.reverse().toString());
• // here the digits are sorted in ascending order
• for (int i = 0; i < digits.length; i++) {
• sum += Math.round( Character.getNumericValue(digits[i]) * Math.pow(10, i) );
• }
• return sum;
• }
• }

### Calculate fines based on a speed limit and an array of driver speeds.

Functional Programming
Algorithms
Mathematics
Code
Diff
• ``````export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => {
return driverSpeeds.map(speed => CalculateFine(speed, speedLimit));
}
const CalculateFine = (speed: number, limit: number) => {
if(speed >= limit + 30) return 500
if (speed >= limit + 20 && speed <= limit + 29) return 250
if (speed >= limit + 10 && speed <= limit + 19) return 100
return 0
}``````
• export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => {
• return driverSpeeds.map(speed => CalculateFine(speed, speedLimit));
• }
• const CalculateFine = (speed: number, limit: number) => {
• if(speed > limit + 30) return 500
• if (speed > limit + 20 && speed < limit + 29) return 250
• if (speed > limit + 10 && speed < limit + 19) return 100
• if(speed >= limit + 30) return 500
• if (speed >= limit + 20 && speed <= limit + 29) return 250
• if (speed >= limit + 10 && speed <= limit + 19) return 100
• return 0
• }

### Show the current date

Date Time
Code
Diff
• ``````function ShowDate() {
const days = {'1':'st','2':'nd','3':'rd'};
const date = new Date().toLocaleDateString('en', {month: 'long', day: 'numeric', year: 'numeric'})
const dateFixed = date.replace(',', days[new Date().getDate()]?? 'th')
return dateFixed
}``````
• function ShowDate() {
• const months = {'Jan':'January','Feb':'February','Mar':'March','Apr':'April','May':'May',
• 'Jun':'June','Jul':'July','Aug':'Augest','Sep':'September','Oct':'October',
• 'Nov':'November','Dec':'December'};
• const days = {'1':'st','2':'nd','3':'rd'};
• return new Date().toDateString().slice(4).split(' ').map((e,i) => i?i==1?+e+(days[e.slice(-1)]||'th'):e:months[e]).join(' ');
• const date = new Date().toLocaleDateString('en', {month: 'long', day: 'numeric', year: 'numeric'})
• const dateFixed = date.replace(',', days[new Date().getDate()]?? 'th')
• return dateFixed
• }

### Fix the code

i fixed it

Code
Diff
• ``````use std::arch::asm;

#[cfg(target_arch = "x86_64")]
pub fn multiply(a: usize, b: usize) -> usize {
let mut result: usize;
unsafe {
asm!(
"mov {result}, 0",
"2:",
"dec {b}", // i mean like no ones gonna notice if we modify it :3
"cmp {b}, 0",
"ja 2b",
a = in(reg) a,
b = in(reg) b,
result = out(reg) result,
);
}

result
}``````
• fn multiply(a: usize, b: usize) -> usize {
• a * b
• use std::arch::asm;
• #[cfg(target_arch = "x86_64")]
• pub fn multiply(a: usize, b: usize) -> usize {
• let mut result: usize;
• unsafe {
• asm!(
• "mov {result}, 0",
• "2:",
• "dec {b}", // i mean like no ones gonna notice if we modify it :3
• "cmp {b}, 0",
• "ja 2b",
• a = in(reg) a,
• b = in(reg) b,
• result = out(reg) result,
• );
• }
• result
• }

### one number multiplication table, and you enter that number.

Code
Diff
• ``````#include <stdio.h>
prnt_mltply(m,n){for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)printf("%d * %d = %d\n",i,j,i*j);return m*n;}``````
• #include <stdio.h>
• int prnt_mltply(int m, int n) {
• for (int i = 0; i < m; i++) for (int j = 1; j <= n; j++) printf("%d * %d = %d
• ", i + 1, j, (i+1) * j);
• return m * n;
• }
• prnt_mltply(m,n){for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)printf("%d * %d = %d
• ",i,j,i*j);return m*n;}

### Python 101 - Hello World - 1 (C++)

Code
Diff
• ``````#include <iostream>
#include <string>
using namespace std;

bool helloWorld() {
return [](const string &H, const string &W){
return (cout << H << W << endl).good();
}("Hello, ", "World!");
}``````
• //Created by RHB
• #include <iostream>
• #include <string>
• using namespace std;
• int main() {
• string H, W;
• H="Hello ";
• W="World!";
• cout << H << W << endl;
• return 0;
• bool helloWorld() {
• return [](const string &H, const string &W){
• return (cout << H << W << endl).good();
• }("Hello, ", "World!");
• }

### Non Repeating Character Optimization

Code
Diff
• ``firstNonRepeatingCharacter=s=>(j=s.split``,r=j.reduce((o,c)=>(o[c]=(o[c]??0)+1,o),{}),j.find(c=>r[c]==1)??null)``
• const firstNonRepeatingCharacter = (str) => {
• let counts = {};
• for(const char of str) {
• counts[char] = 1 + (counts[char] ? counts[char] : 0);
• }
• for(const char in counts) {
• if(counts[char] == 1) {
• return char;
• }
• }
• return null;
• }
• firstNonRepeatingCharacter=s=>(j=s.split``,r=j.reduce((o,c)=>(o[c]=(o[c]??0)+1,o),{}),j.find(c=>r[c]==1)??null)