Ad

shorter, barely

heh heh heh

Code
Diff
  • 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``
Code
Diff
  • disemvowel=lambda s:''.join(c for c in s if c not in "aieouAEIOU")
    • disemvowel=lambda s:''.join(i for i in s if i.lower() not in "aieou")
    • disemvowel=lambda s:''.join(c for c in s if c not in "aieouAEIOU")
Code
Diff
  • 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
Code
Diff
  • 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]
Algorithms
Arrays
Mathematics
Geometry
Code
Diff
  • 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
Code
Diff
  • 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;
    • }
Code
Diff
  • 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)))
    • }
Code
Diff
  • 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

Code
Diff
  • average=lambda t:[*map(__import__('numpy').average,zip(*t))]
    • average=lambda t:[*map(__import__('statistics').mean,zip(*t))]
    • average=lambda t:[*map(__import__('numpy').average,zip(*t))]
Mathematics
Logic

reinstituted the usefull mean function and still kept it to ONE LINE!!!1!

Code
Diff
  • average=lambda t:[*map(__import__('statistics').mean,zip(*t))]
    • average=lambda t:[*map(lambda x:sum(x)/len(x),zip(*t))]
    • average=lambda t:[*map(__import__('statistics').mean,zip(*t))]
Mathematics
Logic
Code
Diff
  • 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
Code
Diff
  • 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)]
Code
Diff
  • 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;
    • };
Code
Diff
  • maxnum=lambda n:int(''.join(sorted(str(n),reverse=1)))
    • def maxnum(number):
    • lista = []
    • result = ""
    • for char in str(number):
    • lista.append(char)
    • lista.sort(reverse = True)
    • for char in lista:
    • result = result + char
    • return int(result)
    • maxnum=lambda n:int(''.join(sorted(str(n),reverse=1)))
Code
Diff
  • #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;
    • }
Loading more items...