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.

Fundamentals
Numbers
Mathematics
Algorithms

Quick Science Lesson:
There are four major types of temparature scales (Celsius, Kelvin, Fahrenheit, and Rankine).

To convert Celsius to Kelvin simply add 273.15
EX:
3°C = 276.15K
To convert Celsius to Fahrenheit simply multiply by 9/5 and add 32
EX:
3°C = 37.4°F
To convert Celsius to Rankine simply multiply by 9/5 and add 491.67
EX:
3°C = 497.07°R

NOTE: Remember you can convert from different if you wanted

Actual Program:
Basically you will be given three parameters: initial temperature (float), source scale (string), and target scale (string) from which you will have to convert a result.

Ex #1:
Input:
21, 'r', 'c'
Output:
-261
Ex #2:
Input:
234.21, 'f', 'r'
Output:
693
Ex #3:
Input:
-122, 'k', 'c'
Output:
-395

NOTE: Make sure you return only ints

Code
Diff
  • # the affine transformations of the form "y = a*x + b"
    # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F)
    convert = {
        "c": (1.0, -273.15),
        "r": (1.8,    0.0 ),
        "f": (1.8, -459.67),
        "k": (1.0,    0.0 ),
    }
    
    def temperature_convert(temp, source, target):
        # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a
        temp = (temp - convert[source][1]) / convert[source][0]
        # convert Kelvins to target unit, rounded to integer
        return int(temp * convert[target][0] + convert[target][1])
  • 11
    # the affine transformations of the form "y = a*x + b"
    
    22
    # from Kelvin (k) to Celsius (c), Rankine (r) or Fahrenheit (F)
    
    3
    from_kelvin = {
    
    4
        "c": {"a": 1.0, "b": -273.15},
    
    5
        "r": {"a": 1.8, "b": 0.0},
    
    6
        "f": {"a": 1.8, "b": -273.15 * 1.8 + 32.0},
    
    7
        "k": {"a": 1.0, "b": 0.0},
    
    3+
    convert = {
    
    4+
        "c": (1.0, -273.15),
    
    5+
        "r": (1.8,    0.0 ),
    
    6+
        "f": (1.8, -459.67),
    
    7+
        "k": (1.0,    0.0 ),
    
    88
    }
    
    99
    10
    11
    def temperature_convert(params):
    
    12
        value, src, tgt = params
    
    10+
    def temperature_convert(temp, source, target):
    
    1313
        # convert source unit to Kelvins : invert from_kelvin, x = (y - b) / a
    
    14
        value_in_k = (value - from_kelvin[src]["b"]) / from_kelvin[src]["a"]
    
    12+
        temp = (temp - convert[source][1]) / convert[source][0]
    
    1515
        # convert Kelvins to target unit, rounded to integer
    
    16
        return int(value_in_k * from_kelvin[tgt]["a"] + from_kelvin[tgt]["b"])
    
    14+
        return int(temp * convert[target][0] + convert[target][1])
    

Recent Moves:

Lists
Data Structures
Numbers
Functions
Control Flow
Basic Language Features
Fundamentals
Algorithms

Two bytes shorter.

Code
Diff
  • combine_list=lambda a,b:[x for x in{*a,*b}if x>0]
  • 1
    combine_list=lambda a,b:[x for x in set(a+b)if x>0]
    
    1+
    combine_list=lambda a,b:[x for x in{*a,*b}if x>0]
    

Recent Moves:

enumerating over vector, equivelent to python's enumerate(list)

#include <vector>
#include <tuple>
#include <iostream>

template <class T>
void enumerate(std::vector<T> A)
{
    for(auto [a,i]=std::tuple{A.begin(), 0}; a < A.end(); a++, i++)
   { 
    std::cout << i << ":" << *a << "\n";
   }
}

Iterating over two vectors at the same time till end of one of them

#include <vector>
#include <tuple>
#include <iostream>
template <class T, class U>
void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
{

   for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++) 
   { 
    std::cout << *a << ":" << *b << "\n";
   }
}

Macro to get max of two integers
can be used as a new pseudo-command

; A macro with two parameters
; Implements actual int max(int a, int b)
%macro _max 2 
  cmp %2, %1 ; compare a ?= b
  jle _lower ; jump to lower if a <= b
  jmp _greater ; jump to greater if a > b
  
  _lower:
    mov rax, %1 ; assgine rax to b
    jmp _end ; end program
  _greater:
    mov rax, %2 ; assgine rax to a
  _end:
  ret
  
%endmacro

section .text
global max ; declaring int max(int a, int b)

max:            
  _max rdi, rsi ; using inner _max macro 
  ret

Get Max of two integers

section .text
global max ; declare max function
max:            ; int max(int a, int b)
  cmp rdi, rsi ; compare a ?= b
  jle _lower  ; jump to lower if a <= b
  jmp _greater ; jump to greater if a > b
  _lower:
    mov rax, rsi ; assgine rax to b
    jmp _end ; end program
  _greater:
    mov rax, rdi ; assgine rax to a
  _end:
  ret