instruction
stringlengths
34
53.1k
Mölkky Mölkky is a Finnish throwing game. The players use a wooden pin (also called "mölkky") to try to knock over wooden pins of almost similar dimensions with the throwing pin, marked with numbers from 1 to 12. The initial position of the pins is as follows: (07)(09)(08) (05)(11)(12)(06) (03)(10)(04) (01)...
Input : Two decimal integers m and n that respectively give the number of rows and columns of the table. m and n are greater than or equal to 1. Output : A table in HTML that has m rows and n columns. The table should be displayable by a modern browser of your choice. Most browsers will display everything properly even...
Background If you do much code golfing, you're likely aware of the bitwise XOR operation. Given two integers, it gives another integer with 1s in the bits where the two inputs differ. So, for example, 1010 XOR 0011 = 1001. It turns out to be very useful in game theory, where it's better known as the "nim sum". If you ...
Blackjack, also known as twenty-one, is a comparing card game between yourself and a dealer, where each player in turn competes against the dealer, but players do not play against each other. Play goes as follows, the dealer deals you a card. The dealer then deals them-self a card, face down. The dealer then deals yo...
Challenge Let's imagine an N-tuple of integers between 0 and M inclusive, and let's call it F. There are (M + 1) ** N possible Fs in total. How many such Fs satisfy all of the following inequalities (index is one-based)? F[n] + F[n+1] <= M for 1 <= n < N F[N] + F[1] <= M Write a program or function that takes two pos...
Inspired by last week's APL lesson. Given an uppercase 2D seat map and a 1D list of customers, return the seat map and the customer list but modified as follows (to indicate occupied seats and seated customers): For each unique letter in the input passenger list, lowercase that many (or all, if there are not enough) of...
Originally posted (and deleted) by @Tlink, which was most likely inspired from this StackOverflow question. Since it was a shame it got deleted, because it seemed like a good challenge in general, I figured I'd repost it with proper formatting and rules. (I've tried contacting @Tlink and get his/her permission to post ...
As a celebration of good old Notepad, we are going to treat carriage returns and line feeds as what they originally meant, rather than what they are (ab-)used for today. Given a string consisting of printable ASCII plus line feeds (␊; LF; esc \n; hex 0A; dec 10) and carriage returns (␍; CR; esc \r; hex 0D; dec 13), cau...
I love functional programming in Octave, but it's rather unwieldy in practice. I'm wondering about the shortest way to define an anonymous recursive function. I have some ideas, but I'm wondering if there is a way to combine these ideas to make them even shorter (or equally short but more versatile). For the sake of th...
Imagine an arsonist walking around the town and picking its victims according to a very specific pattern (Or, alternatively, Imagine a bee flying around the garden and picking its flowers to pollenize according to a very specific pattern). Let's say the town is an N × N matrix, where N is an integer higher than or equa...
The 21 Hairstyles of the Apocalypse Given a a list of numbers between 1 and 21 (or 0 and 20) output a "stitched together" drawing of the following faces (see rules for stitching information): ___ ,,, ooo === +++ ### -*~*- (o o) (o o) ...
Given a nonempty list of positive integers \$(x, y, z, \dots)\$, your job is to determine the number of unique values of \$\pm x \pm y \pm z \pm \dots\$ For example, consider the list \$(1, 2, 2)\$. There are eight possible ways to create sums: \$+ 1 + 2 + 2 \to +5\$ \$+ 1 + 2 − 2 \to +1\$ \$+ 1 − 2 + 2 \to +1\$ \$+ 1...
Input: An array I of k positive integers. The integers will be no larger than 100 and k ≤ 100. Output: Your code must output all possible arrays O of non-negative integers of length k with the restriction that 0 ≤ Oi ≤ Ii. To get from one array to the next you may add or subtract 1 to one value in the array. Your co...
The Premise: You are writing a C driver for a screen for use on an embedded system. The screen uses a tortured version of SPI that requires data to be sent LSb (least-significant-bit) first, but MSB (most-significant-byte) first. A fast way to do this (if you have the memory) is to use the integer value of each byte to...
The setup: A social network reports the number of votes a post has in two ways: the number of net upvotes (total upvotes - total downvotes), and the % of votes that were upvotes, rounded to the nearest integer (.5 rounds up). The number of net upvotes is an integer (not necessarily positive), and the second is guarant...
Challenge : Given a string split at specific positions and capitalize the first character of the given word. Capitalize the first word's first char if and only if it was already capitalized Input : A string s and a character c. Ouput : The string with each occurrence of c replaced with the first char capitalized Exam...
Input A non-empty encoded string consisting of printable ASCII characters (in the range 32-126), where some missing letters have been replaced with _. Output A decoded string of the same length with all letters in lowercase, including the missing ones. How? Edit: As mentioned by @Deusovi in the comments, this is a vari...
The challenge here is to find the longest uninterruped arc around a unit circle with a random amount of points distributed in random positions around it. Here is a diagram to assist my explanation: The red line indicates the largest arc between any two points that is not interrupted by any other points. The challenge ...
Challenge Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers (integers with absolute difference 1) are next to each other. Examples 4 → [1, 3, 0, 2] 5 → [0, 2, 4, 1, 3] 6 → [0, 2, 4, 1, 3, 5] 7 → [0, 2, 4, 1, 5, 3, 6] You may use 1-indexing instead...
See similar question for 2D case: Find the longest uninterrupted arc The challenge here is to find the longest uninterruped great circle arc around a unit hypersphere in N dimensions, with a random amount of hyperspheres distributed in random positions around it. Here is a diagram in two dimensions to assist my explana...
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: paste. Introduction MATL has several clipboards, where you can store values (copy) to be retrieved later (paste). Some clipboards are automatic, which means...
Your goal is to alternate uppercase and lowercase letters, while ignoring non-alphaneumeric characters. Input => Output abc => aBc OR AbC a c => A c OR a C abc123abc => AbC123aBc OR aBc123AbC Shortest answer wins.
Introduction: In the northern hemisphere (i.e. Europe, North America, etc.), the seasons are divided like this: - Spring: March, April, May - Summer: June, July, August - Autumn: September, October, November - Winter: December, January, February In the southern hemisphere however (i.e. Australia, South America, etc.), ...
It's a common problem to navigate in a 2D matrix. We've seen it many times and will see again. So let's help future us and develop the shortest solutions to generate all eight possible steps in a 2D matrix. Challenge Your code must output the following 8 pairs of -1,0,1 in any order: (0,1) (0,-1) (1,0) (-1,0) (1,1) (1,...
Given this list of all the words in english and a string with s_me missi_g lett__s, find one way to fill in the letters. Do note that some words on the list contain special characters (! & ' , - . /) and numbers Input: This list and a string with missing letters. The input sentence can contain or be missing any of thes...
When writing a message with fridge magnets, you'll often find yourself substituting a 1 for an I. In this challenge, your goal is to find out if a message can be written using the letters of another message. The allowed substitutions are: A = 4 B = 8 C = U E = M = W = 3 G = 6 = 9 I = 1 L = 7 N = Z O = 0 R = 2 S = 5 Fo...
Challenge Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other. The value of a permutation pi is the sum of abs(pi[i] - i) for all indices i. Examples (1, 3, 0, 2) has value 6 (0, 2, 4, 1, 3) has value 6 (0, 2, 4, 1, 3, 5) ha...
In this variant of the Four fours puzzle your should use up to x x's (and no other number) and a defined set of operations to reach every number from 0 to 100. If x = 4 then you can use up to four 4s and this question becomes the classic four fours puzzle (except you can use up to four 4s rather than having to use exac...
Given a single digit integer and a three digit integer, output a mathematical formula that uses only the single digit and a given list of operators to equal the three digit integer. Input: A one digit positive integer (1-9) and a three digit integer (100-999) Output: A mathematical formula meeting the following requir...
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...