Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
Fundamentals
Code
Diff
  • using System;
    
    public class Kata {
      public static int Opposite(int n) => -n;
    }
  • 11
    using System;
    
    22
    3
    public class Kata
    
    4
        {
    
    5
            public static int Opposite(int n)
    
    6
            {
    
    7
                return -n;
    
    8
            }
    
    9
        }
    
    3+
    public class Kata {
    
    4+
      public static int Opposite(int n) => -n;
    
    5+
    }
    
Code
Diff
  • Solution=_=>"Hello World"
    
  • 1
    function Solution() {return "Hello World"}
    
    1+
    Solution=_=>"Hello World"
    
Mathematics
Algorithms
Numbers
Code
Diff
  • powerdistance(x)=2x-1
  • 1
    power_distance=lambda x:2*x-1
    
    1+
    powerdistance(x)=2x-1
    
Mathematics
Algorithms
Numbers
Code
Diff
  • power_distance=lambda x:2*x-1
  • 1
    power_distance = lambda x: 2 * x - 1
    
    1+
    power_distance=lambda x:2*x-1
    

just messing with you :>

module Kumite where

main = do
  putStrLn "<DESCRIBE::>Kumite\n<PASSED::>Test Passed\n"
  print $ if if if if if True then True else False then True else False then True else False then True else False then 1 else 0

:D

Code
Diff
  • divisors=lambda n:[x for x in range(1,n+1)if n%x<1]
  • 1
    divisors=lambda n:[x for x in range(1,n+1)if n%x==0]
    
    1+
    divisors=lambda n:[x for x in range(1,n+1)if n%x<1]
    

Control.Lens is mind-bogglingly powerful.
Just playing with this amazing thing.

module Kumite where

import Control.Lens

main = do
  print $ (1, 2, 3) ^.. each
  print $ map (^..each) [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
  print $ both ^~ 2 $ (1,2,3,4)
  print $ mapped._2 %~ succ . (* 2) $ [(1,2),(3,4)]
  print $ over (mapped._2) succ [(1,2),(3,4)]
  print $ (10,20) ^. _2
  print $ _1 .~ "i changed this" $ ((), "world")
Code
Diff
  • const findMax = a => Math.max(...a);
  • 1
    function find_max(arr){
    
    2
    	maxNum = arr[0];
    
    3
    	arr.forEach((ele)=>{
    
    4
    		if(ele > maxNum){
    
    5
    			maxNum = ele;
    
    6
    		}
    
    7
    	})
    
    8
    	return maxNum;
    
    9
    }
    
    1+
    const findMax = a => Math.max(...a);
    
Code
Diff
  • f=str.__mul__
  • 1
    Kata=lambda x,y: x*y
    
    2
    3
    # Alternative:
    
    4
    # def Kata(string, num):
    
    5
    #     return string*num
    
    1+
    f=str.__mul__
    

Let's rename the function to max.

Code
Diff
  • #
  • 1
    f=max
    
    1+
    #
    

30

Code
Diff
  • toiletRolls=(r,d,m)=>r>=d*m/20
  • 1
    toilet_rolls=lambda r,d,m:r>=d*m/20
    
    1+
    toiletRolls=(r,d,m)=>r>=d*m/20
    
Fundamentals
Code
Diff
  • def find_special(jar, special):
        if not isinstance(jar, list) or special not in jar:
            return
        return [special, *filter(special.__ne__, jar)]
  • 11
    def find_special(jar, special):
    
    2
        if not isinstance(jar, list) or not isinstance(special, (int, float)) or special not in jar:
    
    3
            return None
    
    4
        jar = jar[:]
    
    5
        jar.remove(special)
    
    6
        jar.insert(0, special)
    
    7
        return jar
    
    2+
        if not isinstance(jar, list) or special not in jar:
    
    3+
            return
    
    4+
        return [special, *filter(special.__ne__, jar)]
    
Fundamentals

Please no input validation.

Code
Diff
  • find_special=lambda j,s:[s,*filter(s.__ne__,j)]
  • 1
    def find_special(jar, special):
    
    2
        if not isinstance(jar, list) or not isinstance(special, (int, float)) or special not in jar:
    
    3
            return None
    
    4
        jar = jar[:]
    
    5
        jar.remove(special)
    
    6
        jar.insert(0, special)
    
    7
        return jar
    
    1+
    find_special=lambda j,s:[s,*filter(s.__ne__,j)]
    
Arrays
Strings
Numbers
Code
Diff
  • const smallBigNum = (s, a) => typeof s === "string" ? [Math.max(...a = s.match(/\d/g)), Math.min(...a)] : [];
  • 1
    def small_big_num(infos):
    
    2
        if isinstance(infos, int): return []
    
    3
        elif isinstance(infos, str):
    
    4
            infos = [int(i) for i in infos if i.isdigit()]
    
    5
            return [max(infos), min(infos)]
    
    6
        
    
    1+
    const smallBigNum = (s, a) => typeof s === "string" ? [Math.max(...a = s.match(/\d/g)), Math.min(...a)] : [];
    
Loading more items...