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

Game of Life :

The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.

Game of Life

Your task is to write a program to calculate the next generation of Conway's game of life, given any starting position.
You start with a two dimensional grid of cells, where each cell is either alive or dead.
The grid is finite, and no life can exist off the edges.
When calculating the next generation of the grid, follow these four rules:

  1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
  2. Any live cell with more than three live neighbours dies, as if by overcrowding.
  3. Any live cell with two or three live neighbours lives on to the next generation.
  4. Any dead cell with exactly three live neighbours becomes a live cell.

Examples: * indicates live cell, . indicates dead cell

Example input: (4 x 8 grid)
........
....*...
...**...
........

Example output:
........
...**...
...**...
........
function nextGeneration(grid) {
  return grid.map((row, rowIndex) => {
    return row.map((cell, colIndex) => {
      if (rowIndex !== 0 && colIndex !== 0 && rowIndex < grid.length - 1 && colIndex < row.length - 1) {
        let neighboursCount = 0;
        if (grid[rowIndex][colIndex + 1] === 1) neighboursCount++;
        if (grid[rowIndex][colIndex - 1] === 1) neighboursCount++;
        if (grid[rowIndex + 1][colIndex] === 1) neighboursCount++;
        if (grid[rowIndex - 1][colIndex] === 1) neighboursCount++;
        if (grid[rowIndex + 1][colIndex + 1] === 1) neighboursCount++;
        if (grid[rowIndex + 1][colIndex - 1] === 1) neighboursCount++;
        if (grid[rowIndex - 1][colIndex + 1] === 1) neighboursCount++;
        if (grid[rowIndex - 1][colIndex - 1] === 1) neighboursCount++;
      
        if (cell === 1) {
          if (neighboursCount === 2 || neighboursCount === 3 ) {
            return 1;
          }
        } else {
          if (neighboursCount === 3 ) {
            return 1;
          }
        }
        return 0;
      }
      return 0;
    });
  });
}
Puzzles
Games
Mathematics
Algorithms
Logic
Numbers
Data Types
Sequences
Arrays

Description

The Kolakoski Sequence is a infinite string of integers that describes it own construction. Each digit, in order, encodes the size of the run that some digit in the sequence appears.

The inital terms of the sequence seeded by [1,2] are:

1, 2, 2, 1, 1, 2, 1, 2, 2...

Notice that there is one 1, followed by two 2s, then two 1s. In general the repitition of digits can be described as:

1, 2, 2, 1, 1, 2, 1, 2, 2...

Or the sequence itself. That is the idea you will be exploring in this excercise.

Instructions

Task 1:

Generate_Kolakoski_Seq(seed, n)
Write a function that takes an array of symbols as a seed, and an integer n, and produces the Kolakoski Sequence for that seed up to the nth digit as a common separted string.

Generate_Kolakoski_Seq( [2,3], 11 )

returns "2,2,3,3,2,2,2,3,3,3,2"

Generate_Kolakoski_Seq( [2], 5 )

returns "2,2,2,2,2"

Task 2:

Find_Kolaskoski_Number(seed, n)
Write a function that takes an array of symbols and a large integer n, and returns the nth digit of the sequence as an integer.

Find_Kolaskoski_Number( [1,2], 10000 )

returns: 1

(There is a way to compute this without computing the whole sequence)

// takes int[] and int, returns string (comma seperated integers)
function Generate_Kolakoski_Seq(seed, n){

}


// takes int[] and int, returns int
function Find_Kolaskoski_Number(seed, n){

}
Arrays
Data Types

Function will recive N for length of array and point as index to pint at in that array.


For example, function should generate arrays like this for


N = 10, point = 7
[7,6,5,4,3,2,1,0,1,2]


N = 10, point = 4
[4,3,2,1,0,1,2,3,4,5]

function func(N, point) {
  let start = 0; // starting position of array
  let clonePoint = point; // clone for point to start counting from that number at begining of array
  let arr = [...Array(N).keys()] // generate array and fill with 0 to 10
  if(!(point > N)) {
    arr.forEach((o, index) => {
      index < point ? arr[index] = clonePoint-- : arr[index] = start++;
    });
    return arr;
  }
  return [];
}
use Math;

