Skip to content

Instantly share code, notes, and snippets.

@lyxal
Created October 5, 2022 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyxal/68078c6b45723cb2a84719266c8cd556 to your computer and use it in GitHub Desktop.
Save lyxal/68078c6b45723cb2a84719266c8cd556 to your computer and use it in GitHub Desktop.
/*
**AICMC**: Find the point closest to the origin (0, 0) from a list of points.
**AICMC**: Sort a list of numbers by how many digits they have in binary (with the leading 0's trimmed)
**AICMC**: Given two identically structured non-ragged arrays, return an array identical to one of them, except each element is copied to N copies, with N being the corresponding number from the other array.
**AICMC**: "Roll" n 20 sided dice (random number 1 to 20), and select the ith largest (n and i positive integer inputs)
**AICMC**: Given a Unicode string, return a string of equal length where every character differs from the corresponding character in the input.
**AICMC**: given n!, output n
**AICMC**: Given a string, chop it into a list of Fibonacci-sized pieces. For example, "Hello, world!" -> ["H", "e", "ll", "o, ", "world", "!"] (pieces have sizes 1, 1, 2, 3, 5, and there aren't enough characters left to make 8 so the final piece contains all the remaining characters).
**AICMC**: Take a nonnegative integer as input, and return the closest even integer (rounded down)
**AICMC**: Given integer n, output the largest square number smaller than n
**AICMC**: Given an odd prime, return (truthy/falsey) whether it is a sum of two squares
**AICMC**: flip a palindrome inside out (e.g. abcba -> cbabc, defggfed -> gfeddefg)
**AICMC**:
/*
CMC: Compare two numbers: if the first is smaller, return -1. If they are identical, return 0. If the first is larger, return 1. The reverse is also fine.
CMC: Dot product between two lists of same length
CMC: Output the indices of the maximal elements of a list. [1,2,3,2,1,2,3,3] -> [3,7,8] (1-indexed)
CMC: Given a list (even length) of integers, split into consecutive pairs, sort each pair by its sum, then flatten. e.g. [2,3,6,4,2,1] -> [[2,3],[6,4],[2,1]] -> [[2,1],[2,3],[6,4]] -> [2,1,2,3,6,4]
CMC: Append two matrices [[0,1],[4,5]], [[2,3],[6,7]] => [[0,1,2,3],[4,5,6,7]]
CMC: Given a positive integer n, create a n^2×n^2 boolean matrix which is an n×n checkerboard with each square being of size n×n. The top left color does not matter. Example: 2 -> [[0,0,1,1],[0,0,1,1],[1,1,0,0],[1,1,0,0]]
CMC: Take an array of numbers. Take the sum, but where every second item is negated.
CMC: Given a string, keep only digits. e.g. ab3829cbw2 -> 38292
CMC: Given a square matrix of positive digits, return the upper triangular matrix formed by zeroing all of the elements below the main diagonal.
CMC: Output two integers (between 1 and 100) chosen at random from 2 different distributions (e.g. one is uniform, another is exponential)
CMC: Given an alphabetic string and a boolean list of the same length, uppercase or lowercase each letter accordingly. "Hello", 0 1 1 0 1 -> "hELlO"
CMC: Given a string, output which-th time each character is appearing in that string. "abracadabra" -> 1, 1, 1, 2, 1, 3, 1, 4, 2, 2, 5
CMC: Given a string, return all substrings that are palindromes. By substrings, I mean that you can also remove characters in between, e.g. fobarrbf -> brrb, bab, fof, fbf, faf, frf, bb, brb, etc. (duplicates are allowed)
CMC: Group elements in a list by their count, e.g. [1, 2, 3, 1, 4, 4, 4, 2, 5] -> {2: [1, 2], 3: [4], 1: [3, 5]}
CMC: Given a list of numbers L and number n, return the n largest numbers from L in order of appearance. E.g. L=[1,6,1,8,0,3] and n=4 gives [1,6,8,3]
CMC: Given a word composed of lowercase ASCII letters, reverse the order of the vowels (aeiou) within it. Examples: code -> cedo; bureaucracy -> baruaecrucy; subtraction -> sobtrictaun
CMC: Given a string, output its reverse and its length.
CMC: Given a list of positive integers, output their sum and the number of digits of the sum. E.g. [1,2,3] -> 6 and 1, [1,2,3,4] -> 10 and 2.
CMC: Given any positive integer, return the list of digits in its binary representation
CMC: Given a positive integer, write numbers from it (largest to smallest) forming an arithmetic sequence with the difference of 3.
CMC: Given two sorted arrays A and B of size m & n respectively, return an array C containing elements common to A and B
CMC: Given a list of floats [0. , .22, .25], find absolute maximum in time O(n). e.g for above array -> 0.25
CMC: Print all primes between two numbers
CMC: Find the smallest positive number with a sum of its digits equal to n. The result must be bigger than n
CMC: If a word starts with 'M', return in pig latin - eg. "Monday" would convert to "Ondemay". Take care of only string alphanumeric words (don't convert   etc.)
CMC: Given n distinct integers, count the frequencies of those from 0 to 10
CMC: Given a set of characters (A, B), return all possible strings made from those chars.
CMC: Print all permutations of a string
CMC: From integer 0 to n print all integers that cannot be represented as n^x, where x is any integer.
CMC: Reverse the bits of an integer, example 1357 ==> 10101001
CMC: A palindromic number which is the sum of 3 consecutive square numbers.
CMC: Given a sequence of integers, print the length and sum of its longest increasing subsequence.
CMC: You are given a positive integer N. Output all semiprimes in range [1,N](both inclusive)
CMC: Given a list of integers, remove the smallest possible number of elements such that all remaining numbers are even.
CMC: Given a non-empty array of integers, every element appears twice except for one. Find that single one
CMC: Write a function that finds the largest product between three integers in any given array.
CMC: Complete the function that returns "Yes"/"No". Given a string, if its length is less than or equal to 3 return "Yes", otherwise return "No". Remove all punctuation from the given String and handle capitalization so consider puctuation characters such as apostrophes/quotation marks as part of the string, e.g "Selamat!" is considered 'Yes'
CMC: Given a list L containing numbers and strings return whether or not it contains integer values so [1,"2", 3] returns true while ['a', 2 ,3, 4e7] will return false.
CMC: Given input as a string, return number of vowels in it (consider "y" to be not vowel). Consider capital letters same as small.
CMC: Find the deepest level in a list - given [2,[[3],1]] should print out 2 using 0-indexing or 3 using 1-indexing for depths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment