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.

Oho, you forgot to write a newline!

Code
Diff
  • import sys
    sys.stdout.write("Hello Python!\n")
  • 11
    import sys
    
    2
    sys.stdout.write("Hello Python!")
    
    2+
    sys.stdout.write("Hello Python!\n")
    

Recent Moves:

(format t "Welcome to Common Lisp, made with secret alien technology.")
Recursion
Algorithms
Computability Theory
Theoretical Computer Science
Arrays
Methods
Functions
Object-oriented Programming
Control Flow
Basic Language Features
Fundamentals
Classes

Array#flip method:

This kumite is a script that "flips" an Array's contents. Rather than simply Array#reverse it. Here's an example:

[1,2,3,[4,5,6],7,8,9].reverse #=> [9,8,7,[4,5,6],3,2,1]
[1,2,3,[4,5,6],7,8,9].flip    #=> [9,8,7,[6,5,4],3,2,1]
 #                                          ^

It's as if you've physically turned around an array. This goes for any smaller arrays within the Array given, so recursion may be on the cards.

I've done a neat little script (If you don't mind me saying!) carrying out this task. Please feel free to refactor, comment and feedback; I find critisism indispensible.

As a sidenote, maybe we could implement this for Hash as well? Maybe {:hello => "world"} should become {"world" => :hello}?

class Array # Opens up the Array class for method creation
  def flip
    result = []
    me = self.reverse # Don't fret, I'll sort the Arrays out!
    
    me.each do |x|
      
      if x.class == Array then result << x.flip # Here's the recursion.
      else result << x
      end
      
    end
    
    return result
  end
end
greet = "Hello Ruby!"

print           greet, "\n"
puts            greet
$stdout.write   greet +"\n"
$stdout.puts    greet
$stdout.print   greet, "\n"
Code
Diff
  • #include <iostream>
    
    int main(){
      
      std::cout << "Hello C++" << std::endl;
      
    }
  • 11
    #include <iostream>
    
    22
    33
    int main(){
    
    44
      
    
    5
      std::cout << "Hello C++" << endl;
    
    5+
      std::cout << "Hello C++" << std::endl;
    
    66
      
    
    77
    }
    

Recent Moves: