Ad
Code
Diff
  • maxNumber
    
        =n=>
    
            eval([...n+``].sort().reverse().join``+`n`)
    • const maxNumber = n => {
    • return BigInt([...n+''].reduce((a,c) => {a[9-c]=(a[9-c]||'')+c;return a},[]).join(''));
    • }
    • maxNumber
    • =n=>
    • eval([...n+``].sort().reverse().join``+`n`)
Code
Diff
  • from numpy import square
    
    def find_squares_in_array(arr):
        return sum(map(square, arr))
    • using System.Linq;
    • public class Program
    • {
    • public static int FindSquaresInArray(int[] arr) => arr.Sum(x => x*x);
    • }
    • from numpy import square
    • def find_squares_in_array(arr):
    • return sum(map(square, arr))
Code
Diff
  • get_fibs=lambda a=1,b=1:[(t:=a,a:=b,b:=b+t)[0]for _ in range(100)]
    • def output(thing=[1,1]):
    • for _ in range(100): thing.append(thing[-1]+thing[-2])
    • return thing
    • get_fibs=lambda a=1,b=1:[(t:=a,a:=b,b:=b+t)[0]for _ in range(100)]

-1

Code
Diff
  • firstNonRepeatingCharacter=s=>(j=s.split``,r=j.reduce((o,c)=>(o[c]=(o[c]|0)+1,o),{}),j.find(c=>r[c]==1)??null)
    • firstNonRepeatingCharacter=s=>(j=s.split``,r=j.reduce((o,c)=>(o[c]=(o[c]??0)+1,o),{}),j.find(c=>r[c]==1)??null)
    • firstNonRepeatingCharacter=s=>(j=s.split``,r=j.reduce((o,c)=>(o[c]=(o[c]|0)+1,o),{}),j.find(c=>r[c]==1)??null)
Code
Diff
  • #include <stdio.h>
    prnt_mltply(m,n){for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)printf("%d * %d = %d\n",i,j,i*j);return m*n;}
    • #include <stdio.h>
    • int prnt_mltply(int m, int n) {
    • for (int i = 0; i < m; i++) for (int j = 1; j <= n; j++) printf("%d * %d = %d
    • ", i + 1, j, (i+1) * j);
    • return m * n;
    • }
    • prnt_mltply(m,n){for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)printf("%d * %d = %d
    • ",i,j,i*j);return m*n;}

okay

Code
Diff
  • const firstNonRepeatingCharacter = (str) => {
      let counts = {};
      for(const char of str) {
        counts[char] = 1 + (counts[char] ? counts[char] : 0);
      }
      for(const char in counts) {
        if(counts[char] == 1) {
          return char;
        }
      }
      return null;
    }
    • const firstNonRepeatingCharacter = (str) => {
    • let chars = [], counts = [];
    • for(char of str) {
    • let index = chars.indexOf(char);
    • if(index < 0) {
    • index = counts.length;
    • chars.push(char);
    • counts.push(0);
    • }
    • counts[index]++;
    • let counts = {};
    • for(const char of str) {
    • counts[char] = 1 + (counts[char] ? counts[char] : 0);
    • }
    • for(let i = 0; i < chars.length; i++) {
    • if(counts[i] === 1) {
    • return chars[i];
    • for(const char in counts) {
    • if(counts[char] == 1) {
    • return char;
    • }
    • }
    • return null
    • };
    • return null;
    • }

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))]
Loading more items...