Ad
Code
Diff
  • const isEven=i=>Number.isInteger(i)?!(i%2):undefined
    • function isEven(input) {
    • if(!Number.isInteger(input)) {
    • return undefined
    • }
    • return input.toString(2).at(-1) == false
    • }
    • const isEven=i=>Number.isInteger(i)?!(i%2):undefined
Code
Diff
  • const isEven=i=>typeof i==="number"&&i!==Infinity&&Math.floor(i)===i?i%2===0:undefined
    • function isEven(input) {
    • if(!Number.isInteger(input)) {
    • return undefined
    • }
    • return input.toString(2).at(-1) == false
    • }
    • const isEven=i=>typeof i==="number"&&i!==Infinity&&Math.floor(i)===i?i%2===0:undefined
int main;
Code
Diff
  • #include <stdbool.h>
    
    bool odd_even(int n)
    {
      goto start;
    uwu:
      goto end;
    start:
      goto uwu;
    end:
      return !(n&1);
      goto start;
    }
    • def odd_even(n):
    • def invert_sign(s):
    • if s == "odd":
    • return "e" + "v" + "e" + "n"
    • else:
    • return "o" + "d" + "d"
    • if n < 0:
    • return odd_even(n - 2 * (-abs(-n)))
    • n = int(n ** (81 ** .25))
    • sign = "even"
    • x = 0.
    • while x < n:
    • sign = invert_sign(sign)
    • x += 3.14159265358 // 3
    • n = pow(n, 1)
    • return sign == "odd"
    • #include <stdbool.h>
    • bool odd_even(int n)
    • {
    • goto start;
    • uwu:
    • goto end;
    • start:
    • goto uwu;
    • end:
    • return !(n&1);
    • goto start;
    • }
Code
Diff
  • #include <vector>
    
    long
    add_arr(std::vector<int> arr)
    {
      long result = 0;
      while(arr.size()) {
        result += arr[0];
        arr.erase(arr.begin());
      }
      return result;
    }
    • #include <array>
    • #include <vector>
    • template <std::size_t L>
    • long
    • add_arr(std::array<int, L> arr)
    • add_arr(std::vector<int> arr)
    • {
    • long result = 0;
    • for (int i : arr) result += i;
    • while(arr.size()) {
    • result += arr[0];
    • arr.erase(arr.begin());
    • }
    • return result;
    • }
    • template long add_arr(std::array<int, 9> arr);
    • }
Algorithms
Arrays

create a pop_first and pop_last functions which will delete first/last element from vector and then return it

#include<vector>

template <typename T>
T
pop_last(std::vector<T>* v) {
  T result = (*v)[v->size() - 1];
  v->pop_back();
  return result;
}

template <typename T>
T
pop_first(std::vector<T>* v) {
  T result = (*v)[0];
  v->erase(v->begin());
  return result;
}

template int pop_last(std::vector<int>*);
template int pop_first(std::vector<int>*);
Code
Diff
  • module AddNumbers where
    add_arr x = sum x
    • pub fn add_arr(arr: &[i16]) -> i16{
    • arr.iter().sum()
    • }
    • module AddNumbers where
    • add_arr x = sum x
Code
Diff
  • pub fn add_arr(arr: &[i16]) -> i16{
        arr.iter().sum()
    }
    • #include <array>
    • template <std::size_t L>
    • long
    • add_arr(std::array<int, L> arr)
    • {
    • long result = 0;
    • for (int i : arr) result += i;
    • return result;
    • }
    • template long add_arr(std::array<int, 9> arr);
    • pub fn add_arr(arr: &[i16]) -> i16{
    • arr.iter().sum()
    • }
Code
Diff
  • add-sum(){
      expr \
      $(
        echo -n 0
        for i in "$@"; do {
          echo -n " + ${i}" 
        }; done
      )
    }
    
    add-sum "$@"
    • function addArr(arr){
    • if(arr.length === 0) return null
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • }
    • add-sum(){
    • expr \
    • $(
    • echo -n 0
    • for i in "$@"; do {
    • echo -n " + ${i}"
    • }; done
    • )
    • }
    • add-sum "$@"
Code
Diff
  • (ns arr-sum)
    (def arr-add #(reduce + %))
    • function addArr(arr){
    • if(arr.length === 0) return null
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • }
    • (ns arr-sum)
    • (def arr-add #(reduce + %))
Code
Diff
  • #include <array>
    
    template <std::size_t L>
    long
    add_arr(std::array<int, L> arr)
    {
      long result = 0;
      for (int i : arr) result += i;
      return result;
    }
    
    template long add_arr(std::array<int, 9> arr);
    • #include <array>
    • template <std::size_t L>
    • long
    • add_arr(const unsigned long len, const int arr[len])
    • add_arr(std::array<int, L> arr)
    • {
    • long result = 0;
    • for
    • (
    • unsigned long i = 0;
    • i < len;
    • result += arr[i++]
    • );
    • for (int i : arr) result += i;
    • return result;
    • }
    • }
    • template long add_arr(std::array<int, 9> arr);
Code
Diff
  • long
    add_arr(const unsigned long len, const int arr[len])
    {
      long result = 0;
      
      for
      (
        unsigned long i = 0;
        i < len;
        result += arr[i++]
      );
      
      return result;
    }
    • function addArr(arr){
    • long
    • add_arr(const unsigned long len, const int arr[len])
    • {
    • long result = 0;
    • if(arr.length === 0) return null
    • for
    • (
    • unsigned long i = 0;
    • i < len;
    • result += arr[i++]
    • );
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • return result;
    • }
Code
Diff
  • add_arr = sum
    • add_arr = lambda foo: sum(foo)
    • add_arr = sum
Strings
Big Integers

more test cases
added logs

Code
Diff
  • __uint128_t solution(char* str1, char* str2) {
      __uint128_t result = 0;
      
      for (unsigned long i = 0; i < 7; ++i) {
        result +=
          (((__uint128_t) str1[i]) << (8*(i + 0))) +
          (((__uint128_t) str2[i]) << (8*(i + 8)));
      }
      
      return result;
    }
    • __uint128_t solution(char* str1, char* str2) {
    • __uint128_t result = 0;
    • for (unsigned long i = 0; i < 7; ++i) {
    • result +=
    • (((__uint128_t) str1[i]) << (8*i)) +
    • (((__uint128_t) str1[i]) << (8*(i + 0))) +
    • (((__uint128_t) str2[i]) << (8*(i + 8)));
    • }
    • return result;
    • }
Strings

all described in title lol

__uint128_t solution(char* str1, char* str2) {
  __uint128_t result = 0;
  
  for (unsigned long i = 0; i < 7; ++i) {
    result +=
      (((__uint128_t) str1[i]) << (8*i)) +
      (((__uint128_t) str2[i]) << (8*(i + 8)));
  }
  
  return result;
}