instruction stringlengths 34 53.1k |
|---|
You are probably familiar with the Fibonacci sequence where the first two terms are 0, 1 (or sometimes 1, 1) and every term after that is the sum of the previous two. It starts like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Sometimes, the sequence contains numbers that have a particular pattern that I find int... |
Consider the infinite matrix:
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 2 3 0 0 2 3 0 0 2 3 0 0 2 3
0 0 0 4 5 6 0 0 0 4 5 6 0 0 0 4 ...
0 0 0 0 7 8 9 10 0 0 0 0 7 8 9 10
0 0 0 0 0 11 12 13 14 15 0 0 0 0 0 11
...
Each new row of the matrix is co... |
A while ago, I had a look at the prime factorization of 27000:
27000 = 23 × 33 × 53
There are two special things about that:
consecutive-prime: The primes are consecutive: 2 is the 1st prime, 3 is the 2nd prime, 5 is the 3rd prime.
constant-exponent: The exponent is the same for every prime (always 3)
Mathematicall... |
Asked on Stack Overflow, but they suggested to move it here
A while ago I was reading about quines. It made me wonder if it possible to write a macro in C which will print itself, without writing any function such as main. every piece of code should be only in macro. After a few attempts, I couldn't find the solution.
... |
Challenge
Given a matrix of positive integers, determine if there are any "rings" of mountains. The formal definition for this challenge is: given a matrix of positive integers, is there any positive integer n for which there is a closed ring of cells in the matrix that are strictly greater than n such that all cells e... |
Challenge:
Given a positive integer input n, create a vector that follows this pattern:
0 1 0 -1 -2 -1 0 1 2 3 2 1 0 -1 -2 -3 -4 -3 -2 -1 ... ±(n-1) ±n
Or, explained with words: The vector starts at 0, and makes increments of 1 until it reaches the smallest odd positive integer that isn't part of the sequence... |
Consider a one-dimensional sequence of numbers within a fixed range, i.e.
[1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩
The Ever-Increasing Graph* ** is a line that connects all the points in this sequence left to right, and always goes upwards or stays level. If necessary, the line wraps around from top to bottom and ... |
Write a function (using as few bytes as possible) that takes a bi-dimensional array of any number of columns and rows in which:
0 represents empty block,
1 represents snake block.
The function must return the number of possible paths the snake traveled.
Example 1:
Input:
[
[1,1,1,1,1],
[0,0,0,0,1],
[0,0,0,0,1... |
Your task is to write a program or a function that outputs n random numbers from interval [0,1] with fixed sum s.
Input
n, n≥1, number of random numbers to generate
s, s>=0, s<=n, sum of numbers to be generated
Output
A random n-tuple of floating point numbers with all elements from the interval [0,1] and sum of all el... |
Balanced binary search trees are essential to guarantee O(log n) lookups (or similar operations). In a dynamic environment where a lot of keys are randomly inserted and/or deleted, trees might degenerate to linked lists which are horrible for lookups. Thus there are various kinds of self-balancing binary trees that cou... |
You're organizing a treasure hunt for your friends. To conduct things more easily, you want to draw a map of all locations where you hid the precious objects.
Input
Any form of input denoting a list of points consisting of (nonnegative) x- and y-coordinate, 0 0 being the upper left corner is permitted (Note: You may al... |
Given a non-empty list L of integers greater than 1, we define d(L) as the smallest positive integer such that n + d(L) is composite for each n in L.
We define the sequence an as:
a0 = 2
ai+1 is the smallest integer greater than ai such that d(a0, ..., ai, ai+1) > d(a0, ..., ai)
Your task
You may either:
Take an in... |
Fairy Chess is a sort of generalized chess that allows unconventional pieces. The eight queens puzzle is a classic problem where you have to put 8 queens on a chess board such that no two queens threaten each other. This challenge is sort of a generalized combination of the two.
Challenge
Given a list of fairy chess pi... |
Given an integer matrix a and a nonnegative integer i, output a mapping b that maps the distinct values in the ith column of a to rows of a who have that value in the ith column.
You may assume that i is in the half-open range [0, num_cols(a)) (or [1, num_cols(a)] if you choose to use 1-based indices), and that all int... |
Pangrams
The quick brown fox jumped over the lazy dog.
This is an example of a pangram - a sentence that contains every letter of the alphabet at least once.
A self-enumerating pangram is a sentence that fulfills the criteria to be a pangram by producing an analysis of its own letter count.
An example of achieving th... |
This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Associated challenge: Function clipboard: copy.
Introduction
MATL's function clipboard stores ("copies") the inputs to the four most recent calls to normal, input-taking functions. Normal functions a... |
Challenge :
Given a string representing a mathematical expression return the result
Input :
A string representing a mathematical expression : '1 + 2 - 3 * (2/3 * 1)'.
Output :
The result after performing all operations.
Operators :
Possible operators
+ ---> plus
- ---> minus
* ---> multiplication
/ -... |
Background
Boggle is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("adjacent" means horizontally, vertically or diagonally adjacent.) Also, same cell can't be used more than once in a word... |
I am a robot. I bought this keyboard because of its easy rectangular layout:
~` !1 @2 #3 $4 %5 ^6 &7 *8 (9 )0 _- +=
tab Qq Ww Ee Rr Tt Yy Uu Ii Oo Pp {[ }] \|
Aa Ss Dd Ff Gg Hh Jj Kk Ll :; "' [-enter-]
Zz Xx Cc Vv Bb Nn M... |
Problem
Let's define a generalized Cantor set by iteratively deleting some rational length segments from the middle of all intervals that haven't yet been deleted, starting from a single continuous interval.
Given the relative lengths of segments to delete or not, and the number of iterations to do, the problem is to w... |
After inputting a string [length 1-20], only containing the chars y for yes and n for no,
your program should output the result (y or n). Example input: yynynynny would output y.
The result is determined by combining the y's and n's in the following way:
yes and no equals no
yes and yes equals yes
no and no equals yes... |
Create a program that outputs itself.
However, if the source code is repeated n times (meaning to concatenate a copy of the source code to the end n-1 times), then there should be 1/n probability outputting the original source code, a 1/n probability of outputting the source code repeated twice, a 1/n probability of o... |
Given a list of numbers \$[a_1, a_2, ... a_n]\$, compute the sum of all the matrices \$A_i\$ where \$A_i\$ is defined as follows (\$m\$ is the maximum of all \$a_i\$):
$$
\begin{array}{c|cc}
& 1 & 2 & \cdots & i-1 & i & i+1 & \cdots & n \\
\hline
1 & 0 & 0 & \cdots & 0 & a_i & a_i & \cdots & a_i \\
2 ... |
You have two values each of which is either 0 representing "unknown", or one of 1,2,3. Merge them into a single value as follows:
If both values are nonzero and equal, output that value:
(3,3) -> 3
If both values are nonzero but unequal, output 0 for unknown:
(1,2) -> 0
If one value is zero and the other is not, outpu... |
We all know that a lot of exercises only affect one half of your body, so you have to do them twice, once for each side. Such exercises have two counterparts, one for the left side and one for the right. However, there's no need to execute the two counterparts consecutively, as long as the exercises for both sides are ... |
The task is taken from an MIT lecture by Prof. Devadas called You can read minds. A detailed explanation of the trick can be found in the linked video, or in this document. I'll try to explain it in simpler terms.
It turns out this was invented in the 1930's, and is known as the "Five-Card Trick of Fitch Cheney".
The ... |
The game of xiangqi, also known as Chinese chess, is a chess-like game popular in China, Vietnam, Taiwan, and other East Asian countries. The colours of the two sides in xiangqi are red and black. There are 16 black pieces in xiangqi: the 1 general (G), 2 advisor (A), 2 elephant (E), 2 horse (H), 2 chariot (R), 2 canno... |
Challenge :
Create a random (pseudo random) Sudoku board with dimension n x n
Input :
Given :
n where :
2 < n < 100
Output :
true / false depending on whether the board is valid or not.
Examples :
For n = 3 :
[7, 8, 4, 1, 5, 9, 3, 2, 6], [5, 3, 9, 6, 7, 2, 8, 4, 1], [6, 1, 2, 4, 3, 8, 7, 5, 9],
[9, 2, 8, 7, 1, ... |
Your challenge is to sort a string, but rather than by the normal alphabetical order (abc..xyz), you will be sorting strings by a specified alphabet.
You must write a program or function that takes two inputs: An alphabet A and an string S. Both will only contain lowercase English letters, and both will contain at leas... |
I was looking for a very easy task to look how short of a code can be produced on a beginners exercise.
The goal is to produce a simple table that looks like this common java/c# code is about 4 lines. So get your golfing-languages ready ;) Try to align the matrix in any way it is readable.
1 2 3 .. 10
2 4 6 .. ... |
Consider all 2^n different binary strings of length n and assume n > 2. You are allowed to delete exactly b < n/2 bits from each of the binary strings, leaving strings of length n-b remaining. The number of distinct strings remaining depends on which bits you delete. Assuming your aim is to leave as few remaining diff... |
Challenge
Your task is to write a piece of code that outputs another piece of code. That code must in turn output yet another code until the final code outputs the integer 1. The chain ends the first time 1 is outputted.
None of your programs may share any characters (there's one exception in the Rules-section).
The w... |
It's strange this question hasn't been asked yet, so here it is:
Calculate the length of a string given through STDIN
Rules
As said, your string will be given through STDIN, not via command line arguments
Print the length of the string to STDOUT
Only ASCII chars will be given, and all printable ASCII chars count!
This... |
A Math.SE user have a funny game explained as such:
Pick a random positive integer X.
Add +1, 0, -1 to make it divisible by 3Keep track of how much you've added and subtracted. That is your "score"..
Divide by 3 to create a new X.
Repeat steps 2 and 3 until you reach one.
I'm expecting the shortest code to give the... |
Write a function in Python 2.7 that takes a list of integers as an argument. It should return True or False depending on whether there are any 2 integers in the argument list that sum to zero.
[4,-4,9,6,5]
True
[6,5,-3,2]
False
|
The Task
Your task is to create a program or a function that, given a sentence, outputs it translated to the Farfallino language. 'Y' is treated as a consonant.
The usual rules for farfallino alphabet are based on the substitution of each vowel with a 3 letter sequence where the vowel itself is repeated with an interce... |
Rotonyms 1
ROT13 ("rotate by 13 places") is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in the alphabet. So, A becomes N, N becomes A, B <-> O, and so on to M <-> Z.
ROT13('abcdefghijklmnopqrstuvwxyz') == 'nopqrstuvwxyzabcdefghijklm'
A "Rotonym" is a word (pair) that ROT... |
Rotonyms 2
A "Rotonym" is a word that ROT13s into another word (in the same language).
For this challenge, we'll use an alternate definition: a "Rotonym" is a word that circular shifts/rotates into another word (in the same language).
For example:
'stable' < 'tables' < 'ablest'
'abort' > 'tabor'
'tada' >> 'data'
The C... |
99 bugs in the code
The adaption of "99 bottles of beer on the wall" for computer science where the bugs increase instead of the bottles decreasing is often re-posted around the internet. Example T-Shirt Here.
I think it'll be interesting to see potential recursion and random number generation across a huge variety of ... |
When given a a list of values and a positive integer n, your code should output the cartesian product of the list with itself n times.
For example, in pseudocode your function could be similar to:
for x1 in list:
for x2 in list:
for x3 in list:
...
for xn in list:
pri... |
The abs() function in most languages does one thing: give the positive version of the input. Most of the times this is done using something similar to
int
abs (int i)
{
return i < 0 ? -i : i;
}
I was wondering if there is any way to do this with less bytes.
Note that this doesn't have to be more efficient, just sm... |
There is currently a meme on the internet that consist of taking a sentence, reverse the meaning and adding n't at the end. For example, I am small becomes I am talln't
Challenge
For the sake of the challenge, we'll simplify this : Your task will be to detect whenever there is a negation in a sentence, and replace it w... |
There's a type of n×n matrix W called the basic Weyr canonical form. Such a matrix is described by its blocks and has the following properties, using the following reference diagram:
the main diagonal blocks Wii are ni×ni matrices of the form λIni where Ini is the ni×ni identity matrix.
n1 ≥ n2 ≥ ... ≥ nr
the first s... |
Here the first 100 numbers of an easy sequence:
0,1,0,2,1,4,3,7,6,11,10,16,15,22,21,29,28,37,36,46,45,56,55,67,66,79,78,92,91,106,105,121,120,137,136,154,153,172,171,191,190,211,210,232,231,254,253,277,276,301,300,326,325,352,351,379,378,407,406,436,435,466,465,497,496,529,528,562,561,596,595,631,630,667,666,704,703,74... |
I thought of a new way to generate my passwords, and even though it's probably not very clever in the long run, it could still make for a fun code-golf.
Taking a string of words, the password is generated thus:
Pick the nth character in the nth word
If n is larger than the word, continue counting backwards
Example:
T... |
Inspired by the Codewars Kata.
Your goal is to take an input string such as this one:
"'Twas a dark and stormy night..."
and return a string containing the position of each character in the alphabet, separated by spaces and ignoring non-alphabetical characters, like this:
"20 23 1 19 1 4 1 18 11 1 14 4 19 20 15 18 13 ... |
Matrix challenges are popular. There's an issue of how to provide test cases. A common method is the row-wise array-of-arrays representation, such as:
[[1,2],[3,4],[5,6]] -> a 3 by 2 matrix
This is good with vertical space, but there's always the task of converting the test cases into something your language can use, ... |
Challenge
Make two programs, A and B, which are both cat programs in the same language. When concatenated, AB (also in the same language) should be a quine.
For example, suppose hello and world are both cat programs in language XYZ. If helloworld is a quine in said language, then your solution is valid.
For those of yo... |
Definitions
The kth ring of a square matrix of size N, where 1 ≤ k ≤ ceiling(N/2) is the list formed by the elements of the kth and (N-k+1)th rows and columns, but without the first and last k-1 elements.
Example:
Matrix:
1 2 3 4 5
6 7 8 9 1
8 7 6 5 4
3 2 1 9 8
7 6 5 4 3
Delimited in rings:
+-------------------+
| ... |
I've been enslaved in a quine factory. The other workers and I can't communicate with the outside world, we can only slave away making quines all day. The masters will reject any work that isn't a proper quine. I'll have to put messages into the quines I make to let people know we're trapped here.
The Challenge
Help us... |
Given an array of numbers with length >=3 and length % 3 == 0
[1, 2, 3, 4, ...]
You will split it in sub-arrays of length 3
[[1, 2, 3], [4, 5, ...], [...
And return an array with
[0] => The amount of cases in the sub-array where all numbers are equal
[1] => In case all numbers in sub-array are not equal, the amount ... |
Given two strings of letters, transfer the capitalization pattern of each string onto the other one. Fewest bytes wins.
Input: CodeGolf xxPPCGxx
Output: coDEGOlf XxppCgxx
Both strings will be equal-length and nonempty, with only letters a..z and A..Z.
You may output the two resulting strings in either order rel... |
Given a list of strings, replace each string by one of its non-empty substrings which is not a substring of any of the other strings in the list and as short as possible.
Example
Given the list ["hello","hallo","hola"], "hello" should be replaced by just "e" as this substring is not contained in "hallo" and "hola" and ... |
Minesweeper is a puzzle game where mines are hidden around a board of nondescript tiles with the goal of identifying the location of all mines. Clicking on a mine loses the game, but clicking on any other tile will reveal a number from 0-8 which signifies how many mines directly surround it.
Given a number, you must di... |
Create a function which takes a polynomial equation, a value for x and returns the result of the operation.
Example: given 4x^2+2x-5 and x=3 output 37. This is the result of 4(3)^2+2(3)-5
Assume all polynomials are valid
Polynomial format will always be coefficient(variable)^exponent => 4x^2 except :
When exponent ... |
You may have seen Jacob's Ladder in children's science museums. If you're not familiar with what they look like, there are several images and video examples on the Wikimedia Commons. The challenge today is to create an animated ASCII version of the electrical gadget. In the end, it should look something like this:
La... |
Define f(a,b) := a if b=1; a^f(a,b-1) if b>1 (Tetration, where ^ means power) for positive integers a and b, given four positive integers a,b,c,d, compare f(a,b) and f(c,d).
Your program should output three constant values to mean "greater", "less" and "equal".
Samples:
a b c d f(a,b) output f(c,d)
3 2 2 3 27 > ... |
The challenge
Create a function which takes an array of numbers and subtract from each element the lowest element in the array that has not yet been subtracted from another.
After using the lowest value, It can not be used again.
Numbers in the array are decimal numbers, and not necessarily integers.
Example:
Input: ... |
Challenge
Given a sequence of numbers, create a function which returns the sequence steps.
Assume a sequence will be N >= 3
Sequence will repeat it steps at least once
Sequence will only contain natural numbers
Your function or program should return the shortest possible sequence of steps
Example:
Input: [1, 2, 3, 5,... |
Challenge :
Count the number of ones 1 in the binary representation of all number between a range.
Input :
Two non-decimal positive integers
Output :
The sum of all the 1s in the range between the two numbers.
Example :
4 , 7 ---> 8
4 = 100 (adds one) = 1
5 = 101 (adds two) = 3
6 = 110 (adds two) = 5... |
We define the function g as g(n) = n XOR (n * 2) for any integer n > 0.
Given x > 0, find the smallest integer y > 0 such that gk(y) = x for some k > 0.
Example
x = 549
549 = 483 XOR (483 * 2) (as binary: 1000100101 = 111100011 XOR 1111000110)
483 = 161 XOR (161 * 2) (as binary: 111100011 = 10100001 XOR 101... |
So, I have an array
['a', 42, 'b', 42, 'a']
I want to alert users to the fact that 42 and 'a' appear in it twice.
some_function(['a', 42, 'b', 42, 'a'])
should return
['a', 42]
Write some code to extract the duplicates from an array.
It should accept an array as input.
The array can have multiple types of object.
... |
Input
Take a list of values xi each paired with a key yi.
[(x1, y1), (x2, y2), ...]
Output
Return a list L containing only values from the set {xi}.
The length of L must be equal to the number of unique keys k in the set {yi}.
For each unique key k there must be a value from {xi} that has key k.
Details
Standard l... |
Task
Given a number between 0 and 1 and another integer, print the approximated value of the first number rounded off to the specified number of digits given by the second integer. For example, if the input is 0.3212312312 , 2 then the output is:
0.32
Rules
The number of digits after the dot should always equal the s... |
This is a Cops and Robbers challenge. For the Robbers' thread, go here.
The Cops have three tasks.
1) Pick a sequence from the OEIS.
2) Pick a language (this is suggested to be a golflang, but doesn't have to be) that, when given input n, outputs A(n) (where A(n) is the sequence chosen) using all usual code-golf rule... |
This is a Cops and Robbers challenge. For the Cops' thread, go here.
The Cops have three tasks.
1) Pick a sequence from the OEIS.
2) Pick a language (this is suggested to be a golflang, but doesn't have to be) that, when given input n, outputs A(n) (where A(n) is the sequence chosen) using all usual code-golf rules.
... |
Inspiration.
Consider a list l, consisting of numbers. Define a block operation at index i on the list l to be the act of moving 3 consecutive elements starting from i in l to the end.
Example:
l, i (1-indexing) -> l (after applying block operation at index i)
[1,2,3,4,5], 1 -> [4,5,1,2,3]
[1,2,3,4,5,6,7], 3 -> [1,2,6,... |
Input
A string of printable ASCII characters, for example:
This is an example string.
Output
For every consonant (BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz) that is not followed by a vowel (AEIOUaeiou) add the last vowel before it, in lowercase.
Consonants before the first vowel are left as-is:
Thisi isi ana examapal... |
Background
Three years ago, this guy Tom Murphy got it into his head to extend the idea of a portmanteau to all words in a language and called this a portmantout (portmanteau plus tout [French for all]). Defining English as a list of 108,709 words, he managed to find a sequence of 611,820 letters with the following two... |
I like to think of a 10-adic number as a number that goes infinitely to the left, or an integer modulo a very very large power of 10.
Things carry infinitely to the left and vanish. To see what I mean, note that ...6667 * 3 = 1 in the 10-adic land, since the "2" that carries to the left goes to infinity.
Addition and m... |
Challenge :
Inspired by Alphabet Position Finder
Given an string and one of two possible mathematical operator (+ or -) as input, your task is to return the operation of each alphabet position from the string.
Example :
Input: "Hello World", "+"
=> "Hello World" = [8, 5, 12, 12, 15, 23, 15, 18, 12, 4] (converted to the... |
You will be given a string s. It is guaranteed that the string has equal and at least one [s and ]s. It is also guaranteed that the brackets are balanced. The string can also have other characters.
The objective is to output/return a list of tuples or a list of lists containing indices of each [ and ] pair.
note: The s... |
Challenge :
Check :
if there are exactly n exclamation marks ! between every pair
and whether the sum of each pair equals to 10.
Input :
A string of arbitary length.
The number of exclamation marks to check for
Output :
if there are exactly n exclamation marks between each pair, return truthy value, otherwise fal... |
I forgot towel day
Sandbox link
PHP script for both examples (error, formatting the string)
Corrected php script, the input is self explanatory
PHP script with more input comment/uncomment $argv to see different results
As you may know, May 25 is well known as Towel Day, because of the many uses a towel can have.
A si... |
One day, I saw the challenge to multiply two strings and I thought I might be able to do one better.
That challenge was fake. It was elementwise maximum. It was not real multiplication. So I set out to make something real. Real division between two strings.
I quickly realized that this would make an amazing challenge,... |
You have come across an old Indian manuscript, one that describes mounds of buried treasure. The manuscript also tells you the location of the treasure, except that some crucial numbers have been encoded indirectly into the text. You figure out that the text uses a 'Kaadi' system, a restricted subset of the more common... |
Imagine a text file where each csv record may have different numbers of fields. The task is to write code to output how many fields there are in each record of the file. You can assume there is no header line in the file and can read in from a file or standard input, as you choose.
You can assume a version of rfc418... |
Your task is to decipher a non-empty string consisting of printable ASCII characters in the range [32..126].
Reading the string character per character:
each time you encounter a letter in lowercase, associate it with the next letter in uppercase, starting with 'A'
each time you encounter a letter in uppercase, replac... |
A little known fact is that if you turn on enough language extensions (ghc) Haskell becomes a dynamically typed interpreted language! For example the following program implements addition.
{-# Language MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}
data Zero
data Succ a
cl... |
Let's define a simple language that operates on a single 8-bit value.
It defines three bitwise operations (code explanation assumes 8-bit value variable):
! Negate the least significant bit (value ^= 1)
< Wrapping left-shift (value = value << 1 | value >> 7)
> wrapping right-shift (value = value >> 1 | value << 7)
In... |
Background
Nonogram, also known as Picross or Griddlers, is a puzzle where the objective is to determine if each cell on the 2D grid should be colored or left blank, using the numbers of consecutive colored cells on each line.
The following is an example Nonogram puzzle with solution.
The problem is, some commercial N... |
Introduction
I've seen throughout the code-golf challenges several simple tasks involving JSON, such as interpreting JSON strings with RegExs, and almost every other manipulation I could think of.
In a binding for AppleScript that I was using for a Node project, I noticed that objects would be returned in a strange wa... |
Here's an array representing a standard deck of cards, including two Jokers.
[
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "K... |
Introduction:
The best options for the glass of your house will:
1. Let through as little heat as possible in both directions (insulation-value Ug).
(2. Let through as much sunbeams as possible from the outside to the inside.)
(3. Let through as much light as possible from the outside to the inside.)
We only care about... |
Taken from StackOverflow Question
Challenge
Given an encoded string in format n[s] where n is the amount of times s will be repeated, your task is to output the corresponding decoded string.
n will always be a positive number
s can not contain empty spaces
strings only contains letters from the alphabet
s length can b... |
This challenge is really simple (and a precursor to a more difficult one!).
Given an array of resource accesses (simply denoted by nonnegative integers) and a parameter n, return the number of cache misses it would have assuming our cache has capacity n and uses a first-in-first-out (FIFO) ejection scheme when it is fu... |
This is inspired by an 05AB1E answer by Magic Octupus Urn.
Given two arguments, a positive integer and a string/list of characters:
Translate the number to base-n, where n is the length of the string.
For each character, replace every appearance of the index of that character in the base-n number with that character.
... |
Introduction
In a private chat, a friend of mine apparently recently stumbled across a security system which has the following two restrictions on its valid pins:
Each digit must be unique (that is "1" may only appear once)
The order of the digits doesn't matter ("1234"="4321")
So to illustrate how bad this padlock s... |
Here's a programming puzzle for you:
Given a list of pairs of strings and corresponding numbers, for example, [[A,37],[B,27],[C,21],[D,11],[E,10],[F,9],[G,3],[H,2]], output another list which will have just the strings in the following manner:
The total count of any string should be exactly equal to its corresponding ... |
Problem Description
Given:
a function \$f(a, b, c, d, e) = \frac{a \times b}c + \frac de\$
an array \$x = [x_1, x_2, x_3, x_4, ..., x_n]\$ of non-distinct integers
a target value \$k\$
What is the most efficient way, in terms of worst-case \$n\$, to find 5 distinct indices \$x_a, x_b, x_c, x_d, x_e\$ from \$x\$ such ... |
Inspired by a real-life scenario, which I have asked for an answer to here: https://superuser.com/questions/1312212/writing-a-formula-to-count-how-many-times-each-date-appears-in-a-set-of-date-ran
Given an array of timespans (or startdate-enddate pairs), output a count of how many timespans cover each day, for all days... |
You are given two arbitrary integer lists, e.g. [-10, 99, -6, 43], [100, 32, 44]. You are to pick one integer from each list and sum them up, then sort the best pairs ordered by the absolute distance to 100 in ascending order. Paired up integers from each list shall not be repeated in the output.
For instance, we have
... |
This is a bit similar to this dust covered entry but I'm hoping my spin on it makes it unique enough. Not been able to find anything dissuading me from posting this but there is quite the sea out there.
Anyway! The challenge:
Your code receives a string of characters; It converts this into an ASCII-art style version of... |
First, let's talk about Beatty sequences. Given a positive irrational number r, we can construct an infinite sequence by multiplying the positive integers to r in order and taking the floor of each resulting calculation. For example,
If r > 1, we have a special condition. We can form another irrational number s as s =... |
A frog sits on a lily pad wishing it were on the other side of the river. There are some lily pads of varying sizes between the frog and the other side of the river. Larger lily pads allow the frog to jump further than smaller ones and the frog wishes to reach the other side of the river in as few jumps as possible.
... |
I have a simple challenge for you this time. Given an array of positive integers A (or the equivalent in your language), replace each entry Ai with the sum of the next Ai elements of A, cycling back from the beginning if there are not enough items.
As usual, you can compete in any programming language and can take inpu... |
The digital root (also repeated digital sum) of a positive integer is the (single digit) value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital... |
The positive rational numbers can be shown to be numerable with the following process:
Zero has the ordinal 0
Arrange the other numbers in a grid so that row a, column b contains a/b
Plot a diagonal zig-zag top right to bottom left
Keep a running tally of the unique numbers encountered along the zig-zag
Here's a pict... |
For the purposes of this question, a deck of cards is formatted in this way:
[
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "K... |
Introduction
I recently came across an oral exam where the candidates were asked to find a logical circuit than can negate 3 inputs A,B,C using only two NOT gates.
The question also specified that such a circuit is unique up to removal of useless gates and reordering inputs/outputs. The candidates were asked to prove t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.