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
Ad

You find some interesting messages, but they are encrypted. Find a way to decrypt them!

In those messages, you find some pairs of encrypted - decrypted words.

rwdcoeas - codewars

ndcoig - coding

iaetmahmtc - mathematic

hagtyCrporpy - Cryptography

import math
def decrypt(message):
    # JUST DO IT
    return message

Frank like withdrawing a message after he sent it on a chatting channel. If the message is useful, Frank will withdraw it, while he will leave the unimportant message along.

So we need to write a bot to prevent Frank from withdrawing a message. If Frank withdraw something after saying it:

Frank: This message is useful!
Frank: Recalled a message

the bot should display(return) what Frank withdraw:

bot: Frank: This message is useful!

If Frank say something without withdrawing it:

Frank: I will not withdraw this message

the bot should not display anything:

module Kata (bot) where


bot :: String -> String
bot txt
  | length msgs < 2 = ""
  | head msgs == "Frank: Recalled a message" = "bot: " ++ (msgs !! 1)
  | otherwise = ""
  where msgs = reverse $ lines txt
Bugs

write a divide program

def div(num1, num2):
    return(num1 / num2)

Input any number and this will return what number is in that place in the Fibonacci sequence

def fibonacci(x):
    if x == 0:
        return 0 
    elif x == 1:
        return 1
    else :
        return fibonacci(x-1) + fibonacci(x-2)
Theoretical Computer Science
Mathematics
Algorithms
Logic
Numbers

In international chess, a knight is a chess piece which can move in an L-shape (possibly mirrored) of size 2x1 in any orientation. Due to its unique movement patterns, it is the only chess piece able to "jump" past chess pieces of any color that may be blocking its way.

However, what is more interesting is that its movement patterns allow it to move to any desired square on a given chessboard provided that no same-color chess piece is occupying that desired square. This Haskell program seeks to prove this statement, extending the chessboard to an infinite chessboard (in the rightwards and upwards directions) characterized by an ordered tuple of natural numbers.

