#include <stdbool.h> bool odd_even(int n) { return n < 0 || n > 1 ? odd_even(n + 2 * (n < 0 ? 1 : -1)) : !n; }
- #include <stdbool.h>
- bool odd_even(int n)
- {
int r = 0, p[1] = {0};goto owo;uwu:*&*p = (&r)[0];goto miau;owo:*(int*)((void*)&r) = n%2;goto uwu;miau:return !(*p&1) ? true : false;- return n < 0 || n > 1 ? odd_even(n + 2 * (n < 0 ? 1 : -1)) : !n;
- }
#include <stdlib.h> #include <string.h> char *fanis(char *r, int k) { char *w = malloc(strlen(r) + 1), *p = w; while(w && *r) *p++ = k + *r++; return w; }
- #include <stdlib.h>
- #include <string.h>
char *fanis(char* r, int k) {char *w = malloc(strlen(r)+1);if (!w)- char *fanis(char *r, int k) {
- char *w = malloc(strlen(r) + 1), *p = w;
- while(w && *r) *p++ = k + *r++;
- return w;
char *p = w;while (*r)*p++ = k + *r++;return w;- }
#include <string.h> #include <stdlib.h> char *fanis(char *r, int k) { char *w = malloc(strlen(r) + 1), *p = w; if(w) while(*r) *p++ = k + *r++; return realloc(w, strlen(w) + 1); }
- #include <string.h>
- #include <stdlib.h>
char *fanis(char* r, int k) {char* w = malloc(strlen(r) + 1);if (w != NULL) {char* p = w;while (*r) { *p++ = k + *r++;}*p = '\0'; w = realloc(w, strlen(w) + 1);}return w;}- char *fanis(char *r, int k) {
- char *w = malloc(strlen(r) + 1), *p = w;
- if(w) while(*r) *p++ = k + *r++;
- return realloc(w, strlen(w) + 1);
- }
Sets
dumbRockPaperScissors=lambda a,b:"Draw"if a==b else f"Player {(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins"
def dumbRockPaperScissors(player1, player2):Rock = {"Paper"}Paper = {"Scissors"}Scissors = {"Rock"}if player1 in eval(player2):return "Player 1 wins"elif player2 in eval(player1):return "Player 2 wins"else:return "Draw"- dumbRockPaperScissors=lambda a,b:"Draw"if a==b else f"Player {(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins"
import java.util.Arrays; import java.lang.Math; public class MaxNumber { public static long print(long number) { int z = (int)Math.ceil(Math.log10(number)); long digits[] = new long[z]; int index = 0; while(number > 0) { digits[index++] = number % 10; number /= 10; } Arrays.sort(digits); long result = 0; while(z --> 0) { result = result * 10 + digits[z]; } return result; } }
- import java.util.Arrays;
- import java.lang.Math;
- public class MaxNumber {
- public static long print(long number) {
return number- int z = (int)Math.ceil(Math.log10(number));
- long digits[] = new long[z];
- int index = 0;
- while(number > 0) {
- digits[index++] = number % 10;
- number /= 10;
- }
- Arrays.sort(digits);
- long result = 0;
- while(z --> 0) {
- result = result * 10 + digits[z];
- }
- return result;
- }
- }
fix the code lol
#include <stdio.h> int prnt_mltply(int m, int n) { int i = 1; while(i <= m) { int j = 1; while(j <= n) { printf("%d * %d = %d \n", i, j, i * j); j++; } i++; printf("\n"); } return m - n; }
#include<stdio.h>int main(){int i=1;while(i<=5){int j=1;while(j<=12){printf("%d * %d =%d", i,j, i*j);j++;- #include <stdio.h>
- int prnt_mltply(int m, int n) {
- int i = 1;
- while(i <= m) {
- int j = 1;
- while(j <= n) {
- printf("%d * %d = %d
- ", i, j, i * j);
- j++;
- }
- i++;
- printf("\n");
- }
i++;printf("\n");}return(0);- return m - n;
- }
#include <criterion/criterion.h> int prnt_mltply(int m, int n); void tester(int m, int n, int expected); Test(prnt_mltply, Sample_Test) { tester(5, 12, 60); } void tester(int m, int n, int expected) { int submitted = prnt_mltply(m, n); cr_assert_eq( submitted, expected, "< Incorrect Result >\n \nm = %d\nn = %d\n \nSubmitted: %d\nExpected: %d", m, n, submitted, expected ); }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.- #include <criterion/criterion.h>
// replace with the actual method being testedint foo(int,int);- int prnt_mltply(int m, int n);
- void tester(int m, int n, int expected);
Test(the_multiply_function, should_pass_all_the_tests_provided) {cr_assert_eq(foo(1, 1), 1);- Test(prnt_mltply, Sample_Test)
- {
- tester(5, 12, 60);
- }
- void tester(int m, int n, int expected) {
- int submitted = prnt_mltply(m, n);
- cr_assert_eq( submitted, expected,
- "< Incorrect Result >\n \nm = %d\nn = %d\n \nSubmitted: %d\nExpected: %d",
- m, n, submitted, expected
- );
- }
#include <stddef.h> static const char *nums[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; const char *digit_to_text(unsigned digit) { return digit < 10u ? nums[digit] : NULL; }
- #include <stddef.h>
const char* digit_to_text(unsigned digit){static const char* nums[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};if(digit > 9u){return NULL;}return nums[digit];- static const char *nums[] = {
- "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
- };
- const char *digit_to_text(unsigned digit) {
- return digit < 10u ? nums[digit] : NULL;
- }
#include <criterion/criterion.h> const char *digit_to_text(int digit); Test(digit_to_text, Test_Cases) { cr_assert_eq(digit_to_text(-1), NULL); cr_assert_str_eq(digit_to_text(0), "zero"); cr_assert_str_eq(digit_to_text(1), "one"); cr_assert_str_eq(digit_to_text(2), "two"); cr_assert_str_eq(digit_to_text(3), "three"); cr_assert_str_eq(digit_to_text(4), "four"); cr_assert_str_eq(digit_to_text(5), "five"); cr_assert_str_eq(digit_to_text(6), "six"); cr_assert_str_eq(digit_to_text(7), "seven"); cr_assert_str_eq(digit_to_text(8), "eight"); cr_assert_str_eq(digit_to_text(9), "nine"); cr_assert_eq(digit_to_text(10), NULL); }
- #include <criterion/criterion.h>
const char* digit_to_text(int digit);- const char *digit_to_text(int digit);
Test(digit_to_text, should_pass_all_the_tests_provided) {- Test(digit_to_text, Test_Cases)
- {
- cr_assert_eq(digit_to_text(-1), NULL);
- cr_assert_str_eq(digit_to_text(0), "zero");
- cr_assert_str_eq(digit_to_text(1), "one");
- cr_assert_str_eq(digit_to_text(2), "two");
- cr_assert_str_eq(digit_to_text(3), "three");
- cr_assert_str_eq(digit_to_text(4), "four");
- cr_assert_str_eq(digit_to_text(5), "five");
- cr_assert_str_eq(digit_to_text(6), "six");
- cr_assert_str_eq(digit_to_text(7), "seven");
- cr_assert_str_eq(digit_to_text(8), "eight");
- cr_assert_str_eq(digit_to_text(9), "nine");
- cr_assert_eq(digit_to_text(10), NULL);
- }
digitToText =_=> `zero one two three four five six seven eight nine`.split` `[_]
const nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']function digitToText(digit) {return nums[digit]}- digitToText
- =_=>
- `zero one two three four five six seven eight nine`.split` `[_]
class Kata { public static String verifySum(String nameOne, String nameTwo) { if(nameOne == null || nameTwo == null) { return "NULL"; } int sum = 0, lengthOne = nameOne.length(), lengthTwo = nameTwo.length(); for(int i = 0; i < lengthOne; i++) { char c = nameOne.charAt(i); sum += c > 96 ? c - 32 : c; } for(int i = 0; i < lengthTwo; i++) { char c = nameTwo.charAt(i); sum -= c > 96 ? c - 32 : c; } return sum == 0 ? "TRUE" : "FALSE"; } }
class Kata{- class Kata {
- public static String verifySum(String nameOne, String nameTwo) {
int[] sumOfNames = new int[]{0, 0};if (nameOne == null || nameTwo == null) {- if(nameOne == null || nameTwo == null) {
- return "NULL";
- }
for (int i = 0; i < nameOne.length(); i++){sumOfNames[0] += nameOne.charAt(i);- int sum = 0, lengthOne = nameOne.length(), lengthTwo = nameTwo.length();
- for(int i = 0; i < lengthOne; i++) {
- char c = nameOne.charAt(i);
- sum += c > 96 ? c - 32 : c;
- }
for (int i = 0; i < nameTwo.length(); i++){sumOfNames[1] += nameTwo.charAt(i);- for(int i = 0; i < lengthTwo; i++) {
- char c = nameTwo.charAt(i);
- sum -= c > 96 ? c - 32 : c;
- }
return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";- return sum == 0 ? "TRUE" : "FALSE";
- }
- }
helloWorld =_=> _?`Hello World baby`:`No World`
/*def hello_world(world):if world == True:return "Hello World baby"elif world == False:return "No World"*/- helloWorld
// helloWorld = (world) => world == true ? 'Hello World baby': 'No World';- =_=>
const helloWorld=(world)=>world==true?`Hello World baby`:`No World`;- _?`Hello World baby`:`No World`
/*def hello_world(world): if world == True: return "Hello World baby" elif world == False: return "No World"*/ // helloWorld = (world) => world == true ? 'Hello World baby': 'No World'; helloWorld =(_)=> _?`Hello World baby`:`No World`
// def hello_world(world):// if world == True:// return "Hello World baby"// elif world == False:// return "No World"helloWorld = (world) => world == true ? 'Hello World baby': 'No World';- /*def hello_world(world):
- if world == True:
- return "Hello World baby"
- elif world == False:
- return "No World"*/
- // helloWorld = (world) => world == true ? 'Hello World baby': 'No World';
- helloWorld
- =(_)=>
- _?`Hello World baby`:`No World`
const { assert } = require('chai'); describe("Solution", function() { it("should test for something", function() { assert.strictEqual(helloWorld(true), `Hello World baby`); assert.strictEqual(helloWorld(2 + 2 == 5), `No World`); }); });
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");const assert = chai.assert;// Uncomment the following line to disable truncating failure messages for deep equals, do:// chai.config.truncateThreshold = 0;// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.// Uncomment the following to use the old assertions:// const Test = require("@codewars/test-compat");- const { assert } = require('chai');
- describe("Solution", function() {
- it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);- assert.strictEqual(helloWorld(true), `Hello World baby`);
- assert.strictEqual(helloWorld(2 + 2 == 5), `No World`);
- });
- });
greeting=Greeting=lambda name,rank='',formal=False:"He{0}, {1}{2}{3}{4}".format(('y','llo')[formal],rank*formal,' '*bool(rank and formal),name,'!.'[formal])
def Greeting(n, rank='', formal=False):determinant = f'{rank} {n}' if formal and rank else f'{n}'return f"Hello, {determinant}." if formal else f"Hey, {determinant}!"- greeting=Greeting=lambda name,rank='',formal=False:"He{0}, {1}{2}{3}{4}".format(('y','llo')[formal],rank*formal,' '*bool(rank and formal),name,'!.'[formal])
import codewars_test as test from solution import Greeting import random def get_greeting(name, rank=None, formal=False): print(f'Hello,{" " + rank if rank is not None else ""} {name}.' if formal else f'Hey, {name}!') return f'Hello,{" " + rank if rank is not None else ""} {name}.' if formal else f'Hey, {name}!' names = [ 'Lisa', 'Skylar', 'Dylan', 'Harper', 'Susan', 'Kenneth', 'Quinn', 'Kevin', 'Morgan', 'Jordan', 'Finley', 'Karen', 'Michael', 'Emerson', 'Daniel', 'Avery', 'William', 'Michelle', 'Justice', 'David', 'Donald', 'Richard', 'Jennifer', 'Robert', 'Payton', 'John', 'James', 'Ariel', 'Skyler', 'Dorothy', 'Charles', 'Paul', 'Drew', 'Rory', 'Steven', 'Riley', 'Reese', 'Robin', 'Cameron', 'Mark', 'Jamie', 'Sarah', 'Jessica', 'Nancy', 'Anthony', 'Brian', 'Sandra', 'George', 'Helen', 'Melissa', 'Dakota', 'Mary', 'Alexis', 'Peyton', 'Alex', 'Charlie', 'Matthew', 'Patricia', 'Christopher', 'Edward', 'Elizabeth', 'Amanda', 'Sawyer', 'Margaret', 'Donna', 'Emily', 'Thomas', 'Bailey', 'Hayden', 'Rowan', 'Harley', 'Kai', 'Carol', 'Laura', 'Linda', 'Casey', 'Parker', 'Andrew', 'Joseph', 'Reagan', 'Emery', 'Phoenix', 'Taylor', 'Betty' ] titles = [ 'Duchess', 'Ambassador', 'Mistress', 'Executive', 'Sultan', 'Pharaoh', 'Baron', 'Mayor', 'Magistrate', 'Sergeant', 'Doctor', 'Sir', 'Lord', 'Vice President', 'Baroness', 'Cardinal', 'Officer', 'Archbishop', 'Duke', 'Agent', 'Madam', 'Queen', 'Minister', 'King', 'Captain', 'Pope', 'Master', 'Admiral', 'Princess', 'Lieutenant', 'Director', 'President', 'Governor', 'Commander', 'Prince', 'Detective', 'Professor', 'Sheikh', 'Bishop', 'Chancellor', 'Countess', 'Empress', 'Chief', 'Senator', 'Counselor', 'Emperor', 'Judge', 'General', 'Count' ] @test.describe("Fixed Tests") def test_group(): @test.it("Tests") def test_case(): test.assert_equals(Greeting('John'), 'Hey, John!') test.assert_equals(Greeting('Churchill', 'Sir', True), 'Hello, Sir Churchill.') test.assert_equals(Greeting('Einstein', 'Proffessor', False), 'Hey, Einstein!') test.assert_equals(Greeting('Jane', formal=True), 'Hello, Jane.') @test.describe("Random Tests") def random(): for test_number in range(100): qname = names[random.randint(0,len(names)-1)] qrank = titles[random.randint(0,len(titles)-1)] if random.randint(0,1)==1 else '' f = bool(random.randint(0,1)==0) @test.it(f'Random Test #{str(test_number+1)}: {qname}{", rank="+qrank if not qrank=="" else ""}, formal={f}') def _(): expected = f'Hello,{" "if not qrank=="" else ""}{qrank} {qname}.' if f else f'Hey, {qname}!' print(f'Expected Answer: "{expected}". Your Answer: "{Greeting(qname, qrank, f)}"') test.assert_equals(Greeting(qname, qrank, f), expected)
- import codewars_test as test
- from solution import Greeting
- import random
- def get_greeting(name, rank=None, formal=False):
- print(f'Hello,{" " + rank if rank is not None else ""} {name}.' if formal else f'Hey, {name}!')
- return f'Hello,{" " + rank if rank is not None else ""} {name}.' if formal else f'Hey, {name}!'
- names = [
- 'Lisa', 'Skylar', 'Dylan', 'Harper', 'Susan', 'Kenneth', 'Quinn', 'Kevin', 'Morgan', 'Jordan', 'Finley',
- 'Karen', 'Michael', 'Emerson', 'Daniel', 'Avery', 'William', 'Michelle', 'Justice', 'David', 'Donald',
- 'Richard', 'Jennifer', 'Robert', 'Payton', 'John', 'James', 'Ariel', 'Skyler', 'Dorothy', 'Charles', 'Paul',
- 'Drew', 'Rory', 'Steven', 'Riley', 'Reese', 'Robin', 'Cameron', 'Mark', 'Jamie', 'Sarah', 'Jessica', 'Nancy',
- 'Anthony', 'Brian', 'Sandra', 'George', 'Helen', 'Melissa', 'Dakota', 'Mary', 'Alexis', 'Peyton', 'Alex',
- 'Charlie', 'Matthew', 'Patricia', 'Christopher', 'Edward', 'Elizabeth', 'Amanda', 'Sawyer', 'Margaret',
- 'Donna', 'Emily', 'Thomas', 'Bailey', 'Hayden', 'Rowan', 'Harley', 'Kai', 'Carol', 'Laura', 'Linda', 'Casey',
- 'Parker', 'Andrew', 'Joseph', 'Reagan', 'Emery', 'Phoenix', 'Taylor', 'Betty'
- ]
- titles = [
- 'Duchess', 'Ambassador', 'Mistress', 'Executive', 'Sultan', 'Pharaoh', 'Baron', 'Mayor', 'Magistrate',
- 'Sergeant', 'Doctor', 'Sir', 'Lord', 'Vice President', 'Baroness', 'Cardinal', 'Officer', 'Archbishop',
- 'Duke', 'Agent', 'Madam', 'Queen', 'Minister', 'King', 'Captain', 'Pope', 'Master', 'Admiral', 'Princess',
- 'Lieutenant', 'Director', 'President', 'Governor', 'Commander', 'Prince', 'Detective', 'Professor',
- 'Sheikh', 'Bishop', 'Chancellor', 'Countess', 'Empress', 'Chief', 'Senator', 'Counselor', 'Emperor', 'Judge',
- 'General', 'Count'
- ]
- @test.describe("Fixed Tests")
- def test_group():
- @test.it("Tests")
- def test_case():
- test.assert_equals(Greeting('John'), 'Hey, John!')
- test.assert_equals(Greeting('Churchill', 'Sir', True), 'Hello, Sir Churchill.')
- test.assert_equals(Greeting('Einstein', 'Proffessor', False), 'Hey, Einstein!')
- test.assert_equals(Greeting('Jane', formal=True), 'Hello, Jane.')
- @test.describe("Random Tests")
- def random():
- for test_number in range(100):
- qname = names[random.randint(0,len(names)-1)]
- qrank = titles[random.randint(0,len(titles)-1)] if random.randint(0,1)==1 else ''
- f = bool(random.randint(0,1)==0)
- @test.it(f'Random Test #{str(test_number+1)}: {qname}{", rank="+qrank if not qrank=="" else ""}, formal={f}')
- def _():
- expected = f'Hello,{" "if not qrank=="" else ""}{qrank} {qname}.' if f else f'Hey, {qname}!'
- print(f'Expected Answer: "{expected}". Your Answer: "{Greeting(qname, qrank, f)}"')
- test.assert_equals(Greeting(qname, qrank, f), expected)