instruction
stringlengths
34
53.1k
Write an irreducible proper quine, i.e. a program that prints its own source code, which can't be reduced by removing characters to a shorter program with the same constraints. Eg. the python quine: var='var=%r;print(var%%var)';print(var%var) can be reduced to the quine v='v=%r;print(v%%v)';print(v%v) thus it is no...
Given a list of Integers greater than zero, Sort each of the unique values in ascending order, then repeat the process on the remaining duplicate values and append. Example: [1,5,2,2,8,3,5,2,9] ==> [1,2,3,5,8,9,2,5,2] [8,5] ==> [5,8] [2,2,2] ==> [2,2,2]
I want an n*n table that is filled with black or white and the following conditions are satisfied in it: All cells of a 2*2 square in this table should not be the same color. All black and white cells must be connected horizontally or vertically. Acceptable examples: Can anyone design a function that takes n as inpu...
Given a list of non-negative integers the function \$f\$ replaces every integer with the number of identical integers preceding it (not necessarily contiguously). So f [1,1,2,2,1,3,3] = [1,2,1,2,3,1,2] We will say that a list, \$X\$, is in a loop if there is some positive integer \$n\$ such that \$f^n X = X\$. That i...
What am I? As a plant cell, your program/function/etc. must undergo photosynthesis: When the input is 6CO2+6H2O+light in any order, output C6H12O6+6O2 in any order. It does not have to be the same for each arrangement of the input. When the input is just r, replicate (i.e. output your own code). quine rules apply. Whe...
Consider an \$n \times n\$ grid and a circle of radius \$r \leq \sqrt{2} n\$ with its center in the top left. In each square there is an integer from the range -3 to 3, inclusive. For a given radius, there is a set of squares in the grid which are not at least half covered by a circle of radius \$r\$ but are at least ...
In this challenge you will write code to take a list of positive integers and output all maximal linear sublists. A sublist is is a list which can be created by deleting values from the the input list. Sublists have more structure than just lists. They in a way "remember" which values are deleted. Similarly we say tha...
Consider an \$n \times n\$ grid of integers. The task is to draw a straight line across the grid so that the part that includes the top left corner sums to the largest number possible. Here is a picture of an optimal solution with score 45: We include a square in the part that is to be summed if its middle is above o...
Challenge This challenge is based on the domino effect: Initially, each domino is located on one straight line and is in a vertical state. It can be dropped either to the left along the same straight line, or to the right. Then this domino will knock down the next one, and that one, perhaps, the other. The dominoes are...
Given a string of ASCII text as input, encode it in BPSK31 using Varicode. You may either output an audio file in any common format, or play the audio over the device speakers. You may output at any sample rate and with any carrier frequency between 500 Hz and 2500 Hz. The sample rate and carrier frequency must be cons...
You know what a monotonic sequence is: each element is bigger than its predecessor (monotonically rising) or as its successor (monotonically falling). Bitonic means you have two arms of the sequence, one monotonically rising, the other falling. For example, 1,3,5,7,6,4,2 is bitonic (rising until 7, then falling until t...
The flick input method is a way of inputting Japanese kana on a modern smartphone. It is arranged in a 12-key layout, with the following labels: あかさ たなは まやら 小わ、 When a key is tapped, it produces its respective kana. However, when the key is flicked in one of the four cardinal directions (up, down, left, right) it prod...
Disclaimer: the content of this post is not medical information and should not be used for any medical purpose, as it is deliberately oversimplified for the purpose of the challenge. There are several different strains of Neisseria meningitidis, the bacterium that causes meningococcal meningitis. Vaccines are available...
The following problem is taken from the real world — but indubitably code-golf! In this puzzle, the programming language is fixed, and your job is to write the most efficient program in this fixed language. The language has no loops; a program is a straight-line sequence of instructions. Each instruction consists of ex...
For this problem you are given an \$n \times n\$ matrix of integers. The task is to find a pentagon in the matrix with maximum sum. The pentagon must include part (or all) of the x and y axes as two of its sides starting from the top left cell. All the sides except one must be horizontal or vertical. The remaining si...
Input a datetime, format the datetime in YYYY-MM-DD HH:mm:ss format using 30-hour clock time. The 30-hour clock time works as: After 6 a.m., it is same as 24-hour clock time Before 6 a.m., it use date for previous day, and plus Hours by 24. For more examples, you may checkout the testcases. Rules To simplify the que...
Introduction In the video the best way to count, binary is proposed as the best system of counting numbers. Along with this argument is a proposal on how to say numbers in this system. First, we give names to each "double power of two", \$2^{2^n}\$ for each \$n\$. number = symbol = spoken ============================ 2...
Related: Sort these bond ratings Credit rating agencies assign ratings to bonds according to the credit-worthiness of the issuer. The rating business is mostly controlled by "Big Three" credit rating agencies (i.e. Fitch Ratings, Moody's, and Standard & Poor's (S&P)), which use a similar tiered rating system. Task For ...
This is an exact inverse of the question Convert to Spoken Binary. This introduction is copied from there. Introduction In the video the best way to count, binary is proposed as the best system of counting numbers. Along with this argument is a proposal on how to say numbers in this system. First, we give names to eac...
You want to draw a regular polygon but you have limited space! In this challenge, you should draw a polygon with n sides which is as big as possible for a given square container image. I found surprisingly little information on the Internet about inscribing a polygon into a square. To save you the hassle, I verified th...
Input An integer n and a pair of distinct integer valued (x, y) coordinates on the boundary of the grid. The coordinates are indexed from 1. For example, n=10 and (1,2), (10, 7). The points will always be on different sides of the grid and neither of them will be \$(1, 1)\$. Output The number of integer points in an n...
Given two non-empty 01 strings, check if there is string containing both given strings, and their first appearance end at same position. Test cases: 01, 1 => true (01) 0, 00 => false (0 would at least come 1 character earlier) 01, 11 => false (can't meet on same position) 01, 0 => false (can't meet on same position) 11...
if you have a range of numbers with values missing, eg l=[1,2,9,10,99], you can always use modulus and subtraction to make all the numbers in the list cover a smaller range, for example: l%99%6=[1,2,3,4,0]. your task is to take in a list of numbers and output an equation which will map them to unique numbers in the ran...
In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that: All positive integers are contained infinitely many times within the sequence. As more and more terms are added to the sequence, for all positive integers \$n\$, the ratio of the number of \$n\$s to...
Objective Write a full program that works exactly like the flow chart below. Each output, which is an integer, shall be through stdout, followed by a line feed. Each input shall be a line of string fed through stdin, and shall be judged to a predicate you choose for branching. The same predicate must be used for all br...
The Dutch system for naming one's ancestors is a lot more interesting than the English version. For English, the sequence goes "parent", "grandparent", "great-grandparent", "great-great-grandparent", "great-great-great-grandparent"; and in Dutch those terms are "ouder", "grootouder", "overgrootouder", "betovergrootoude...
Classic Tetris was often a difficult game to play. One problem was that you could only work with the Tetris piece you were given, so if you had an awkward board, it would sometimes be difficult to find a suitable location to put your piece. Another problem was that you could only look one piece ahead, so it was difficu...
Consider a 10 by 10 grid of points at integer coordinates. Given a coordinate (x, y) of one of the points in the grid and a radius r, some of the points in the grid will fall inside a circle of radius r that is centered at (x, y). You will count the number of such points. Input An integer coordinate (x, y) in a 10 by...
Background The monkeys need your help again organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options as they appear in your insta-monkey collection. Each tower has three unique upgrade "paths", called "top", "middle", and "bottom", each having a...
Happy New Year 2024! 2024 is a tetrahedral number. A tetrahedral number is a number that can be represented in the form \$n(n+1)(n+2)/6\$ for some positive integer \$n\$. Or, equivalently, they are the sum of the first \$n\$ triangular numbers. They are also the number of objects in a triangular pyramid which has \$n\$...
OEIS sequence A003242 comprises the numbers of Carlitz compositions for any given positive integer. This is the number of integer partitions of the integer for which no two adjacent parts are equal. For example, for 4: Generate the possible integer partitions (and their permutations): [1,1,1,1], [1,1,2], [1,2,1], [2,1...
In most programming languages, the string Hello, World! can be represented as "Hello, World!". But if you want to represent "Hello, World!" you need to escape the double quotes with backslashes for "\"Hello, World!\"", and to represent that you also need to escape the backslashes resulting in "\"\\\"Hello, World!\\\"\"...
Given a constructible point \$(x, y) \in \mathbb R^2\$, output the steps required to construct \$(x, y)\$ Constructing a point Consider the following "construction" of a point \$(\alpha, \beta)\$ in the Cartesian plane: Begin with the points \$(0, 0)\$ and \$(1, 0)\$. Then, more points can be added by performing a fini...
Following the great advice (what do you mean it's not advice?!) on Adding unnecessary fluff we can devise the following task: Take a list of positive integers and a positive integer \$m\$ as input. Only keep the prime values from the list. Define \$f(n) = F_{n^2 + 1}\$ (the \$n^2+1\$-th element in the Fibonacci sequen...
So simple: Provide some code that outputs foo and with the reversed source outputs bar. But before you come up with something like this boring python 2: print "foo"#"rab" tnirp you should know the score: You multiply the number of bytes with (1 + dead bytes), where dead bytes are bytes that can be changed to most othe...
I was wondering if it was possible to make this code even shorter than it already was. f=lambda x:f(x-1)+f(x-2) if x>1 else 1 [print(f(i))for i in range(20)] Expected output: 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 Good luck, "golfers" (I'm assuming thats what you guys are called) Note: spe...
Challenge Display Inky the ghost from Pac-Man using only ANSI escape codes. Here's a text representation of the image B B B B B C C C C B B B B B B B B C C C C C C C C B B B B B C C C C C C C C C C B B B C W W C C C C W W C C C B B W W W W C C W W W W C C B B E E W W C C E E W W C C B C E E W W C C E E W W C C C C C W...
Given two strings containing only 0 and 1, decide the probability that first appears earlier as a consecutive substring in an infinite random 0/1 stream. You can assume that neither string is suffix of the other string, so 01, 1, 00, 0 are invalid. (*) IO format flexible. Your answer should be precise given ideal float...
Write a program to calculate the first 500 digits of the mathematical constant e, meeting the rules below: It cannot include "e", "math.e" or similar e constants, nor may it call a library function to calculate e. It must execute in a reasonable time (under 1 minute) on a modern computer. The digits are to include the...
Consider an \$n \times n\$ grid of integers which is part of an infinite grid. The top left coordinate of the \$n \times n\$ grid of integers is \$(0, 0)\$. The task is to find a circle which when overlaid on the grid gives the largest sum of values inside it. The constraints are: The circle has its centre at \$(x, x...
This quite literally came to me in a dream. A common combination padlock design has letters on the dials so you can set the combination to a word. Unfortunately, I can't read, but I can count. Considering I am in a hurry, send the shortest path around the dials to open the 4 letter lock, given the current letters and t...
Input A single-character string containing an uppercase or a lowercase letter from the English alphabet. Alternatively, you may handle only uppercase or only lowercase letters as input. Output This 3x3 typeface of the input letter (source), with two distinct, printable ASCII characters of your choice (excluding tabs a...
Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two points. Use any maths formula you like, such as $$gcd(|x_2 - x_1|, |y_2 - y_1|) - 1$$ Input Four integer coordinates of...
Given an n non-negative integers, how many numbers must be changed so that each number x appears x times? You cannot add or remove elements, only replace them with other numbers. For example: 1 6 23 6 9 23 1 1 6 can be turned into: 1 6 2 6 6 2 6 6 6 with 5 changes, which is optimal. Test cases 0 => 1 1 2 3 => 1 5 5 5...
I found this YouTube video with a table on it showing some card suits with ampersands. You might not understand what it is about, but I still want to make a challenge about it. The input is two suits, being one of the following: heart diamond spade club You can do anything for any other input. Then the output is their...
Consider the sequence 1/2, 1/3 + 1/2, 1/4 + 1/3 + 1/2, and so on. In mathematical symbols, this is $$S(n)=\sum_{m=2}^{n+1}\frac{1}{m}$$ where S is the function that makes the sequence. Outputting this sequence as a fraction would not be complicated. To add depth to the challenge, you must output as a repeating decimal....
Abracadabra is a magic word. To make it even more magical, let's make several alterations to how it may be written: Change the casing for any subset of characters; for example: aBrAcAdAbRa Append an exclamation mark to it: abracadabra! Change each occurrence of a into a different vowel: ybrycydybry Change any single c...
Every Brazilian citizen has a national identification number associated with them, named CPF. This number has 11 digits (formatted as XXX.XXX.XXX-XX) and it's validated by the following (real) algorithm1: Take the 9 most significant digits of the number. Call it c. Multiply the n-th least significant digit of c by n+1...
Input Two non-negative floating point numbers \$x < y\$. You can assume they are close enough to each other that there is no integer between \$x\$ and \$y\$. Output A fraction with the smallest possible denomination that lies strictly between \$x\$ and \$y\$. Examples Input: 1 and 2 Output: 3/2 Input: 0 and 0.33 Output...
Can you decrypt me? Cops Cops, post obfuscated code that hides a number \$n\$ (n must not be greater than the program length) inside its code. If \$n\$ chars are changed (no additions or deletions), the program outputs exactly one \$n\$ (any amount of whitespace before or after is allowed.) Otherwise, it outputs someth...
Can you decrypt me? Robbers Find any combination of \$n\$ working chars to change and what they should change into, where \$n\$ is chosen by the cop. You cannot change less than n chars, only exactly \$n\$. Example print(2) N is 1. Robbers' post: print(1) Scoring For the robbers, the user with the most cracks wins. ...
The challenge, should you accept it, is to determine how much you win in the Bingo Golf Flax Lottery. Based on but not equal to the BingoFlax lottery The input is two lists of numbers (positive non-zero integers). The first list always contains 24 potentially non-unique numbers that make up your board, a 5 x 5 grid of ...
The task is simple, divide, get the quotient and the remainder, and if the remainder isn't 1 or 0, do the same thing (quotient divmod remainder) until the remainder is 1 or 0, then get the remainder. If the last input number is 1 or 0, output it. If the input is [15, 4], then the output would be 0, because the divmod o...
Select any word from https://websites.umich.edu/~jlawler/wordlist with length greater than 1. For each letter on that word, remove it and check if any rearrangement of the remaining letters is present in the wordlist. If it is, this rearrangement is a child anagram of the original word. For example, theism: removing t...
I define mousetail's sequence as follows: If the nth element of the sequence is q, then n+1 must appear q times in the sequence The sequence is weakly monotonically increasing (i.e. no lower number may follow a higher number) f(1)=1 I'll show an example of how this works: the first element is 1 after the 1, come 1 2...
Consider a horizontal line with vertical lines centered on the x-axis and placed at gaps of \$\sqrt{2}/2\$. For a positive integer \$n \geq 3\$, the first half of the lines have lengths \$0, \sqrt{2}, 2\sqrt{2}, 3\sqrt{2}, \dots, (n-1)\sqrt{2}\$ and then the second half have lengths \$(n-2)\sqrt{2}, (n-3)\sqrt{2}, \do...
Write a program that takes a United States aircraft registration number and returns a 24-bit ICAO hex code corresponding to that registration and vice-versa. An aircraft registration number always begins with an N and is followed by 1 to 5 characters: 1 to 5 digits and then 0 to 2 uppercase letters. That is, one of the...
Challenge Determine how many integer lattice points there are in an ellipse $$\frac{x^2}{a^2} + \frac{y^2}{b^2} \leq 1$$ centered at the origin with width \$2a\$ and height \$2b\$ where integers \$a, b > 0\$ . Input The Semi-major \$a\$ and Semi-minor \$b\$ axes. Output Number of interior and boundary points. Example E...
The following data contains the (approximate) population of each UTC timezone in the world (source): UTC;Population (in thousands) -11;57 -10;1853 -9.5;8 -9;639 -8;66121 -7;41542 -6;272974 -5;332101 -4.5;31923 -4;77707 -3.5;499 -3;248013 -2;4855 -1;3285 0;285534 +1;857443 +2;609921 +3;496279 +3.5;81889 +4;129089 +4.5;3...
Challenge Generate \$n-1\$ consecutive composite numbers using this prime gap formula $$n!+2,n!+3,...,n!+n$$ Input An integer \$n\$ such that \$3 \leq n \leq 50 \$. Output Sequence of \$n-1\$ consecutive composite numbers. Example Input 3 Output 8 9 Rules Output should be in integer format. Test Cases For \$n > 20\...
What general tips do you have for golfing in Uiua? I'm looking for ideas that can be applied to code golf problems in general that are specific to Uiua. (e.g. "remove comments" would not be an answer.) Please post one tip per answer.
In this challenge you are asked to find in how many ways we can express a positive integer n as the sum of two positive integers k and the reverse of k. Here is an example using n = 1069 : 188 + 881 = 1069 287 + 782 = 1069 386 + 683 = 1069 485 + 584 = 1069 980 + 89 = 1069 So, the answer here would be 5. rules As you ca...
I found another sequence not yet in the OEIS The binary expansion sequence is defines as follows, assuming 0 indexing: The even numbers of the sequence are how often 0 has appeared in the binary expansion of all previous items in the sequence The odd elements are the same, but for 1s. If you choose to 1-index, revers...
Historic Tetris Achievement Blue Scuti became the first ever human to beat the classic game of Tetris on NES. Here's the Tetris Kill Screen Challenge Output the following Tetris Kill Screen board (10x20 blocks) EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEEEEEEE EEEEGGEEE...
Input A non-empty string or list of capital letters k with length between 3 to 5000. Output A value indicating whether k can be expressed as a+b+b, where a and b are non-empty. Truthy test cases SSS SNYYY SNYY SNNYY SNYNY Falsy test cases FALSYTESTCASES FALSYFALSYTESTCASES FALSYTESTCASESXFALSYTESTCASES FALSYTESTCASESF...
Input An integer k composed of 1 and 2, with at least 3 digits and at most 200 digits. Output Another integer k' obtained by removing at most one (could be none) digit from k, such that k' is composite, and then another integer p for a non-trivial (that is, not 1 or k') factor of k'. Test Cases 121212 -> 121212 10101 1...
Earlier I asked about this problem on stackoverflow (link), but now I also want to see the golfiest solutions Problem: Given an array of arbitrary numbers, what is the longest subarray that is repeated (appears more than once)? In case there are multiple distinct repeated subarrays that all have the longest length, the...
Validate a codice fiscale Every Italian resident/citizen is given a 16-character alphanumeric codice fiscale Challenge The final letter is a check code, which is calculated as follows : Characters of the code are split up into even and odd character according to their positions (check letter excluded) Both sets are re...
Given a sequence of three integers, determine if the sequence is arithmetic (of the form [a, a+d, a+2*d]) or geometric (of the form [a, a*r, a*r^2]) by outputting a fourth term that completes it (a+3*d for arithmetic, a*r^3 for geometric). Examples: [1, 2, 3] -> 4 (This is an arithmetic sequence with a difference of 1)...
Given a string \$X\$ we will say two strings, \$a\$ and \$b\$, are building blocks of \$X\$ if \$X\$ can be made by concatenating some \$n\$ \$a\$s with \$m\$ \$b\$s in any order. For example the string tomato has building blocks to and ma: to ++ ma ++ to We will say that the fineness of a set of building blocks is th...
The Roman numeral for 499 is usually given as CDXCIX which breaks down as CD + XC + IX = 400 + 90 + 9 where numerals like CD and IX are written using subtractive notation. Some programming languages have a roman() function that extends this subtractive notation through various relaxation levels. From Google Sheets docu...
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \end{cases} $$ Since it can be proved that it always terminates and evaluates to the simple function below, $$ t(x, y, z) = \begin{...
Inspired by Greg Martin's "Shiny cryptarithm" puzzle. A cryptarithm is a game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters of the alphabet. The goal is to identify the value of each letter. They are usually represented by an addition operation, such as SEND + MORE...
Imagine you are given an array/string containing \$5\$ letters of the English alphabet, with each letter having any value from A to Z (inclusive). Every day, each letter will perform a job, which can affect itself or other letters in the array. The letter's job is determined by the letter itself. Most letters are, due ...
The goal of this challenge is to compare how well different programming languages support functional programming, by seeing how much code it takes to implement BLC8, the simplest functional programming language BLC8 is the bytewise variant of Binary Lambda Calculus, as described in my 2012 IOCCC entry at https://www.io...
The well known cat command simply copies its stdin directly to stdout unchanged. But there are plenty of other commandline tools that exist... What other commands can be used to duplicate the functionality of the venerable cat? Rules You are not allowed to use any shell features, including pipes, file redirection, var...
A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. For those who are not aware of how knights in chess work, knights are capable of moving in an L shape (see fig. 1). (Or a ߆ shape, or even a \ shape depending on who you ask.) Essentially, in one move,...
Othello/Reversi is a board game in which players take turn placing pieces of a color (dark or light) on the 8x8 board. The possible moves are positions where there are one or more pieces of the opponent's color in a straight (horizontal, vertical, or diagonal) line between that position and a piece of the player's colo...
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$: $$ t(x, y, z) = \begin{cases} y, & \text{if $x \le y$} \\ t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise} \end{cases} $$ It can be proved that it always terminates and evaluates to the simple function below: $$ t(x, y, z) = \begin{cases}...
Your program should print the following: **Language, XXX bytes** ``` CODE ``` or its equivalent. XXX should be substituted by the actual number of bytes your program takes, and CODE should be substituted by the source code of your program. Language should be substituted by the actual language your program is in. Your...
Given two numbers \$x,y > 2, x≠y \$ output all integers \$m\$ such that $$ x + y \equiv x \cdot y \pmod m $$ $$ x \cdot y > m > 2 $$ Input Two integers Output A list of integers Test cases 3, 4 -> 5 5, 8 -> 3, 9, 27 29, 9 -> 223 26, 4 -> 37, 74 13, 11 -> 7, 17, 119 6258, 571 -> 463, 7703, 3566489
Consider an array A of integers of length n. The k-max subarray sum asks us to find up to \$k \leq 3\$ (contiguous) non overlapping subarrays of A with maximum sum. If A is all negative then this sum will be 0. If A = [-1, 2, -1, 2, -1, 2, 2] and k=2 for example, then the two subarrays could be [2, -1, 2] and [2, 2] ...
Given an \$n \times n\$ matrix of integers, The task is to find the optimal dividing line that maximizes the sum of the integers on the same side as the top left corner. The dividing line should be connected and made up of only vertical and horizontal lines. For an example with a non-optimal dividing line: [[ 3, 0,...
Consider a function \$r\$ where $$ r(i,k)= \begin{cases} L_{i+1}-L_i, & \text{if}\ k =0\ \text{ (1st reduction)} \\ r(i,0)-r(\lfloor \log_2{k} \rfloor,k-2^{\lfloor \log_2{k} \rfloor}) & \text{if}\ k \geq 1\ \text{ (2nd reduction)} \end{cases} $$ where \$k<2^i\$ and \$L\$ is a finite sequence of integers. For example,...
Challenge Create a 3D word puzzle where the cube's dimensions match the length of the input word. The uppercase word (A-Z) must be validly placed within the cube in one of the fixed orientations: horizontally, vertically, or diagonally. The program should randomly place the hidden word and fill the rest of the cube wit...
I am exploring a unique approach to the classic problem of Reverse Polish Notation on code.golf. Unlike the conventional solutions, my focus lies on leveraging the eval function in GolfScript. This twist was inspired by a comment in a related thread, where the absence of eval was deemed a limitation. "It's a shame no ...
Your code-golf challenge is to find all occurences of a word in the 3d matrix. There is no restriction on I/O format. In the samples below, the word is presented, then a blank line, then the 2-dimensional layers from top to bottom, and the output, for each line, consists of a coordinate and a direction (x, then y, then...
Assumption A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked. Explanation Say you have 31 butts. That means, you can make 7 cigarettes from 28 butts and have 3 left over. Now, these 7 cigarettes will yield 7 butts when you're done smoking them. That means you have 3...
Challenge Given a positive integer \$N \ge 3\$, generate an alternating series of \$N\$ random numbers within the range \$[1, N]\$, such that their sum equals \$N\$. Expressed mathematically as $$N = \sum_{i=1}^{N} (-1)^{i-1} a_i$$ where \$a_i \in [1,N]\$ are random terms. Input \$N\$ Output A string representing the ...
Definitions The common methods to generate consecutive composites are $$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$ $$\overbrace{n!+2,n!+3,...,n!+n}^{\text{n-1 composites}}$$ $$\overbrace{n\#+2,n\#+3,…n\#+n}^{\text{n-1 composites (Primorials)}}$$ A less common method involv...
This small challenge derives from my annoyance at discovering that numpy doesn't have a built in function for it. Input An n by m matrix of integers. Output The maximum value in the matrix and the 2d coordinates of one of its occurrences. The coordinates should be in the order (row_idx, col_idx) if your code is no sho...
Given a string consisting of only printable ascii (letters, numbers, symbols, and spaces), how many keystrokes are required minimally to type out this string from scratch? That is, current text is initially an empty string and should end up being equal to the input string. These are the allowed actions and their cost i...
CHALLENGE This is a fastest-code challenge. Count how many n-dimensional hypercubes with n=1,2,3,4 exist, with vertices labeled with either 1 or 0, such that there does not exist any rectangle formed by 4 vertices such that one diagonal is 1-1 and the other diagonal is 0-0. To be more clear, the forbidden rectangles ha...
There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there can be three participants who won 2nd place, and the next best participant gets the 5th place. More rigorously, a partici...
Exposition In this challenge, I am talking about ARM assembly language. ARM is a 32-bit RISC processor; I'll use instruction set up to architecture v6. To load a constant ("immediate") value into a register, use the MOV instruction: MOV r8, #42 To load negative values, use the MVN instruction, with a bit-complement of...
What is Typoglycemia? Typoglycemia is a term that refers to the phenomenon where readers are able to understand text even when the letters in the middle of words are jumbled, as long as the first and last letters of each word remain in their correct positions. For example, Aoccdrnig to a rscheearch at Cmabrigde Uinerv...
Make a cat program, with a catch. The program must refuse under all circumstances to output "Hello World", instead outputting "Goodbye World", with matching spacing (but matching casing is not required). "Hello World" must never appear as a substring of the output, regardless of casing, not even if the two words are (o...
Given an array of integers A, the task is to output another array B of the same length so that B[i] is the maximum over A for every index that is not i. That is \$B[i] = \max_{i' \ne i} A[i']\$. Examples: A = [1, 5, -3, 4, 2]. B = [5, 4, 5, 5, 5] A = [1, 2, 3]. B = [3, 3, 2] A = [-1, -2, -3, -1]. B = [-1, -1, -1, -1] ...
Your challenge is to, given a matrix of nonnegative integers, remove all rows and columns that contain a 0. For example, with this matrix: [[5, 3, 2, 4, 1], [3, 2, 0, 4, 7], [7, 1, 9, 8, 2], [3, 2, 1, 5, 7], [6, 4, 6, 1, 2], [9, 3, 2, 4, 0]] Columns 3 and 5, along with rows 2 and 6 (in bold), contain a 0, so they...
Challenge The primitive circle problem is the problem of determining how many coprime integer lattice points \$x,y\$ there are in a circle centered at the origin and with radius \$r \in \mathbb{Z}^+ \$ such that \$x^2+y^2 \le r^2 \$. It's a generalization of Code-Golf: Lattice Points inside a Circle. Input Radius \$r...