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.

Ad
BánkFailed Tests

Even or odd

const number = prompt("Enter a number: ");

if(number % 2 == 0){
  console.log("The number is even.");
}else{
  console.log("The number is odd.");
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");

describe("Solution", function() {
  it("should test for something", function() {
    // Test.assertEquals(1 + 1, 2);
    // assert.strictEqual(1 + 1, 2);
  });
});
.section .text
  .global solution
solution:
  la a0, msg
  tail preloaded_function

  .section .rodata
msg:
  .string "butterfly"
Games

It needs to store simple(so far) details about creatures and their immediate battles.

It is like an observer with extra steps.

class BattleMediator:
    CREATURES = {}

    def __init__(self, summoner) -> None:
        self.summoner = summoner  

    def update(self, attacker, enemy):        
        self.attacker = attacker
        self.enemy = enemy        
        self.add_creature()
    
    def add_creature(self):     
        if self.attacker not in __class__.CREATURES.keys():
            __class__.CREATURES[self.attacker] = {'initiated_attacks': 1, 'enemy': self.enemy}            
        else:
            __class__.CREATURES[self.attacker]['initiated_attacks'] += 1
            __class__.CREATURES[self.attacker]['enemy'] = self.enemy

    def unleash_earth_elemental(self):
        mould = EarthElemental()
        elemental = self.summoner.summon_elemental(mould)
        elemental.fight(self.attacker, self.enemy)

    def unleash_fire_elemental(self):
        mould = FireElemental()
        elemental = self.summoner.summon_elemental(mould)        
        elemental.fight(self.attacker, self.enemy)       

    def take_action(self):
        '''Unleashes Elementals based on how aggresive an attacker is'''
        if __class__.CREATURES[self.attacker]['fight'] % 2 == 0:            
            self.unleash_earth_elemental()

        if __class__.CREATURES[self.attacker]['fight'] % 7 == 0:
            self.unleash_fire_elemental()

            

class FireElemental:
    def fight(*args):
        pass

class EarthElemental:
    def fight(*args):
        pass

class Summoner:
    def summon_elemental(elemental: object):
        pass

Given a string s return an organized string in alphabetical order. Capital letters should be returned first. Number digits should be at the end of the returned string, and should be returned in numerical order. Ignore any special characters.

def sort(s):
    from string import ascii_lowercase, ascii_uppercase
    alphabet = list(ascii_uppercase) + list(ascii_lowercase) + list("0123456789")
    out = ""
    for letter in alphabet:
        for char in s:
            if char == letter:
                out += char
    return out

Looking for improvements, such as automated deletion or just some memory wasting projects :)

#include <iostream>
#include <string>
#include <ostream>
#include <fstream>
//mini .txt virus (160MB min!)
int main()
{
  std::cout << "Starting Amogus.exe" << '\n';
	for (int i{}; i < 1000; i++)
	{
		std::ofstream newip("Amogus" + std::to_string(i) + ".txt", std::ios::app);
		for (int j{}; j < 1000; j++)
		{
			for (int a{}; a < 10; a++)
			{
				newip << "sus ";
			}
			newip << '\n';
		}
		newip.close();
	}
  std::cout << "Done! enjoy deleting them now :)" << '\n';
  return 0;
}
//capiche?

The Code section has some functions to build some data.

The Test Cases describe the requirements.

The requirements are, fill out the four functions described in the Code section such that the Test Cases pass. For reference, the four functions are:

  • find_furthest_west()
  • get_latest_snapshot()
  • get_counts()
  • calculate_speeds()

There is no right or wrong. Don't spend too long. You don't need to make the tests pass if you don't want to spend much time. You can use pseudocode instead. It's a springboard for discussion, nothing more or less. We might not even have time to go through code together anyway.

"""Test equipment positions."""
from __future__ import annotations
from collections import Counter, defaultdict
import datetime as dt
import math
import numpy as np
import pandas as pd
from typing import Any


