shorter, barely
heh heh heh
n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join`` d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join``
n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join('')d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join('')- n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``
- d=s=>[...s].map(e=>("12345".includes(e)?"aeiou"[e-1]:e)).join``
dumbRockPaperScissors =(a,b)=> a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`
function dumbRockPaperScissors(player1, player2) {if (player1 === player2) return "Draw";const condition = {Scissors: "Paper",Rock: "Scissors",Paper: "Rock",};return player2 === condition[player1] ? "Player 1 wins" : "Player 2 wins";}- dumbRockPaperScissors
- =(a,b)=>
- a==b?`Draw`:`Player ${(a!={'Rock':'Paper','Paper':'Scissors','Scissors':'Rock'}[b])+1} wins`
Algorithms
Arrays
Mathematics
Geometry
make_move=lambda c,s:((d:=__import__('collections').Counter(s)),(c[0]+d['l']*-1+d['r'],c[1]+d['b']*-1+d['t']))[1]
makeMove=(c,s)=>[...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)- make_move=lambda c,s:((d:=__import__('collections').Counter(s)),(c[0]+d['l']*-1+d['r'],c[1]+d['b']*-1+d['t']))[1]
import codewars_test as test from solution import make_move @test.describe("Fixed Tests") def fixed_tests(): @test.it("Basic Test Cases") def basic_test_cases(): tests = ( ( ( 0, 0), "ttrbrrbllrt", ( 2, 1) ), ( ( 4, 1), "bllbrt", ( 3, 0) ), ( (-2, 4), "trlbb", (-2, 3) ), ( ( 5, 5), "trlbrb", ( 6, 4) ) ) for coords, moves, expected in tests: submitted = make_move(coords, moves) test.assert_equals(submitted, expected)
// 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 deprecateddescribe("Solution", function() {it("should test for something", function() {assert.deepEqual(makeMove([0, 0], "ttrbrrbllrt"), [2, 1]);assert.deepEqual(makeMove([4,1], "bllbrt"), [3,0]);assert.deepEqual(makeMove([-2, 4], "trlbb"), [-2,3]);assert.deepEqual(makeMove([5,5], "trlbrb"), [6, 4]);});});- import codewars_test as test
- from solution import make_move
- @test.describe("Fixed Tests")
- def fixed_tests():
- @test.it("Basic Test Cases")
- def basic_test_cases():
- tests = (
- ( ( 0, 0), "ttrbrrbllrt", ( 2, 1) ),
- ( ( 4, 1), "bllbrt", ( 3, 0) ),
- ( (-2, 4), "trlbb", (-2, 3) ),
- ( ( 5, 5), "trlbrb", ( 6, 4) )
- )
- for coords, moves, expected in tests:
- submitted = make_move(coords, moves)
- test.assert_equals(submitted, expected)
Algorithms
Arrays
Mathematics
Geometry
makeMove =(c,s)=> [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)
function makeMove(init, sequence) {let coords = [...init];for(const dir of sequence) {coords[0] += (dir == 'r') - (dir == 'l');coords[1] += (dir == 't') - (dir == 'b');}return coords;}- makeMove
- =(c,s)=>
- [...s].reduce((r,d)=>[r[0]+(d=='r')-(d=='l'),r[1]+(d=='t')-(d=='b')],c)
Algorithms
Arrays
Mathematics
Geometry
function makeMove(init, sequence) { let coords = [...init]; for(const dir of sequence) { coords[0] += (dir == 'r') - (dir == 'l'); coords[1] += (dir == 't') - (dir == 'b'); } return coords; }
- function makeMove(init, sequence) {
[...sequence].forEach(move => {switch (move) {case 't':init[1]++;break;case 'b':init[1]--;break;case 'r':init[0]++;break;case 'l':init[0]--;break;default:break;}});return init;- let coords = [...init];
- for(const dir of sequence) {
- coords[0] += (dir == 'r') - (dir == 'l');
- coords[1] += (dir == 't') - (dir == 'b');
- }
- return coords;
- }
mod preloaded; use preloaded::nand; fn not(a: bool) -> bool { nand(a, a) } fn and(a: bool, b: bool) -> bool { nand(nand(a, b), nand(a, b)) } fn or(a: bool, b: bool) -> bool { nand(not(a), not(b)) } fn nand_nand_or(a: bool, b: bool) -> bool { nand(nand(a, b), or(a, b)) } fn xor(a: bool, b: bool) -> bool { nand(nand_nand_or(a, b), nand_nand_or(a, b)) } fn nor(a: bool, b: bool) -> bool { nand(or(a, b), or(a, b)) } fn xnor(a: bool, b: bool) -> bool { nand(nand(a, b), nand(nand(a, a), not(b))) }
- mod preloaded;
- use preloaded::nand;
- fn not(a: bool) -> bool {
- nand(a, a)
- }
- fn and(a: bool, b: bool) -> bool {
- nand(nand(a, b), nand(a, b))
- }
- fn or(a: bool, b: bool) -> bool {
nand(nand(a, a), nand(b, b))- nand(not(a), not(b))
- }
- fn nand_nand_or(a: bool, b: bool) -> bool {
- nand(nand(a, b), or(a, b))
- }
- fn xor(a: bool, b: bool) -> bool {
nand(nand(nand(a, b), nand(nand(a, a), nand(b, b))), nand(nand(a, b), nand(nand(a, a), nand(b, b))))- nand(nand_nand_or(a, b), nand_nand_or(a, b))
- }
- fn nor(a: bool, b: bool) -> bool {
nand(nand(nand(a, a), nand(b, b)), nand(nand(a, a), nand(b, b)))- nand(or(a, b), or(a, b))
- }
- fn xnor(a: bool, b: bool) -> bool {
nand(nand(a, b), nand(nand(a, a), nand(b, b)))- nand(nand(a, b), nand(nand(a, a), not(b)))
- }
public class Program { public static int FindSquaresInArray(int[] arr) { int sum = 0; foreach(int n in arr) { sum += n * n; } return sum; } }
using System;- public class Program
- {
- public static int FindSquaresInArray(int[] arr)
- {
- int sum = 0;
for (int i = 0; i < arr.Length; i++)- foreach(int n in arr)
- {
sum += arr[i] * arr[i];- sum += n * n;
- }
- return sum;
- }
Mathematics
Logic
two obscure chars shorter because Python, ha ha
Mathematics
Logic
reinstituted the usefull mean
function and still kept it to ONE LINE!!!1!
Mathematics
Logic
from statistics import mean def average(t: tuple[tuple[int | float, ...], ...]) -> list[int | float]: return [*map(mean, zip(*t))]
- from statistics import mean
- def average(t: tuple[tuple[int | float, ...], ...]) -> list[int | float]:
return [mean(x) for x in zip(*t)]- return [*map(mean, zip(*t))]
Mathematics
Logic
from statistics import mean def average(t: tuple[tuple[int | float, ...], ...]) -> list[int | float]: return [mean(x) for x in zip(*t)]
- from statistics import mean
- def average(t: tuple[tuple[int | float, ...], ...]) -> list[int | float]:
return [sum(i) / len(i) for i in zip(*t)]- return [mean(x) for x in zip(*t)]
const firstNonRepeatingCharacter = (str) => { let chars = [], counts = []; for(const char of str) { let index = chars.indexOf(char); if(index < 0) { index = counts.length; chars.push(char); counts.push(0); } counts[index]++; } for(let index = 0; index < chars.length; index++) { if(counts[index] === 1) { return chars[index]; } } return null; };
- const firstNonRepeatingCharacter = (str) => {
let nonRepeatingCharacter = '';const repeatingCharacters = {};str.split('').map(char => ((repeatingCharacters[char] = (repeatingCharacters[char] ?? 0) + 1)));for(const [key, value] of Object.entries(repeatingCharacters)) {if (nonRepeatingCharacter !== '') break;if (value === 1) nonRepeatingCharacter = key;- let chars = [], counts = [];
- for(const char of str) {
- let index = chars.indexOf(char);
- if(index < 0) {
- index = counts.length;
- chars.push(char);
- counts.push(0);
- }
- counts[index]++;
- }
return nonRepeatingCharacter||null;- for(let index = 0; index < chars.length; index++) {
- if(counts[index] === 1) {
- return chars[index];
- }
- }
- return null;
- };
#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;
- }