Mathematics
Algorithms
Logic
Numbers
Data Types
global double_multiplication
section .text
double_multiplication:
xor edx,edx
mov eax,edi
mul esi
ret
#include <stdio.h>
#include <criterion/criterion.h>
int double_multiplication(int a, int b);
Test(add_test, should_add_integers) {
cr_assert_eq(double_multiplication(1, 1), 1);
}
Fundamentals
Fundamentals
using System; public class Kata { public static int Opposite(int number) => ~number + 1; }
- using System;
- public class Kata
- {
public static int Opposite(int number) => -number;- public static int Opposite(int number) => ~number + 1;
- }
using NUnit.Framework; [TestFixture] public class MyTest { [Test] public void Test_1() { Assert.AreEqual(-1, Kata.Opposite(1)); Assert.AreEqual(-100, Kata.Opposite(100)); Assert.AreEqual(1000, Kata.Opposite(-1000)); } }
- using NUnit.Framework;
- [TestFixture]
- public class MyTest
- {
- [Test]
- public void Test_1()
- {
- Assert.AreEqual(-1, Kata.Opposite(1));
- Assert.AreEqual(-100, Kata.Opposite(100));
- Assert.AreEqual(1000, Kata.Opposite(-1000));
- }
- }
Fundamentals
Fundamentals
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
import math def get_primes(num): prime_list = list() limit = int(math.sqrt(num - 1)) bool_list = list() for i in range(0, num - 1): bool_list.append(True) for i in range(2, limit): if bool_list[i]: for x in range (i * i, num - 1, i): bool_list[x] = False for i in range(2, num - 1): if bool_list[i]: prime_list.append(i) return prime_list
import numpy as npdef get_primes(n):bpr = np.ones(n)bpr[:2] = bpr[4::2] = 0v = 1 + int(n**0.5)for i in range(3, v, 2):if bpr[i]:bpr[i*i::i+i] = 0return list(np.nonzero(bpr)[0])- import math
- def get_primes(num):
- prime_list = list()
- limit = int(math.sqrt(num - 1))
- bool_list = list()
- for i in range(0, num - 1):
- bool_list.append(True)
- for i in range(2, limit):
- if bool_list[i]:
- for x in range (i * i, num - 1, i):
- bool_list[x] = False
- for i in range(2, num - 1):
- if bool_list[i]:
- prime_list.append(i)
- return prime_list
test.assert_equals(get_primes(10), [2, 3, 5, 7]) test.assert_equals(get_primes(50), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]) test.assert_equals(get_primes(100), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]) test.assert_equals(len(get_primes(10_000)), 1229) test.assert_equals(len(get_primes(1_000_000)), 78498) test.assert_equals(len(get_primes(10_000_000)), 664579) # test.assert_equals(len(get_primes(49_979_688)), 3000000)
- test.assert_equals(get_primes(10), [2, 3, 5, 7])
- test.assert_equals(get_primes(50), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])
- test.assert_equals(get_primes(100), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97])
- test.assert_equals(len(get_primes(10_000)), 1229)
- test.assert_equals(len(get_primes(1_000_000)), 78498)
- test.assert_equals(len(get_primes(10_000_000)), 664579)
test.assert_equals(len(get_primes(49_979_688)), 3000000)- # test.assert_equals(len(get_primes(49_979_688)), 3000000)
- Just playing around with the testing framework with NASM. I am more than happy to add to this if anyone wants it to become a Kata, just let me know. Thanks.
Change the case of the inputted letter.
If it is not a letter in the A-Z Alphabet, then just return the input character unchanged
section .text
global changeCase
changeCase:
xor ax,ax ; Initialize ax Return Register
cmp di,0x41 ; Compare input char (di Register) to 0x41 (A)
jge _Possible_Letter1 ; If greater than or equal to 0x41, jump to Possible_Letter1
_Return_NonValid_Char:
mov ax,di ; Mov nonvalid letter into ax Return Register
ret ; Return ax Register
_Possible_Letter1:
cmp di,0x5A ; Compare input char (di Register) to 0x5A (Z)
jg _Possible_Letter2 ; If greater than 0x51, jump to _Possible_Letter2
jmp _ChangeCase ; Confirmed Letter otherwise, go to ChangeCase
_Possible_Letter2:
cmp di,0x61 ; Compare input char (di Register) to 0x61 (a)
jl _Return_NonValid_Char ; Invalid Character, return input, jump to _Return_NonValid_Char
cmp di,0x7A ; Compare input char (di Register) to 0x7A (z)
jg _Return_NonValid_Char ; Invalid Character, return input, jump to _Return_NonValid_Char
jmp _ChangeCase ; Valid Character, go to _ChangeCase
_ChangeCase:
xor di, 0x20 ; ChangeCase of character by running XOR on the input register & 0x20
mov ax, di ; Mov the final modified/case-changed input to ax
ret ; Return ax Register
#include <criterion/criterion.h>
char changeCase(char*letter);
Test(changeCase, should_change_the_char_case) {
cr_expect(changeCase('a') == 'A');
cr_expect(changeCase('q') == 'Q');
cr_expect(changeCase('T') == 't');
cr_expect(changeCase('z') == 'Z');
cr_expect(changeCase('@') == '@');
cr_expect(changeCase('1') == '1');
cr_expect(changeCase('^') == '^');
}