proc chebyshev(n: int, v: real) : real
{
  if (v > 1) {
    return cosh(n * acosh(v));
  } else if (v < -1) {
    return (-1) ** n * cosh(n * acosh(-v));
  } else {
    return cos(n * acos(v));
  }
}

Hello World in Julia, since there's nothing on codewars ⊙﹏⊙.

println("Hello Julia!")
const hello = "world"
// add the values "codewars" to the websites array
var websites = ['codears'];

A simple algorithm in Brainf**k that receives exactly 1 byte of input and prints it out as a numerical string. For example: "H" -> "72". Note that this algorithm only works for byte values up to 99 though - it won't handle three-digit bytes properly.

This program might be somewhat useful in writing a short and concise program that prints out the lyrics to "99 bottles of beer" since the lyrics are highly repetitive and involves printing out a lot of numbers in descending order. However, upon second thought, it might not be that useful at all since my program fails to preserve its input :p

,[->>+>+>>-<<----------[[+]>>+<<]>>[[+]<<<----------<+>>>>]<<<[->+>+<<]>>[-<<+>>]<<<<]>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]>++++++++++++++++++++++++++++++++++++++++++++++++.
Mathematics
Algorithms
Logic
Numbers

If we have planty of objects like this: ['a', 'b', 'c']
then we can build all permutation:

0 – abc
1 – acb
2 – bac
3 – bca
4 – cab
5 – cba

Any of them permutations may be calculated by their index number without calculated others.

import math


class SequencePermutation(object):
    def __init__(self, plenty_object, count_item):
        self.plenty_object = list(plenty_object)
        self.count_item = count_item
        self.power_plenty = len(plenty_object)

    @staticmethod
    def calc_count_permutation(n, k):
        return int(math.factorial(n) / math.factorial(n - k))

    def __getitem__(self, index):
        current_mod = index
        plenty = self.plenty_object.copy()
        for i in range(self.count_item - 1):
            perm_count = self.calc_count_permutation(self.power_plenty - i - 1, self.count_item - i - 1)
            current_index = current_mod // perm_count
            yield plenty[current_index]
            plenty.pop(current_index)
            current_mod = current_mod % perm_count
        yield plenty[current_mod]

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

function calculate_multiples {

    $SUM = 0

    1..999 | ForEach-Object {
        if (!( $_ % 3) -OR !($_ % 5)) {
            $Sum += $_
        }
    }

  return $Sum
}
Puzzles
Games
Sequences
Arrays
Data Types
Arithmetic
Mathematics
Algorithms
Logic
Numbers
Recursion
Computability Theory
Theoretical Computer Science

The Ulam Sequence is a recursive sequence that begins with two numbers; for example [1, 2]. The next number in the sequence is the smallest unique sum of any 2 numbers in the sequence.

Example:
[u0, u1] = [1, 2]
u2 = 1 + 2 = 3 --> [1, 2, 3]
u3 = 1 + 3 = 4 --> [1, 2, 3, 4]
u4 = 4 + 2 = 6 --> [1, 2, 3, 4, 6]

Notice that 5 is left out. Though 5 is smaller than 6, 5 can be written as a sum in 2 different ways: 4 + 1 and 3 + 2; therefore, it is not unique; whereas, 6 is unique since it is only the sum of 4 + 2.

Write a code that generates an Ulam Sequence of length n and starts with u0, u1.

Ex:
f(u0=1, u1=2, n=10) = [1, 2, 3, 4, 6, 8, 11, 13, 16, 18]

def ulam_sequence(u0, u1, n):
    u = [u0, u1]
    nn = u[-1] + 1
    while len(u) < n:
        count = 0
        for i in u:
            if nn - i in u and nn - i != i:
                count += 1
            if count >= 3:
                break
                nn += 1
        if count == 2:
            u.append(nn)
        nn += 1
    return u