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.

Type Initializers

When you define a derived data type in GNU Fortran, you are automatically given a type initializer which allows you to initialize an instance of your derived data type in one go. One can think of a type initializer as a primitive type of constructor. However, custom-defined constructors weren't available until Fortran 2003 so it may not be available in GNU Fortran (which is an extension of the Fortran 95 standard).

module Solution
  implicit none
  type Vec3D ! A three-dimensional vector
    integer :: x, y, z
  end type Vec3D
  type(Vec3D) :: v = Vec3D(1, 2, 3) ! Using the type initializer provided by Fortran
end module Solution

This Kumite is created to test JQuery support on Codewars.

var jsdom = require("jsdom/lib/old-api.js");

jsdom.env(
    '<!DOCTYPE html><p>Hello world</p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a>', ["http://code.jquery.com/jquery.js"],
    function(err, window) {
        console.log(window.document.querySelector("p").textContent);
        var $ = window.$;

        $.getJSON('https://www.codewars.com/users/Javatlacati', null, function(data) {
            console.log(data);
        }).error(function(e) {
            console.log("first attempt failed\n" + JSON.stringify(e));
        });



        var name = "kazk";
        var url = "http://anyorigin.com/go?url=" + encodeURIComponent("https://www.codewars.com/users/") + name + "&callback=?";
        $.get(url, function(response) {
            console.log(response);
        }).error(function(e) {
            console.log("second attempt failed\n" + JSON.stringify(e));
        });
        console.log("contents of a.the-link:", window.$("a.the-link").text());
    }
);

Dynamic Memory Allocation by using C library malloc() function

It is possible to allocate memory dynamically in NASM (obviously, otherwise how would it be possible in C and other higher-level languages?) and the easiest way to do it is probably by relying on the C library function malloc().

global one_two_three
extern malloc ; C library function malloc()
section .text
one_two_three:
  mov rdi, 12 ; size_t bytes_required = 3 * sizeof(int) == 12 (because sizeof(int) == 4 on CW)
  call malloc ; int *result = malloc(bytes_required)
  mov dword [rax], 1 ; result[0] = 1 (`dword` means "double word" where 1 word = 2 bytes)
  mov dword [rax + 4], 2 ; result[1] = 2
  mov dword [rax + 8], 3 ; result[2] = 3
  ret ; return result

Recent Moves:

Actually, that was double -> int, now int -> double.

Code
Diff
  • global to_double
    section .text
    to_double:
                    cvtsi2sd    xmm0, edi
                    ret
    
  • 1
    global trunc_
    
    1+
    global to_double
    
    22
    section .text
    
    3
    trunc_:
    
    4
                    cvttsd2si   eax, xmm0
    
    3+
    to_double:
    
    4+
                    cvtsi2sd    xmm0, edi
    
    55
                    ret
    

Recent Moves:

String literals are stored as read-only (const), and any attempt to modify the pointer returned will result in a SEGFAULT (crash) in most current computing environments.

Obvserving the following assembly output from GCC:

	.file	"tst.c"
	.text
	.section	.rodata
.LC0:
	.string	"Hello World."
	.text
	.globl	Hi
	.type	Hi, @function
Hi:

You can see string literal referred to by label .LC0 is defined within section '.rodata' meaning ready-only data.

Therefore Hi() should have a return type of const char* to avert the possibility of such faulty access occurring.

Code
Diff
  • const char* Hi (void)
    {
      return("Hello World.");
    }
    
    char *oopsHi(void)
    {
      return ("Hello World.");
    }
    
  • 1
    char* Hi (void)
    
    1+
    const char* Hi (void)
    
    22
    {
    
    3
    return("Hello World.");
    
    3+
      return("Hello World.");
    
    4+
    }
    
    5+
    6+
    char *oopsHi(void)
    
    7+
    {
    
    8+
      return ("Hello World.");
    
    44
    }
    
Code
Diff
  • syntax error here again
  • 1
    syntax error here
    
    1+
    syntax error here again