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
Code
Diff
  • f=lambda n:[n-10,91][n<101]
    • f=lambda n: 91 if n <= 100 else n - 10
    • f=lambda n:[n-10,91][n<101]
Fundamentals
Strings
Data Types
Algorithms
Logic

A few less spaces...

Code
Diff
  • palindrome=lambda w:str(w)==str(w)[::-1]
    
    • palindrome = lambda w: str(w)==str(w)[::-1]
    • palindrome=lambda w:str(w)==str(w)[::-1]

Assumes entry lists are sorted !!

Code
Diff
  • #include <list>
    
    auto merge_list(const std::list<int>& a, const std::list<int>& b) {
      std::list<int> o{a};
      for(auto i : b) o.insert(std::lower_bound(o.begin(), o.end(), i), i);
      return o;
    }
    • #include <algorithm>
    • #include <list>
    • #include <execution>
    • #include <iterator>
    • auto merge_list(const std::list<int>& a, const std::list<int>& b) {
    • std::list<int> o;
    • std::merge(
    • std::execution::seq,
    • a.begin(),
    • a.end(),
    • b.begin(),
    • b.end(),
    • std::back_inserter(o)
    • // std::less is default sort
    • );
    • std::list<int> o{a};
    • for(auto i : b) o.insert(std::lower_bound(o.begin(), o.end(), i), i);
    • return o;
    • }
Fundamentals
Functional Programming
Declarative Programming
Programming Paradigms
Higher-order Functions
Functions
Control Flow
Basic Language Features
  • Added 3 more test cases
  • Follwing problem description:
    Counting from 1 to n, then back to 1
  • Wait, why am I doing this?
Code
Diff
  • module NumberPrint where
    
    numberprint :: Int -> Integer
    numberprint n = read . concat $ show <$> [1 .. pred n] <> [n, pred n .. 1]
    • module NumberPrint where
    • numberprint :: Int -> Integer
    • numberprint = read . (>>= id) . ((++) <*> (reverse . init)) . (\x -> show <$> [1..x])
    • numberprint n = read . concat $ show <$> [1 .. pred n] <> [n, pred n .. 1]
Games
Algorithms
Logic
Combinators
Functional Programming
Combinatory Logic
Functions
Declarative Programming
Programming Paradigms
Computational Science
Theoretical Computer Science
Control Flow
Basic Language Features
Fundamentals
Design Patterns

Combinators are useful.
I'd like a safe tail function though.
EDIT: drop could be used instead.

<*> is S combinator.

  • For A <*> B, parameter is piped to both A and B
  • and then, they are applied
  • i.e. A <*> B = \x -> (A x) (B x)
Code
Diff
  • module Platforms where
    
    platforms :: [Integer] -> Integer
    platforms = sum . fmap abs . (zipWith (-) <*> drop 1)
    • module Platforms where
    • platforms :: [Integer] -> Integer
    • platforms (x:y:xs) = abs (x - y) + platforms (y:xs)
    • platforms _ = 0
    • platforms = sum . fmap abs . (zipWith (-) <*> drop 1)
Iterators
Control Flow
Object-oriented Programming
Basic Language Features
Fundamentals
Programming Paradigms
Monads
Data Structures
Functional Programming

Pattern matching on number is lame, so implemented using a list.

  • Pattern
    • on each step, 2 is multipled on each element
    • 1 is added in between
  • (iterate step initial !!) could be used to get result of application n times
  • List monad is great!
  • View pattern is unnecessary now.
Code
Diff
  • module Code (powerfulArray) where
    
    import Data.List
    
    powerfulArray :: Int -> [Int]
    powerfulArray = (iterate next [] !!) where next l = 1 : (do n <- l; [2 * n, 1])
    • {-# Language ViewPatterns #-}
    • module Code (powerfulArray) where
    • import Data.List
    • powerfulArray :: Int -> [Int]
    • powerfulArray 0 = []
    • powerfulArray (pred -> n) = arrayN ++ 2^n : arrayN
    • where arrayN = powerfulArray n
    • powerfulArray = (iterate next [] !!) where next l = 1 : (do n <- l; [2 * n, 1])