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

minified.

Code
Diff
  • >,+[-[-<+>>>+<<]>>>+[[-]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->[-]>>+>+<<<]]]]]]]]]<]>>[>]++++++[-<++++++++>]>>]<<<[.[-]<<<]<[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<]
    • >,+
    • [-
    • [-<+>>>+<<]>>>+
    • [[-]<
    • [->+<
    • [->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<
    • [->[-]>>+>+<<<]
    • ]]]]]]]]<
    • ]>>[>]++++++[-<++++++++>]>>
    • ]<<<[.[-]<<<]
    • <[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<
    • ]
    • >,+[-[-<+>>>+<<]>>>+[[-]<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->+<[->[-]>>+>+<<<]]]]]]]]]<]>>[>]++++++[-<++++++++>]>>]<<<[.[-]<<<]<[->+>[-]+<<]>>[+++[->++++++++<]>.[-]<]<]

Statement

Given a number n, the function, add all the multiples 3 and 5 in the range [1, n).

Example:

Say, n <- 10

In the range [1, 10):

  • multiples of 3 are 3, 6 and 9.
    • 3 + 6 + 9 = 18
  • There's only one multiple of 5 which is 5 itself, as we are only supposed to count from 1 to n - 1.

Total sum is 18 + 5 = 23.

Note: if a number is a multiple of both 3 and 5, it should be added only once.

Input:

10

Output:

23

