A novel function to generate console formatted tables.
head = ["***", "Numbler =>", 40, 'another', "last"]
body = [
[ 1 , "B", "C", 2, 3],
["D", "E", "F", 4, 5]
]
t = table(body, head=head)
test = '''\
╭─────┬────────────┬────┬─────────┬──────╮
│ *** │ Numbler => │ 40 │ another │ last │
├─────┼────────────┼────┼─────────┼──────┤
│ 1 │ B │ C │ 2 │ 3 │
│ D │ E │ F │ 4 │ 5 │
╰─────┴────────────┴────┴─────────┴──────╯'''
Test.assert_equals(t, test)
print(t)
test.assert_equals(common_substring("Hello", "lo"), True) test.assert_equals(common_substring("HELLO", "hello"), False) test.assert_equals(common_substring("racecar", "car"), True) test.assert_equals(common_substring("CAR Car cAr caR", "car"), False) test.assert_not_equals(common_substring("rororororor", "roror"), False, ) test.expect(str,)
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)# You can use Test.describe and Test.it to write BDD style test groupings- test.assert_equals(common_substring("Hello", "lo"), True)
- test.assert_equals(common_substring("HELLO", "hello"), False)
- test.assert_equals(common_substring("racecar", "car"), True)
- test.assert_equals(common_substring("CAR Car cAr caR", "car"), False)
- test.assert_not_equals(common_substring("rororororor", "roror"), False, )
- test.expect(str,)
Algorithms
Logic
Algorithms
Logic
Numbers
Data Types
Integers
Algorithms
Logic
digits = lambda n : len(str(n))
// Removed loopfn digits (n: u64) -> usize{n.to_string().len()}- digits = lambda n : len(str(n))
test.describe("Powers of 10") test.assert_equals(digits(0), 1) n = 1 for i in range(1,21): n *= 10 test.assert_equals(digits(n), i+1) import sys test.assert_equals(digits(sys.maxsize), 19) test.describe("Powers of 10 minus 1") n = 1 for i in range(1,21): n *= 10 test.assert_equals(digits(n-1), i) test.describe("Powers of 10 half") n = 1 for i in range(1, 21): n *= 10 test.assert_equals(digits(n // 2), i)
#[test]fn pow10() {assert_eq!(digits(0), 1);let mut n = 1;assert_eq!(digits(1), 1);for i in 1..20 {n*=10;assert_eq!(digits(n), i+1);}assert_eq!(digits(std::u64::MAX), 20);}- test.describe("Powers of 10")
- test.assert_equals(digits(0), 1)
- n = 1
- for i in range(1,21):
- n *= 10
- test.assert_equals(digits(n), i+1)
- import sys
- test.assert_equals(digits(sys.maxsize), 19)
#[test]fn pow10_minus_1() {let mut n = 1;for i in 1..20 {n*=10;assert_eq!(digits(n - 1), i);}}#[test]fn pow10_half() {let mut n = 1;for i in 1..20 {n*=10;assert_eq!(digits(n / 2), i);}}- test.describe("Powers of 10 minus 1")
- n = 1
- for i in range(1,21):
- n *= 10
- test.assert_equals(digits(n-1), i)
- test.describe("Powers of 10 half")
- n = 1
- for i in range(1, 21):
- n *= 10
- test.assert_equals(digits(n // 2), i)
#define G(r,c) GetElement(r,c) double Matrix::GetValueOfDeterminant(){if((2==MaxRow)&&(2==MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);} else{double r=0;for(int c=1;c<=MaxCol;c++){int o=std::pow(-1,c); r+=GetCofactorMatrix(1,c).GetValueOfDeterminant()*G(1,c)*o;}return r;}}
- #define G(r,c) GetElement(r,c)
- double Matrix::GetValueOfDeterminant(){if((2==MaxRow)&&(2==MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);}
else{double r=0;for(int c=1;c<=MaxCol;c++){int PowOfNegativeOne=std::pow(-1,c);r+=GetCofactorMatrix(1,c).GetValueOfDeterminant()*G(1,c)*PowOfNegativeOne;}return r;}}- else{double r=0;for(int c=1;c<=MaxCol;c++){int o=std::pow(-1,c);
- r+=GetCofactorMatrix(1,c).GetValueOfDeterminant()*G(1,c)*o;}return r;}}
#define G(r,c) GetElement(r,c) double Matrix::GetValueOfDeterminant(){if((2==MaxRow)&&(2==MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);} else{double r=0;for(int c=1;c<=MaxCol;c++){int PowOfNegativeOne=std::pow(-1,c); r+=GetCofactorMatrix(1,c).GetValueOfDeterminant()*G(1,c)*PowOfNegativeOne;}return r;}}
- #define G(r,c) GetElement(r,c)
double Matrix::GetValueOfDeterminant(){if((2 == MaxRow)&&(2 == MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);}else{double ResultValue = 0;for(int c = 1;c <= MaxCol; c++){int PowOfNegativeOne = std::pow(-1, c);ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * G(1,c) * PowOfNegativeOne;}return ResultValue;}}- double Matrix::GetValueOfDeterminant(){if((2==MaxRow)&&(2==MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);}
- else{double r=0;for(int c=1;c<=MaxCol;c++){int PowOfNegativeOne=std::pow(-1,c);
- r+=GetCofactorMatrix(1,c).GetValueOfDeterminant()*G(1,c)*PowOfNegativeOne;}return r;}}
def fun(e): leet = { 'a': '@', 'b': '8', 'c': '(', 'd': '|)', 'e': '3', 'f': '|=', 'g': '6', 'h': '#', 'i': '!', 'j': ']', 'k': '|{', 'l': '1', 'm': 'em', 'n': '[\]', 'o': '0', 'p': '|*', 'q': '0,', 'r': '|2', 's': '$', 't': '7', 'u': '(_)', 'v': '\/', 'w': 'vv', 'x': '%', 'y': '`/', 'z': '2'} message = e leetmsg = '' message = message.lower() for c in message: try: leetmsg += leet[c] except: leetmsg += c return leetmsg
function fun(e) {var leet = {a: '@',b: '8',c: '(',d: '|)',e: '3',f: '|=',g: '6',h: '#',i: '!',j: ']',k: '|{',l: '1',m: 'em',n: '[\]',o: '0',p: '|*',q: '0,',r: '|2',s: '$',t: '7',u: '(_)',v: '\/',w: 'vv',x: '%',y: '`/',z: '2',}- def fun(e):
- leet = {
- 'a': '@',
- 'b': '8',
- 'c': '(',
- 'd': '|)',
- 'e': '3',
- 'f': '|=',
- 'g': '6',
- 'h': '#',
- 'i': '!',
- 'j': ']',
- 'k': '|{',
- 'l': '1',
- 'm': 'em',
- 'n': '[\]',
- 'o': '0',
- 'p': '|*',
- 'q': '0,',
- 'r': '|2',
- 's': '$',
- 't': '7',
- 'u': '(_)',
- 'v': '\/',
- 'w': 'vv',
- 'x': '%',
- 'y': '`/',
- 'z': '2'}
let message = e;let leetmsg = ''- message = e
- leetmsg = ''
message = message.toLowerCase();for(var a of message) {if (leet[a]) {leetmsg += leet[a];} else {leetmsg += char;}}return leetmsg}- message = message.lower()
- for c in message:
- try:
- leetmsg += leet[c]
- except:
- leetmsg += c
- return leetmsg
test.assert_equals(fun("string"), '$7|2![\\]6') test.assert_equals(fun("Do you even kumite?"), '|)0 `/0(_) 3\\/3[\\] |{(_)em!73?')
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.var leet = {a: '@', b: '8', c: '(', d: '|)', e: '3', f: '|=', g: '6', h: '#', i: '!', j: ']', k: '|{', l: '1', m: 'em', n: '[\]', o: '0', p: '|*', q: '0,', r: '|2', s: '$', t: '7', u: '(_)', v: '\/', w: 'vv', x: '%', y: '`/', z: '2'}let message = "string";let leetmsg = ''message = message.toLowerCase();for(var a of message) {if (leet[a]) {leetmsg += leet[a];} else {leetmsg += char;}}describe("Solution", function() {it("should test for something", function() {Test.assertEquals(fun(message), leetmsg);Test.assertEquals(fun(message), leetmsg);});});- test.assert_equals(fun("string"), '$7|2![\\]6')
- test.assert_equals(fun("Do you even kumite?"), '|)0 `/0(_) 3\\/3[\\] |{(_)em!73?')
#define G(r,c) GetElement(r,c) double Matrix::GetValueOfDeterminant(){if((2 == MaxRow)&&(2 == MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);} else{double ResultValue = 0;for(int c = 1;c <= MaxCol; c++){int PowOfNegativeOne = std::pow(-1, c); ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * G(1,c) * PowOfNegativeOne;}return ResultValue;}}
double Matrix::GetValueOfDeterminant(){if((2 == MaxRow)&&(2 == MaxCol)){return GetElement(1,1)*GetElement(2,2)- GetElement(1,2)*GetElement(2,1);}- #define G(r,c) GetElement(r,c)
- double Matrix::GetValueOfDeterminant(){if((2 == MaxRow)&&(2 == MaxCol)){return G(1,1)*G(2,2)-G(1,2)*G(2,1);}
- else{double ResultValue = 0;for(int c = 1;c <= MaxCol; c++){int PowOfNegativeOne = std::pow(-1, c);
ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * GetElement(1,c) * PowOfNegativeOne;}return ResultValue;}}- ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * G(1,c) * PowOfNegativeOne;}return ResultValue;}}