{-# LANGUAGE KindSignatures, GADTs #-}

module KnightsOnAChessboard where

-- Peano's axioms for the natural numbers
data Z
data S n

-- Definition of natural numbers (to prevent nonsensical types like `S Bool`)
data Natural :: * -> * where
  NumZ :: Natural Z
  NumS :: Natural n -> Natural (S n)

-- Legal moves of a knight in international chess
data KnightCanReach :: * -> * where
  NoMoves :: KnightCanReach (Z, Z)
  MoveRL :: KnightCanReach (n, m) -> KnightCanReach (S (S n), S m)
  MoveRR :: KnightCanReach (n, S m) -> KnightCanReach (S (S n), m)
  MoveUL :: KnightCanReach (S n, m) -> KnightCanReach (n, S (S m))
  MoveUR :: KnightCanReach (n, m) -> KnightCanReach (S n, S (S m))
  MoveLL :: KnightCanReach (S (S n), S m) -> KnightCanReach (n, m)
  MoveLR :: KnightCanReach (S (S n), m) -> KnightCanReach (n, S m)
  MoveDL :: KnightCanReach (n, S (S m)) -> KnightCanReach (S n, m)
  MoveDR :: KnightCanReach (S n, S (S m)) -> KnightCanReach (n, m)

-- Proof that knight can reach any square on a chessboard starting from (0, 0)
knightCanMoveAnywhere :: Natural n -> Natural m -> KnightCanReach (n, m)
knightCanMoveAnywhere NumZ NumZ = NoMoves
knightCanMoveAnywhere NumZ (NumS n) =
  MoveDR $ MoveUL $ MoveRL $ knightCanMoveAnywhere NumZ n
knightCanMoveAnywhere (NumS n) m =
  MoveLL $ MoveRR $ MoveUR $ knightCanMoveAnywhere n m

Define a method/function that removes from a given array of integers all the values contained in a second array.

Examples:


int[] integerList = new int[]{ 1, 2, 2, 3, 1, 2, 3, 4 }
int[] valuesList = new int[]{ 1, 3 }
Kata.Remove(integerList, valuesList) == new int[]{ 2, 2, 4 } // --> true
int[] integerList = new int[]{ 1, 1, 2, 3, 1, 2, 3, 4, 4, 3 ,5, 6, 7, 2, 8 }
int[] valuesList = new int[]{ 1, 3, 4, 2 }
Kata.Remove(integerList, valuesList) == new int[]{ 5, 6 ,7 ,8 } // --> true
int[] integerList = new int[]{ 8, 2, 7, 2, 3, 4, 6, 5, 4, 4, 1, 2 , 3 }
int[] valuesList = new int[]{ 2, 4, 3 }
Kata.Remove(integerList, valuesList) == new int[]{ 8, 7, 6, 5, 1 } // --> true
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Kata
{
public static int[] Remove(int[] integerList,int[] valuesList)
	{
		if (integerList==null||integerList.length<1) return new int[0];
		if (valuesList==null||valuesList.length<1) return integerList;
		List<Integer> list= Arrays.stream(valuesList).boxed().collect(Collectors.toList());
		return Arrays.stream(integerList).filter(i->!list.contains(i)).toArray();
	} 
}
Theoretical Computer Science
Mathematics
Algorithms
Logic
Numbers

It is not uncommon to see a middle schooler incorrectly simplify the expression (a + b)^2 to a^2 + b^2 in his/her algebra assignments. While the two expressions may be equivalent for particular values of a and b (e.g. (0 + 0)^2 = 0^2 = 0 + 0^2 = 0^2 + 0^2), it is not true in general. So, how can we convince said middle-schooler that (a + b)^2 is not equal to a^2 + b^2 in general? This is equivalent to saying:

-- N.B. The domain of a, b is the natural numbers for
-- sake of simplicity
exists a b. (a + b)^2 /= a^2 + b^2

The general method for proving statements involving existential quantifiers is to provide a specific value or set of values such that the statement to be proven holds true - such value(s) are called witnesses. So, for example, we could provide the witnesses a = 1 and b = 1 in our case which reduces the statement to:

(1 + 1)^2 /= 1^2 + 1^2

And, of course, evaluating both sides of our equation gives 4 /= 2 which trivially holds.

Unfortunately, there is no direct way to encode existential quantifiers (and inequality) as a Haskell type. So what we could do is transform our original statement using known logical equivalences. The first thing to notice is that a /= b is defined as not (a = b) for any a, b:

exists a b. not ((a + b)^2 = a^2 + b^2)

Then, de Morgan's law for quantifiers tells us that exists a. not b is logically equivalent to not (forall a. b) for any b (which may or may not be related to a). Finally, to prove that not (forall a. b), it suffices to prove that asserting forall a. b leads to a contradiction (Void in Haskell). So our final type (minus a bit of required Haskell boilerplate code) is:

(forall a b. (a + b)^2 = a^2 + b^2) -> Void

See the code provided for the exact type signature of our proof and additional clarifications/explanations.

{-# LANGUAGE
  KindSignatures,
  GADTs,
  TypeOperators,
  TypeFamilies,
  UndecidableInstances,
  RankNTypes,
  EmptyCase #-}

module TheMiddleSchoolersMistake where

-- Void - the type representing contradictions in Haskell
import Data.Void

-- Peano's axioms for the natural numbers
data Z
data S n

data Natural :: * -> * where
  NumZ :: Natural Z
  NumS :: Natural n -> Natural (S n)

-- Axiom of reflexivity of equality: The very notion
-- of equality itself mandates that everything be
-- considered equal to itself
data (:=:) :: * -> * -> * where
  Refl :: a -> a :=: a

-- Peano addition, multiplication and exponentation
type family (:+:) (n :: *) (m :: *) :: *
type instance Z :+: n = n
type instance S n :+: m = S (n :+: m)

type family (:*:) (n :: *) (m :: *) :: *
type instance Z :*: n = Z
type instance S n :*: m = m :+: (n :*: m)

type family (:^:) (n :: *) (m :: *) :: *
type instance n :^: Z = S Z
type instance n :^: S m = n :*: (n :^: m)

-- Useful type synonyms for readability
type N1 = S Z -- The natural number 1
type N2 = S N1 -- The natural number 2
type N4 = N2 :+: N2 -- The natural number 4

-- Our proof that (a + b)^2 /= a^2 + b^2 in general
proof ::
  (forall n m.
    Natural n ->
    Natural m ->
    ((n :+: m) :^: N2) :=: ((n :^: N2) :+: (m :^: N2))) -> Void
proof mistake = let
  -- 1 is a natural number
  one :: Natural N1
  one = NumS NumZ
  -- To disprove (a + b)^2 = a^2 + b^2, we provide witnesses
  -- a = 1, b = 1 to our counterexample.  A witness is a
  -- value demonstrating the correctness of a logical statement
  -- involving existential quantifiers
  -- N.B. The witnesses could be anything else as long as it
  -- proves our point.  For example, we could've chosen a = 2,
  -- b = 3 instead and show that (2 + 3)^2 = 5^2 = 25 /= 13 =
  -- 2^2 + 3^2
  erroneous :: N4 :=: N2
  erroneous = mistake one one in
    -- Now we consider all possible cases where 4 = 2 and
    -- describe how to construct a proof of Void in each case
    -- However, there are no constructors that would allow us
    -- to construct a value of such a type!  The only possible
    -- constructor we could consider is Refl, but Refl always
    -- constructs values of a :=: a, never a :=: b where a and
    -- b are distinct types.  Therefore, we have already
    -- considered all (0) possible cases of 4 = 2 and we are
    -- done here.
    case erroneous of {}

Update getIDS to get the iterated digit sum.

The iterated digit sum of 1563 e.g is 1 + 5 + 6 + 3 = 15.

function getIDS($number) {
  return array_sum(str_split($number));
}

Write a function which would take two figures as a parameters and generate List of numbers which would contains figures from 1 fo n (n - first input) and lenght of each number should be equals to n .

Then return number at m position ( m - second input).
If number at that position doesn't exist return -1;

Examples :

Generator(2 ,3) => 11 12 21 22

should return 21

Generator(3, 10) => 111 112 113 121 122 123 131 132 133 211 212 213 221 222 223 231 232 233 311 312 313 321 322 323 331 332 333

should return 211

Good luck :)

using System;
using System.Linq;
using System.Collections.Generic;


public class NumbersFinder
{
    public static int Generator(int size , int position){
        if ( Math.Pow( size , size ) < position )
            return -1;
        List<string>  arr = new List<string>();
        for (int i = 0; i < size; ++i)
            arr.Add((i+1).ToString());
        List<string>  newArr;
        while (arr.Count != Math.Pow(size,size)){
            newArr = new List<string>();
            for (int j = 0; j < arr.Count; j++)
                for (int i = 0; i < size; i++)
                    newArr.Add(arr[j]+(i+1));
            arr.Clear();
            arr.AddRange(newArr);
        }
        return Convert.ToInt32(arr[position - 1]);
    }
}

Challenge

Implement a linked list function

const linkedList = {
  list: {},
  addNode: {}
}