Code
Diff
  • package kata
    
    func AddMultiples(n int) (sum int) {
      for i := 1; i < n; i++ {
        if i % 3 == 0 || i % 5 == 0 {
          sum += i 
        }    
      }
      return
    }
    • package kata
    • func Multiple3And5(number int) int {
    • sum := 0
    • for i:= 1;i< number;i++{
    • if i%3==0||i%5==0{
    • sum += i
    • func AddMultiples(n int) (sum int) {
    • for i := 1; i < n; i++ {
    • if i % 3 == 0 || i % 5 == 0 {
    • sum += i
    • }
    • }
    • return sum
    • return
    • }
Code
Diff
  • from random import getrandbits
    
    
    class RandomBool(object):
    
        def __init__(self):
            self.b = bool(getrandbits(1))
    
        def __repr__(self):
            return f'{self.b}'
    • from random import choice
    • class Random_Bool:
    • @staticmethod
    • def r():
    • return choice((True, False))
    • from random import getrandbits
    • class RandomBool(object):
    • def __init__(self):
    • self.b = bool(getrandbits(1))
    • def __repr__(self):
    • return f'{self.b}'
Strings

Maybe it is my bias for having some dictionary, for the sake of extensibility

Code
Diff
  • using System.Collections.Generic;
    public class ColorAdder
    {
      private static Dictionary<string,int> codes = new(){
        { "Red", 31},
        { "Green", 32},
        { "Yellow", 33},
        { "Blue", 34},
        { "Magenta", 35},
        { "Cyan", 36},
        { "White", 37}
      };
        public static string AddColor(string color, string text)
          => codes.TryGetValue(color, out int v) ? $"\033[{v}m{text}\033[0m" :"";
        
    }
    
    • using System.Collections.Generic;
    • public class ColorAdder
    • {
    • private static Dictionary<string,int> codes = new(){
    • { "Red", 31},
    • { "Green", 32},
    • { "Yellow", 33},
    • { "Blue", 34},
    • { "Magenta", 35},
    • { "Cyan", 36},
    • { "White", 37}
    • };
    • public static string AddColor(string color, string text)
    • {
    • string Reset = "\033[0m";
    • return color switch{
    • "Red" => $"\033[31m{text}{Reset}",
    • "Green" => $"\033[32m{text}{Reset}",
    • "Yellow" => $"\033[33m{text}{Reset}",
    • "Blue" => $"\033[34m{text}{Reset}",
    • "Magenta" => $"\033[35m{text}{Reset}",
    • "Cyan" => $"\033[36m{text}{Reset}",
    • "White" => $"\033[37m{text}{Reset}",
    • _ => ""
    • };
    • }
    • => codes.TryGetValue(color, out int v) ? $"\033[{v}m{text}\033[0m" :"";
    • }

It looks like it it trying to walk-through the directories of a .venv virtual enviornment folder.

I prefer to use the os.walk method.
In order to filter and flatten the array I'm using of the list comprehensions.
I ignore error in the reading

Code
Diff
  • import os
    DIR = os.path.join(os.getcwd(), 'venv')
    
    def list_venv():
        tree_of_files = ([([ os.path.join(root, some_f)  for some_f in  files] ) for root, _, files in os.walk(DIR) if(len(files)>0)])
        flatten_tree_of_files= [ a_file for subtree in tree_of_files for a_file in subtree ]
        for some_file in flatten_tree_of_files:
            with open(some_file,  mode='r', errors='ignore') as file:
                print(file.read())
        return True
    
    list_venv()
    • import os
    • DIR = os.path.join(os.getcwd(), 'venv')
    • def list_venv():
    • """ List venv dirs and files """
    • try:
    • print((ve := os.listdir(DIR)))
    • for x in ve:
    • list_subs(x)
    • except:
    • print("Error: venv dir not found in the path")
    • def list_subs(x):
    • """ For files in venv, which will be (Libs, and Scripts) """
    • try:
    • # subdirs
    • print(x, os.listdir(os.path.join(DIR, x)))
    • for y in x:
    • list_sub_sub(x, y)
    • except:
    • print_config(x)
    • def list_sub_sub(x, y):
    • """ List subdirs and files in subdirs
    • Warning: the next code was full of
    • `This does not get executed` messages """
    • try:
    • print(x, os.listdir(os.path.join(DIR, x, y)))
    • for z in y:
    • try:
    • print_file(x, y) # not y, z?
    • except:
    • print("...goes on...")
    • except:
    • try:
    • print_file_fallback(x)
    • except:
    • print("") # This gets executed (the only one!)
    • def print_file(x, y):
    • with open(os.path.join(DIR, x, y), 'r') as file:
    • print(file.read())
    • tree_of_files = ([([ os.path.join(root, some_f) for some_f in files] ) for root, _, files in os.walk(DIR) if(len(files)>0)])
    • flatten_tree_of_files= [ a_file for subtree in tree_of_files for a_file in subtree ]
    • for some_file in flatten_tree_of_files:
    • with open(some_file, mode='r', errors='ignore') as file:
    • print(file.read())
    • return True
    • def print_file_fallback(x):
    • with open(os.path.join(DIR, x), 'r') as file:
    • print(file.read())
    • def print_config(x):
    • """ This will get executed twice, opening
    • the .gitignore, and pyvenv.cfg file """
    • with open(os.path.join(DIR, x), 'r') as file:
    • print(file.read())
    • list_venv()
    • list_venv()
Code
Diff
  • ring = ''.join(''.join([chr(i+7)]*j) for i,j in zip([90,110,96,97],[5,3,2,4]))
    • ring = ''.join(chr(i+7) for i in [90, 90, 90, 90, 90, 110, 110, 110, 96, 96, 97, 97, 97, 97])
    • ring = ''.join(''.join([chr(i+7)]*j) for i,j in zip([90,110,96,97],[5,3,2,4]))
Code
Diff
  • feed_the_primates_v1 = lambda a,f: [['🍌']*len(list(filter({"🐒","🦍"}.__contains__, a))), 'No bananas!'][f.count("🍌") == 0] 
    feed_the_primates_v2 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]
    • feed_the_primates_v1 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]
    • banana = "🍌"
    • feed_the_primates_v2 = lambda a,f: 'No bananas!' if banana not in set(f) else [banana for m in a if m in {"🐒", "🦍"} and banana in f]
    • # other option being: replacing banana as inline value
    • feed_the_primates_v1 = lambda a,f: [['🍌']*len(list(filter({"🐒","🦍"}.__contains__, a))), 'No bananas!'][f.count("🍌") == 0]
    • feed_the_primates_v2 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]