Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

from hex to 1 dec
'a:2:35:af:1' -> 10 + 2 + 53 + 175 + 1 -> 241
'b:356:3af:cba24:100' -> 11 + 854 + 943 + 834084 + 256 -> 836148

decr = lambda a: sum([int(h,16) for h in a.split(':')])
Code
Diff
  • rubegoldberg=lambda:int(__import__('inspect').getsource(rubegoldberg)[-2]);1
  • 1
    def rubegoldberg():
    
    2
        return 1
    
    1+
    rubegoldberg=lambda:int(__import__('inspect').getsource(rubegoldberg)[-2]);1
    

Recent Moves:

Find your way to discover an "a1", the inverse of the key(a1: a^(-1)), without using the brute-force loop like the example code
Then return the secret text

Note: a x a1 = 1 (modulo 26)
Example: 7 x -11 = 1 (modulo 26) >> a1 = -11

In order to find the secret text:
secret_text = ""
for c in ciphertext:
e = (a1 * (char2num(c) - b)) % m
secret_text = secret_text + num2char(e)

def char2num(c):
return ord(c) - 65

def num2char(n):
return chr(n + 65)

def a_little_decryption(a, b, m, ciphertext):
    secret_text = ""
    a1 = None
    for i in range(0, m):
        if (a*i)%m == 1:
            a1 = i
            break
    for c in ciphertext:
        e = (a1 * (char2num(c) - b)) % m
        secret_text = secret_text + num2char(e)
    return secret_text
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays

How did I miss this?

Code
Diff
  • def get_primes(n):    
        bpr = [0,1] * ((n+1)//2) + [0] * (1 - (1 * 1&n))
        bpr[:3] = [0, 0, 1]
        for i in range(3, 1+ int(n**0.5), 2):
            if bpr[i]:
                ipi, isq = i*2, i*i
                bpr[isq::ipi] = [0] * (( n - isq)//ipi + 1)
        return [2] + [i for i in range(3,n,2) if bpr[i]]
  • 11
    def get_primes(n):    
    
    22
        bpr = [0,1] * ((n+1)//2) + [0] * (1 - (1 * 1&n))
    
    33
        bpr[:3] = [0, 0, 1]
    
    44
        for i in range(3, 1+ int(n**0.5), 2):
    
    55
            if bpr[i]:
    
    66
                ipi, isq = i*2, i*i
    
    77
                bpr[isq::ipi] = [0] * (( n - isq)//ipi + 1)
    
    8
        return [i for i, x  in enumerate(bpr) if x]
    
    9
     
    
    8+
        return [2] + [i for i in range(3,n,2) if bpr[i]]
    

Don't reinitialize static property, instead, reference it.

During first execution, it'll be created with a null value. Right after creation, since it's null the Null Coalescing Assignment Operator will give us a new anonymous class and return a new instance of itself.

On following executions, the static property will be referenced, and since it already exists, it will not be reset to null. Since it's not null, the class assignment will be skipped, and will jump right to return a new instance.

Code
Diff
  • function a() {
      static $poi;
      $poi ??= new class {
         public function create() {
            return new static();
         }
      };
      return $poi->create();
    }
  • 1
    function a(){
    
    2
      // We shall remove the following solution when publish as KATA
    
    3
      static $poi = null;
    
    4
      if ($poi) return $poi->create();
    
    5
      $poi = new class {
    
    1+
    function a() {
    
    2+
      static $poi;
    
    3+
      $poi ??= new class {
    
    66
         public function create() {
    
    77
            return new static();
    
    88
         }
    
    99
      };
    
    1010
      return $poi->create();
    
    1111
    }
    
Fundamentals
Basic Language Features
Arrays

There is an array of numbers.

Let's assume that we delete every M-th element of the array, starting from the first element.

After the first loop, the process is repeated until the last element is left (the function must return the remaining element).

For example, if the length of the array is N=9 and if every M=5 is deleted, the last element will be element 8 (#8).

Input: N-length of the array, M-delete each M-th element!

public class Kata
{
    public static int ReturnsTheLastElement(int n, int m)
    {
      // Here's your code))
    }
}