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.

If printing's all you're going to do, no need to save the result to a variable.

Code
Diff
  • def multiplica(a, b):
        return a * b
    print(multiplica(4, 5))
  • 11
    def multiplica(a, b):
    
    22
        return a * b
    
    3
    resultado = multiplica(4, 5)
    
    4
    print(resultado)
    
    3+
    print(multiplica(4, 5))
    

Recent Moves:

Fundamentals
Numbers
Integers
Code
Diff
  • public static class Kata
    {
        public static bool IsOdd(int input)
        {
          bool Odd  = false;
          if (input % 2 == 0)
              Odd = false;
          else 
            Odd = true;
            return  Odd; 
        }
    }
  • 11
    public static class Kata
    
    22
    {
    
    33
        public static bool IsOdd(int input)
    
    44
        {
    
    5
            return input % 2 != 0 ? true : false;
    
    5+
          bool Odd  = false;
    
    6+
          if (input % 2 == 0)
    
    7+
              Odd = false;
    
    8+
          else 
    
    9+
            Odd = true;
    
    10+
            return  Odd; 
    
    66
        }
    
    77
    }
    

Recent Moves:

A friend had showed this too me a couple of days ago on TeleHack.com (which you all should check out). It uses lambda to print the numbers in the fibonacci sequence.

#To print a specific term in the sequence
f = lambda a, b: (a lambda: f(b, a + b))
g = f(0, 1)

n = int(input('What term?: '))

for i in range(1, n):
    g = g[1]()
    print(g[0])

#To print the sequence upto this term
f = lambda a, b: (a lambda: f(b, a + b))
g = f(0, 1)

n = int(input('What term?: '))

for i in range(1, n):
    g = g[1]()
    print(g[0]) #Simply just tabbing this into the for loop
Mathematics
Algorithms
Numbers

The task: make an array of arrays which store n rows of pascal's triangle, where each entry is each successive row starting from the 0th row. For all n < 0, you can return an empty array.

Examples (with whitespace added for clarity):

pascal-triangle(-1) == []

pascal-triangle(0) == [
  [1]
]

pascal-triangle(1) == [
  [1],
  [1, 1]
]

...

pascal-triangle(3) == [
  [1],
  [1, 1],
  [1, 2, 1],
  [1, 3, 3, 1]
]

... etc
USING: arrays combinators kernel locals math math.ranges sequences ;
IN: pascal

: pascal-index ( n seq -- elt/0 )
  ?nth dup not [ drop 0 ] when ;
  
:: pascal-add ( seq n -- m )
  n 1 - seq pascal-index
  n seq pascal-index
  + ;

:: pascal-next ( arr -- arr' )
  arr empty? [
    { { 1 } }
  ] [
    arr ?last :> lastarr
    lastarr length 1 + :> newlen
    { } :> curr!
    
    newlen [0,b) [| n |
      curr lastarr n pascal-add suffix curr!
    ] each
    
    arr curr suffix
  ] if ;

:: pascal-triangle ( n -- arr ) 
  { } n 1 + [ pascal-next ] times ;

The odds of winning are approxtimately 1 in 1.7556^82527 chance of success. There is a much lower chance of success than winning the lottery 1000 times in a row (assuming the odds of the lottery are 1 in 302 million). Insane.

This can show you the odds:
https://www.calculator.net/big-number-calculator.html?cx=7.8567773e%2B61&cy=1000&cp=20&co=pow

Code
Diff
  • import string
    import random
    
    def greet():
        helloWorlds = []
        for i in range(1000):
            helloWorlds.append("".join(map(chr, (random.randrange(0x10ffff) for i in range(12)))))
        for s in helloWorlds:
            if s != "hello world!":
                return "Fail!"
        return "hello world!"
  • 11
    import string
    
    22
    import random
    
    33
    44
    def greet():
    
    5
        first = "".join(map(chr, (random.randrange(0x10ffff) for i in range(12))))
    
    6
        if first == "hello world!":
    
    7
            second = "".join(map(chr, (random.randrange(0x10ffff) for i in range(12))))
    
    8
            if second == "hello world!":
    
    9
                third = "".join(map(chr, (random.randrange(0x10ffff) for i in range(12))))
    
    10
                if third == "hello world!":
    
    11
                    fourth = "".join(map(chr, (random.randrange(0x10ffff) for i in range(12))))
    
    12
                    if fourth == "hello world!":
    
    13
                        fifth = "".join(map(chr, (random.randrange(0x10ffff) for i in range(12))))
    
    14
                        return fifth
    
    15
        return "Fail!"
    
    5+
        helloWorlds = []
    
    6+
        for i in range(1000):
    
    7+
            helloWorlds.append("".join(map(chr, (random.randrange(0x10ffff) for i in range(12)))))
    
    8+
        for s in helloWorlds:
    
    9+
            if s != "hello world!":
    
    10+
                return "Fail!"
    
    11+
        return "hello world!"
    

Recent Moves: