instruction
stringlengths
34
53.1k
One of many unique features of the Malbolge programming language is its highly unintuitive OP operator, referred to only as "op" in the documentation and source code but popularly known as the "crazy" operator. As described by Ben Olmstead, the creator of the language, in its documentation: "don't look for pattern, it'...
For this task your code should take two sorted arrays of integers X and Y as input. It should compute the sum of the absolute distances between each integer in X and its closest number in Y. Examples: X = (1 5,9) Y = (3,4,7) The distance is 2 + 1 + 2. X = (1,2,3) Y = (0,8) The distance is 1 + 2 + 3. Your code can t...
You are fish in a pond that needs to survive by eating other fish. You can only eat fish that are the same size or smaller than yourself. You must create a program that takes a shoal of fish as sorted input. From this you must work out how many fish you can eat and ultimately the size you will grow to. Size chart +----...
Consider two sorted arrays of integers \$X\$ and \$Y\$ of size \$m\$ and \$n\$ respectively with \$m < n\$. For example \$ X = (1,4)\$, \$Y = (2,10,11)\$. We say that a matching is some way of pairing each element of \$X\$ with an element of \$Y\$ in such a way that no two elements of \$X\$ are paired with the same el...
A portmanteau word is a combination of two words that takes part of each word and makes them into a single new word. For example, lion + tiger => liger. Let's write a program to generate portmanteaus from a pair of input words. Computers aren't the best at English, so we'll need to establish some rules to ensure that t...
A matrix can be thought of as the altitudes of a surface in 3D space. Consider the 8 neighbours (orthogonal and diagonal) of a cell as a cyclic sequence in clockwise (or anticlockwise) order. Some neighbours may be higher than the original cell, some lower, and some levelled at the same height as the original cell. We ...
In this question I will talk about programs as strings, this is strings of bytes, not characters. How your resultant program is rendered or displayed is not important to this challenge, only how it appears in memory matters. A pristine program is a program \$S\$ that when run does not error, however it will error when...
Challenge Given a sequence of non-negative integers, create a function that output a descendant pyramid where the children are the sum of both parent numbers. The result is outputted as an string using tab \t. Note: trailing tabs on each line are not required 1\t\t2\t\t3\n\t3\t\t5\t\n\t\t8\t\t results in 1 2 ...
Introduction OEIS sequence A127421 is the sequence of numbers whose decimal expansion is a concatenation of 2 consecutive increasing non-negative numbers. Put simply, every number in the sequence is formed by putting together n with n+1 for some non-negative, integer value of n. The first several terms are: 1, 12, 23,...
Based on a list of numbers and their equivalent letters, take a string input, replace the characters of that string with the equivalent number/letter and output the result. List 1 = a 2 = b 3 = c 4 = d 5 = e 6 = f 7 = g 8 = h 9 = i 0 = j Input thisisastring1124 Output t89s9s1str9n7aabd Rules Numbers are equiva...
Challenge The task is simple. Given an array and a first and last value: Return the first of the last after the first, and the last of the first before the last. Or simply: Given an array, var1, var2. Example Array: [ var2, , var1, , var2, , var2, var1, var2, ] Return: The index of the first var2 on the right side of...
Given dimensions of a 2D array, except 1xn, that results in an odd number of elements, find the midpoint index. Example: Input is 3x5, representing the 2D array [0,0] [0,1] [0,2] [0,3] [0,4] [1,0] [1,1] [1,2] [1,3] [1,4] [2,0] [2,1] [2,2] [2,3] [2,4] The midpoint index is [1,2] Input 3 5 Output 1 , 2 Rules Stand...
Your task is to write a computer program or function that takes a list of nonnegative integers of at least length 2 and determines if they are a "zigzag". A sequence is a zigzag if and only if the numbers alternate in being larger and smaller than the number that comes before them. For example \$[1,2,0,3,2]\$ and \$[...
Write a program or function that, given an integer n, construct an array with n dimensions of n length, where each element is an identifier of its own coordinates. That is, starting with one array, populate it with n arrays, where each of those contain n more arrays, up to a depth of n-1. The elements of the deepest ar...
In the 1990s, COBOL computer engineers worked out a way to extend six-digit date fields by converting them to YYYDDD where YYY is the year - 1900 and DDD is the day of the year [001 to 366]. This scheme could extend the maximum date to 2899-12-31. In the year 2898, the engineers started panicking because their 900 yea...
Your task is to make a quine, that is a non-empty computer program that prints it's own source without reading it. In addition if you remove any one byte from your original program the new program should print the source of your original program. This is code-golf so answers are scored in bytes with fewer bytes being ...
The task is simple: Create an if-statement from scratch in x86 assembly that runs in as few clock-cycles as possible. Must be x86 assembly. Can't use any of the conditional jump/branch instructions (e.g. je, jne, jz, jg, jge, jl, jle). Can use jmp to jump to existing blocks of code. Can use cmp if necessary. Can't cal...
Your Programs: You'll write two programs (both in the same language). The storage program takes a string from STDIN and stores it somewhere persistent (see below) and then exits without error. The retrieval program takes no input, retrieves the string that was stored, and prints it to STDOUT. Objective test of Persiste...
Take a string as an input, and perform addition/subtraction of all the digits in the string and output the sum of those operations as the result. Rules The digits in the string are read from left to right If a digit (n) is odd, perform addition with the next digit (n + n1) If a digit (n) is even, perform subtraction ...
Terminology An increasing number is one where each digit is greater than or equal to all the digits to the left of it (ex. 12239) A decreasing number is one where each digit is less than or equal to all the digits to the left of it (ex. 95531) A bouncy number is any number that is not increasing or decreasing. Since th...
This time, we want render the count of bytes in a human readable way to user. Let's write a program (a full one or a function or other acceptable formats) to do this. Input An non-negative integer, in range \$0\leq n<2^{31}\$, which means n bytes. Output A string, the human friendly representation of n bytes. Conventio...
Introduction In the not so distant future with the AI revolution, we will need a way to solve their captchas to prove we're not humans. This challenge was inspired by CommitStrip. Challenge One such captcha is the challenge of calculating the sum of all odd digits of Pi from digit 1 to digit n, including the first digi...
Players of the traditional board game Go measure their skill in a system of ranks: Players new to the game are ranked 30th kyū (written 30k) and progress counting down to 1st kyū (written 1k). These are considered the student ranks. A player may promote from 1st kyū to 1st dan rank (written 1d), and then progress coun...
Your task is, given x, output 2*x. Easy right!? But there's a catch: x will be given as a (possibly infinite) continued fraction, and the output must be a continued fraction. The input is guaranteed to be a real algebraic number whose degree is at most 2. Input: The continued fraction of x. This is split into 3 parts: ...
Yes, I know there are already three pokemon type questions, but almost all submissions hardcode the whole chart in one way or other. I think it'd be nice to change the requirement a bit to encourage more shortcut-taking typically seen in decision problems. Objective Write a program/function/whatever that accepts the at...
Challenge Sandbox post Given a positive integer (K) Output a uniformly-random integer (Y) between [0, K). If Y > 0 Assume K = Y and repeat the process until Y = 0. Rules Input must be printed at first Output format as you wish Your program must finish. 0 must be the final output, Optionally an empty line instead 0
I work at a bakery that serves Wheat, Rye, Barley, Grain, and French bread, but the baker's a little weird - he stacks the loaves in random order, and sometimes just leaves some shelves at the end empty. Each day, the same customer comes in and asks for one of each loaf of bread, but the tricky thing is, he's a germoph...
For a given list of number \$[x_1, x_2, x_3, ..., x_n]\$ find the last digit of \$x_1 ^{x_2 ^ {x_3 ^ {\dots ^ {x_n}}}}\$ Example: [3, 4, 2] == 1 [4, 3, 2] == 4 [4, 3, 1] == 4 [5, 3, 2] == 5 Because \$3 ^ {(4 ^ 2)} = 3 ^ {16} = 43046721\$. Because \$4 ^ {(3 ^ 2)} = 4 ^ {9} = 262144\$. Because \$4 ^ {(3 ^ 1)} = 4 ^ {...
Write a program or function that can distinguish the following 12 trigonometric functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh. Your program is given one of the above functions as black box and should output the function's name either as given above or the way it is named in your lan...
A set of n positive numbers has 2^n subsets. We'll call a set "nice" if none of those subsets have the same sum. {2, 4, 5, 8} is one such nice set. Since none of the subsets has the same sum, we can sort the subsets by sum: [{}, {2}, {4}, {5}, {2, 4}, {2, 5}, {8}, {4, 5}, {2, 8}, {2, 4, 5}, {4, 8}, {5, 8}, {2, 4, 8}, {...
Build a function in python that can win a Sevens game provided that there are only 2 players Here are the instructions from Wikipedia: All cards are dealt to the players, even if as a result some players have one card more than others. The owner of the seven of hearts begins by playing it. Similarly, the other ...
Given a string containing only letters, output the length of the longest run of consecutive alphabetical letters the word contains, where order does not matter. An example algorithm may sort the word, remove duplicates, and then output the length of the longest run. Test Cases watch -> 1 stars -> 3 antidisestablishment...
Does anyone have any suggestions as to how I could shorten this program? _=map(ord,raw_input());_=[10if y==88else 0if y==45else 58-_[x-1]if y==47else y-48for x,y in enumerate(_)];t=0;exec('t+=sum(_[:2+(_[0]+_[1]>=10)]);_=_[2-(_[0]==10):];'*10);print t Run it online I'd like to write a bowling calculator. I'm fairly pr...
Challenge: Create a program that prints out the size of its own source code file. For example, a 35 bytes size of program must print out 35. Pre-calculation is not valid. What I mean by pre-calculation is: // test.js -> its size is 15 byte console.log(15) It must dynamically calculate the size of own source code fi...
Introduction Briscola is one of Italy's most popular card games. It is a trick-taking card game, like Bridge. Briscola is well known for its bizarre point system. In this challenge, given two cards, you will output whether the first one scores more, less, or the same number of points as the second in Briscola's point s...
Given a number from 1 to 24, output the kissing number to the best of current knowledge (some numbers will have more than one acceptable output). Knowledge of geometry is not essential as the outputs are all listed below. From the Wikipedia page on the Kissing Number Problem: a kissing number is defined as the number ...
A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. Calculate the number of perfect squares below a number \$n\$ where \$n\$ will be taken as an input Examples: There are 9 perfect squares below 100: 1, 4, 9, 16, 25, 36, 49, 64, 81 Constrain...
Math has a lot of symbols. Some might say too many symbols. So lets do some math with pictures. Lets have a paper, which we will draw on. To start the paper is empty, we will say that is equivalent to \$\top\$ or \$\textit{true}\$. If we write other things on the paper they will also be true. For example Indicates ...
Not to be confused with this question. You need to draw a times table (also known as Cremona's method for cardioid generation) as shown in this video. The number \$n\$ and \$k\$ will be the inputs. In the video n and k are 2 and 10 respectively. How to draw? Draw a circle, divide its perimeter into equal spaced parts...
Given positive integers \$w\$ and \$h\$ output \$w\$ columns and \$h\$ rows of text as described below. The first row begins with 11 0s, the second row with 10 1s, third with nine 2s and so on down the the tenth row with two 9s. On each of these first ten rows, following the initial run of consecutive digits, the next ...
Challenge: Given a list of nonempty lists of integers, return a list of tuples of the following form: First list tuples starting with each element of the first list followed by the first element of every subsequent list, so the ith tuple should be [ith element of first list, first element of second list, ... , first el...
Introduction Your challenge today (inspired by this challenge) is to write a number of snippets, functions or full programs each that output various ascii emoticons, without reusing characters. Challenge The list of valid ascii emoticons for this challenge is both here and in the code block at the bottom of this post....
Traveling with electronics is always fun, especially when you need an adapter to charge them. Your challenge is to make planning a trip a little easier by checking if a given plug will be compatible with a given socket. Challenge Given a plug type and a socket type, return a value that indicates whether they will work ...
Background: the Ramsey number \$R(r,s)\$ gives the minimum number of vertices \$v\$ in the complete graph \$K_v\$ such that a red/blue edge coloring of \$K_v\$ has at least one red \$K_r\$ or one blue \$K_s\$. Bounds for larger \$r, s\$ are very difficult to establish. Your task is to output the number \$R(r,s)\$ for ...
I use "suffix" loosely here to mean "any sub-string that follows the prefix". "Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first character of the input text (for the first word). A "prefix" in the middle of a word is ignored. E.g. if your input prefix is "...
Given two line segments, determine if the line segments intersect and if so, where. In the case that the two given line segments are co-linear and overlap, determine the midpoint of the overlapping segment. Lines will be specified in pairs of (x, y) coordinates. Examples [(-1, -1), (1, 1)], [(-1, 1), (1, -1)] => (0, 0...
Description OEIS sequence A096004 gives the Number of convex triangular polyominoes [polyiamonds] containing n cells. It begins: 1, 1, 1, 2, 1, 2, 2, 3, 2, 2, 2, 3, 2, 3, 3, 5 For example, a(8)=3 with the following three convex polyiamonds: Input: 8 Output: *---*---*---*---* / \ / \ / \ / \ / *---*---*---*---* ...
Defintion A centrosymmetric matrix is a square matrix that is symmetric about its center. More rigorously, a matrix \$A\$ of size \$n \times n\$ is centrosymmetric if, for any \$i,\: j \in ([1, n] \cap \mathbb{Z})\$ the following relation is satisfied: $$A_{i,\:j}=A_{n+1-i,\:n+1-j}$$ Examples of such matrices Here is a...
Challenge Given a positive integer N, output the sum of the first N reciprocals as an exact fraction, which is represented as a pair of integers in a consistent order representing numerator and denominator. Rules Output must be exact. Output should be as a pair of integers in a consistent order representing numerator ...
Given 2 brainfuck code snippets A and B, output some brainfuck code C which has the same behavior as running B with the input of As result. Note that C must work for any input that match the following assumptions, as if it were given to A. You can assume: Finite input. both A and B halt. EOF is consistently 0 or consi...
Rearrange a given list such that all the odd numbers appear before all the even numbers. Besides for this requirement, the output list may be in any order. The input will only contain integers, but they may be negative and there may be duplicates, and they may appear in any order. Shortest solution wins. Test cases [1,...
Imagine the following 24-hour clock that can be controlled by arrow keys: ╔══╗ ┌──┐ ║00║:│00│ ╚══╝ └──┘ HH mm Pressing the up arrow twice (↑↑) will increase the currently focused hour input: ╔══╗ ┌──┐ ║02║:│00│ ╚══╝ └──┘ HH mm Pressing the right arrow (→) will focus the other input. ┌──┐ ╔══╗ │02│:║00║ └──┘ ╚══...
...or Toroidal Moore Neighbourhoods Given positive integers h, w and a non-negative integer i, return all of the indices surrounding i. You are to assume a matrix consisting of h rows of w elements, numbered from lowest, in the top left-hand corner, to highest, in the bottom right-hand corner, and return, in any reaso...
Challenge Given nine numbers, a, b, c, d, e, f, g, h, i, as input which correspond to the square matrix: $$\mathbf{M} = \begin{pmatrix}a& b& c\\ d& e& f\\ g& h& i\end{pmatrix}$$ Find the inverse of the matrix, \$\mathbf{M}^{-1}\$ and output its components. Inverse Matrix The inverse of a matrix 3 by 3 obeys the followi...
Related: Let's design a digit mosaic, Print/Output the L-phabet. Sandbox post here Given 2 inputs C = columns and rows, S = starting point output a matrix as follow: Input 4, 3 1 2 3 0 2 2 3 0 3 3 3 0 0 0 0 0 Explanation Given C = 4, S = 3 1) Create a C x C matrix filled with 0 4 colu...
In the spirit of Solve the Halting Problem for Befinge, let's define another 2D language called Modilar SNISP. Modilar SNISP has the following six instructions: \ directs the instruction pointer as follows: if approached from the top, go right; if approached from the right, go up; if approached from the bottom, go l...
In Russia we have something like a tradition: we like to look for lucky tickets. Here's what a regular ticket looks like: As you can see, the ticket has a six-digit number. A six-digit number is considered lucky if the sum of the first three digits is equal to the sum of the last three. The number on the photo is not...
Kids-related intro Whenever I take my kids to an amusement park, the kids get more nervous the closer we are to the park, with the nerve peak when we are in the parking lot and find no place to park. So I've decided I need a method to find the closest free parking space to minimise the time spent parking. Technical int...
Challenge Given an image of the Moon as input, output the phase of the Moon. Phases of the Moon Your program will be supplied one of these images in png format and you must output the phase exactly as given: new moon hexdump waxing crescent hexdump first quarter hexdump waxing gibbous hexdump full moon hexdump...
If we take the natural numbers and roll them up counter clock-wise into a spiral we end up with the following infinite spiral: ....--57--56 | 36--35--34--33--32--31--30 55 | | | 37 16--15--14--13--12 29 54 | | | | | 38 17 ...
Consider the following list: expected = [ 'A', 'B', 'AB', 'C', 'D', 'CD', 'ABCD', 'E', 'F', 'EF', 'G', 'H', 'GH', 'EFGH', 'ABCDEFGH', 'I', 'J', 'IJ', 'K', 'L', 'KL', 'IJKL', 'M', 'N', 'MN', 'O', 'P', 'OP', 'MNOP', 'IJKLMNOP', 'ABCDEFGHIJKLMNOP', ... ] Here's one way to look at it - you're learning how to write Chinese...
Given three non-negative integers y, m, and d (of which at least one must be positive) and a valid date with a positive year (in any reasonable format that includes the year, month, and day, and no additional information), output the date that is y years, m months, and d days after the original date. The Gregorian cale...
Background An ex-increasing set sequence of order \$N\$ is defined as a sequence of integer sets \$S_1,S_2,\cdots,S_n\$ which satisfies the following: Each \$S_i\$ is a non-empty subset of \$\{1,2,\cdots,N\}\$. For \$1\le i<n\$, \$S_i \cap S_{i+1} = \varnothing\$, i.e. any two consecutive sets have no elements in comm...
Introduction We all know the cool S (also known as Superman S, Stüssy S, Super S, Skater S, Pointy S, Graffiti S etc. etc.): billions of schoolchildren around the world drew this S and immediately felt proud of themselves. In case you've forgotten or had a completely uncool childhood, here is an image of said cool S: ...
Your program has to have an year like 1957 to be the input and then output the century of that year. For example: In: 1946 Out: 20 In: 1705 Out: 18 In: 1900 Out: 19 In: 100 Out: 1 In: 2001 Out 21 because 1946 is in the 20th century. Keep in mind that 2000 should be 20th century or 1900 should be in 19th century. There...
Introduction Today's challenge is all about teeth. Specifically, how long it takes to brush from one tooth to another. Your challenge is, given the locations of two teeth, output the shortest amount of time possible to brush from the first to the second. Challenge For this challenge we will be using a layout of an aver...
Challenge Write code which, given an image of a panel from a random xkcd comic, returns a truthy value if Blackhat is in the comic or falsey if not. Who is Blackhat? Blackhat is the unofficial name given to the character in xkcd comics who wears a black hat: Taken from the Explain xkcd page on Blackhat Blackhat's hat ...
Within the recesses of Unicode characters, there exists a Unicode block of (currently) 63 characters named "Number Forms", which consists of characters that have numerical values such as the roman numeral Ⅻ, vulgar fractions like ⅑ or ↉, or weird ones like ↊ (10) or ↈ (100000). Your task is to write a program or functi...
TeaScript is a powerful JavaScript golfing language created by StackExchange, PPCG, user Downgoat. TeaScript compiles to JavaScript and contains many helpful features for golfing This question is to list some TeaScript golfing tips
Create a program (any language) which, given positive integer m, outputs a valid C expression that: Uses a single variable x assumed of 32-bit unsigned type (i.e. uint32_t) Would evaluate to range [0, m) for any of the 2³² possible x, reaching any of the m possible outcomes either 2³² / m or 2³² / m + 1 times (where /...
In elementary school, children learn about proper fractions, where the numerator is less than the denominator, and thus the value of the fraction is less than one. Later, they are taught about fractions where the value of the fraction is greater than one, and two different ways to express these fractions: mixed fractio...
In a now deleted stackoverflow question, someone posted the following: Write a program or function to print alternating patterns in * and # based on a given integer n. Some examples: Input: n=1 Output: * Input n=5 Output: *#### ###** ***## ###** *#### Input: n=8 Output: *####### ######** ***##### ####**** ****#### ##...
It's Christmas in July, so what better way to celebrate than a virtual white elephant gift exchange! For this King of the Hill challenge, you must create a bot that plays in a White Elephant exchange simulation, trying to get the highest-valued present it can. Game Rules The game will be played over many rounds, each ...
Challenge Given a list of integers and a velocity, \$v\$, implement a sorting algorithm which simulates a program sorting the list from smallest to biggest at the given velocity. Einstein's Theory of Special Relativity What do I mean? Well assume your program takes a time, \$T\$, to sort a particular list. If you ran t...
An office (let's call it "The Office") is going to cut down on wasted time in 2019 by consolidating office birthday parties. Any two people with a birthday between Monday and Friday (inclusive) of the same week will be celebrated with a Shared Birthday Party some time that week. People whose birthdays fall on a Saturda...
Most tip calculator apps simply take a flat percentage of the meal price. So, for example, if your meal is $23.45, you can leave a 15% tip = $3.52, or a more generous 20% tip = $4.69. Convenient enough for credit card users. But not so if you prefer to leave cash tips, in which case these oddball cent amounts get in ...
It's likely that anyone who used Twitter a couple of months ago would know about the 'Howdy! I'm the sheriff of X" meme. Where a simple image of a sheriff is drawn with emoji, and changes to fit a theme. So I thought it was time for the Sheriff of Code Golf. Here he is: ### ##### ### ### ### # ...
Related: Name the poker hand A straight flush is a poker hand containing five cards of sequential rank, all of the same suit. As part of a straight flush, an ace can rank either above a king or below a two. An ace can rank either high (e.g. A♥ K♥ Q♥ J♥ 10♥ is an ace-high straight flush) or low (e.g. 5♦ 4♦ 3♦ 2♦ A♦ is ...
I can't believe we don't have this already.. It's one of the most important data-structures in programming, yet still simple enough to implement it in a code-golf: Challenge Your task is to implement a stack that allows pushing and popping numbers, to test your implementation and keep I/O simple we'll use the following...
This is a 2-dimensional version of this question. Given a non-empty 2-dimensional array/matrix containing only non-negative integers: $$ \begin{bmatrix} {\color{Red}0} & {\color{Red}0} & {\color{Red}0} & {\color{Red}0} & {\color{Red}0} \\ {\color{Red}0} & {\color{Red}0} & 0 & 1 & 0 \\ {\color{Red}0} & {\color{Red}0} & ...
Time sheets In a work place you often have to complete time sheets. This task is write code to help this. Input Two times in a slightly non- standard 12 hour clock signifying the start and end of the day separated by a space. A third number represents the number of minutes taken for lunch. For example 9:14 5:12 30 Th...
This is a code golf version of a similar question I asked on stack earlier but thought it'd be an interesting puzzle. Given a string of length 10 which represents a base 36 number, increment it by one and return the resulting string. This means the strings will only contain digits from 0 to 9 and letters from a to z. B...
421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually played in two rounds, with tokens that each player tries to get rid of, but this is irrelevant here. (Wikipedia page in F...
Motivation: Sometimes certain items in a list don't count towards your totals. For example, counting plane passengers in rows, where babies sit on a parent's laps. Challenge: write a program to split a list of items into chunks. Each chunk (except possibly the last) is the same size, where size is defined as the number...
Display the remaining battery charge, as a percentage of maximum charge Remember if you can't run your code on a phone, calculator, etc, you can probably install your environment on a laptop at least. If you absolutely can't run on a device that has a battery, then unfortunately your language isn't eligible since you h...
Related: Calculate Power Series Coefficients Given a positive integer \$X\$ and a max exponent (Also a positive integer too) \$N\$ calculate the result of a power series. Example: $$X^0+X^1+X^2+\cdots +X^N$$ Assume \$(X + N) \le 100\$ Test Cases 1 2 => 3 2 3 => 15 3 4 => 121 2 19 => 1048575 Standard code-golf ...
We define a tree-like list, or trist for short, as the empty list or a list containing only previously constructed trists. The natural numbers can either include 0 or not, according to your preference. The task is to create a pair of functions or complete programs f and g (they don't have to be named like this or even ...
The matrix tornado is just like any other tornado: it consists of things rotating around a center. In this case, elements of the matrix instead of air. Here is an example of a matrix tornado: First we start by sectioning the matrix into square rings, each section consists of elements that are farther away from the bor...
I'm a musician, and I need more polyrhythms in my life! A polyrhythm occurs in music (and in nature) when two events (claps, notes, fireflies flashing etc.) are occurring at two different regular intervals. The two kinds of event happen a different number of times in the same interval. If I tap with my left hand twice,...
Description Imaginary programming language (IPL) uses Polish Reverse Notation. It has the following commands: i -- input number and push it to the stack o -- non-destructive output top of the stack (number stays on the stack) d -- discard top of stack integer number -- push this number to the stack +-* -- pop two num...
Introduction In number theory, a number is considered evil if there are an even number of 1's in its binary representation. In today's challenge, you will be identifying whether or not a given number is evil. Challenge Your job is to write a full program or function which accepts a single, non-negative integer as input...
Non-associative operators (for example the subtraction-operator) often are either left- or right associative, such that one has to write less parentheses. Consider for example the following: $$ a-b-c $$ Probably everybody read that as \$(a-b)-c\$, by default (usually) subtraction is left-associative. Now let us conside...
We call a parens group the open paren (, its matching close paren ) and everything inside them. A parens group or string is called parenthesly balanced if it contains either nothing or only 2 parenthesly balanced parens groups. For example: The string "(()())()" is parenthesly balanced ( )() ...
You are chained to a chair. Underneath you is a huge volcano. A 12-hour clock next to you ticks ominously, and you see that it has wires leading from the back up to a chain, which will drop you into the center of the earth. Taped to the clock is a note: Each clock hand has an electrode. When both clock hands are in th...
NOTICE: This challenge is now closed: I will no longer be updating the leaderboard and will not change the accepted answer. However, you are free to run the controller and update the leaderboard yourself, if you wish. Join the chat! Introduction Good evening, traders! You are all traders for the golfing company PPCG....
Sandbox post (deleted) The old roman army formations are very famous around the world. In these formations roman legionaries grouped in a geometric shape (usually a rectangle) protecting the flanks and the superior part of it using their shields. The legionaries at interior positions covered the superior part placing t...
I'm trying to get the shortest way (character possible) to obtain List 3. List 1 and List 2 are already given to me as arguments and are the same length. l1 = [1, 2, 3, 4, 5] l2 = ['a', 'b', 'c', 'd', 'e'] And List 3 should look like (yes, it needs to be a list): l3 = ['a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5]
Introduction I have some JavaScript code that uses Array.prototype.map to map an array of functions fns to their return values: const fns = [() => 1, () => 2]; const result = fns.map( fn => fn() ); console.log(result); // => [1, 2] Challenge The argument to map above is fn => fn(). The challenge is to rewrite th...
Input A non-empty binary matrix consisting of 3x3 sub-matrices put side by side. Task Your task is to identify valid dice patterns (as described below) among the 3x3 sub-matrices. Each valid pattern is worth the value of the corresponding dice. Invalid patterns are worth 0. Output The sum of the valid dice values. Dice...
Goal Given a deal result from Duplicate Contract Bridge, calculate the deal score. Basically the same as iBug's question, which was deleted. I figured out this scoring system while trying to answer that question. Input Input is a deal result, and whether or not the declaring side is vulnerable. The deal result is a str...