def data_dict() -> defaultdict[str, Any]:
    """Return all equipment positions."""
    d = defaultdict(list)
    d['T123'].append({'position': {'x': 42, 'y': 24, 'z': 0.42}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    d['T456'].append({'position': {'x': 21.0, 'y': 34, 'z': 0.289}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    d['T789'].append({'position': {'x': 17, 'y': 39, 'z': 0.789}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    d['T456'].append({'position': {'x': 91.0, 'y': 114, 'z': 0.489}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=3)})
    d['T123'].append({'position': {'x': 43, 'y': 25, 'z': 0.43}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=1)})
    d['T789'].append({'position': {'x': 19., 'y': 79, 'z': 0.991}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=6)})
    d['T123'].append({'position': {'x': 46, 'y': 29, 'z': 0.44}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=2)})
    d['T456'].append({'position': {'x': 24.0, 'y': 37, 'z': 0.297}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=4)})
    d['T123'].append({'position': {'x': 49.0, 'y': 32, 'z': 0.451}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=3)})
    d['T789'].append({'position': {'x': 23., 'y': 81, 'z': 1.103}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=7)})
    return d


def latest_snapshot() -> dict[str, Any]:
    """Return a snapshot of latest equipment."""
    return {
        'T123': {'position': {'x': 49.0, 'y': 32, 'z': 0.451}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=3)},
        'T456': {'position': {'x': 24.0, 'y': 37, 'z': 0.297}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=4)},
        'T789': {'position': {'x': 23.0, 'y': 81, 'z': 1.103}, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=7)},
    }


def counts() -> dict[str, int]:
    """Return counts per equipment."""
    return {
        'T123': 4,
        'T456': 3,
        'T789': 3
    }


def speeds() -> defaultdict[str, Any]:
    """Return speeds of equipment."""
    d = defaultdict(list)
    d['T123'].append({'speed': 4.242654947082074, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=3)})
    d['T123'].append({'speed': 5.00000999999, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=2)})
    d['T123'].append({'speed': 1.4142489172702237, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=1)})
    d['T123'].append({'speed': None, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    d['T456'].append({'speed': 102.0687849638664, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=4)})
    d['T456'].append({'speed': 35.43388209045123, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=3)})
    d['T456'].append({'speed': None, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    d['T789'].append({'speed': 4.473538196997986, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=7)})
    d['T789'].append({'speed': 6.6750796998987205, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=6)})
    d['T789'].append({'speed': None, 'timestamp': dt.datetime(2022, 1, 1, hour=12, minute=0, second=0)})
    return d

  
def find_furthest_west(d: defaultdict) -> str:
    """
    Find the name of the truck that is furthest west. That is,
    the truck with the smallest easting position component.
    """
    return ''

def get_latest_snapshot(d: defaultdict) -> dict[str, Any]:
    """
    Return a snapshot of the latest positional updates for the
    equipment.
    """
    return {}

def get_counts(d: defaultdict) -> dict[str, int]:
    """Return a dict of trucks and the times they have provided updates."""
    return {}

  
def calculate_speeds(d: defaultdict) -> defaultdict[str, Any]:
    """Return a dict of equipment and the speeds they are travelling at."""
    return defaultdict(list)
def f():
    a = [1,2,3,4,5]
    b = [4,5,6,7,8]

    c = []
    for i in a:
        if i not in b:
            c.append(i)
    
    return c

The user defined custom arithmetic function should be visible from plunit.
But then the directive in the .pl Code should be recognized also!
Why won't it allow it?

:- arithmetic_function(double/1).

double(N,M) :- M is N*2.
Fundamentals
Arrays

I was struggling with this Kata "Sum Of Positive".
On my computer:

Sum-OfPositive($test = @(1, 2, 3, 4, 5))
15

The function should work as intended, but I can't pass the tests.
What's wrong?

I am using Powershell 6.0.
On 7.2 will not pass for reasons which are unknown to me. Can someone also explain me why?

function Get-SumOfPositive($NumberArray)
{
$Sum =0;
foreach($Number in $NumbArray){
    if($Number -gt 0){
            $Sum+=$Number
        }
    }
Write-Output $Sum
}
def quine():
    q = '"' * 3
    s = """def quine():
    q = '"' * 3
    s = %s%s%s
    return s %% (q, s, q)
"""
    return s % (q, s, q)