instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
The Manhattan distance on a regular grid is the number of orthogonal steps one needs to take to reach one cell from another. Orthogonal steps are those that go through the edges of the grid cells (as opposed to the corners, which would give us the Chebyshev distance).
We can define a similar distance on other grids, fo... | stackexchange_codegolf |
Part of Advent of Code Golf 2021 event. See the linked meta post for details.
The story continues from AoC2015 Day 5, Part 2.
Santa needs help figuring out which strings in his text file are naughty or nice. He has already tried two sets of rules, but they're totally ad-hoc, cumbersome, and janky, so he comes up with ... | stackexchange_codegolf |
Your challenge is to write N snippets of code such that, when you concatenate the first K ≥ 1 together, they produce the number K. The higher N, the better. Here's the catch: you may not use any character more than once across your snippets.
Rules
You may use the same character multiple times in one (and only one) sni... | stackexchange_codegolf |
Calculate the area of a polygon.
Inspired by this shoelace algorithm video.
Task
Your job is to create a program or function that calculates the area of a polygon. Program or function is defined according the the default definition in meta.
Input
You will receive the X and Y coordinates of each vertex of the polygon. Y... | stackexchange_codegolf |
An aesthetically pleasing divisor tree is a tree of divisors of input n that, for any composite number m, has two children nodes that are the pair of divisors that are closest to the square root of m. The left node should be the smaller divisor of m and the right node should be the larger divisor of m. A prime number i... | stackexchange_codegolf |
Left and right Riemann sums are approximations to definite integrals. Of course, in mathematics we need to be very accurate, so we aim to calculate them with a number of subdivisions that approaches infinity, but that's not needed for the purposes of this challenge. You should instead try to write the shortest program,... | stackexchange_codegolf |
Background
In X11 (a windowing system used by a lot of Unix-like OS), what you would call the clipboard behave a bit differently than on other OSes like MacOS or Windows. While the "traditional" clipboard using ctrl+v/ctrl+c works, there is also another clipboard, called PRIMARY selection, that behave as following:
wh... | stackexchange_codegolf |
Your challenge is to format a list of words across multiple lines that are no longer than a given number of characters, so that each line contains as many words as possible and no words are unnecessarily cut off.
Input
The input will be a space-separated list of words and then a number that is at least 4.
Output
The ou... | stackexchange_codegolf |
This is the second version of the task. The original task had a defect that the given range of integers was too small. This was pointed out by @harold that other methods couldn't defeat the way of hard-coding all the possible prime divisors. Now you have a larger range of integers to test from 0 to 2000000. Also, the r... | stackexchange_codegolf |
Your challenge, should you choose to accept it, is simple:
Implement RFC 862, also known as the Echo Protocol:
The Echo protocol
An echo service simply sends back to the originating source any data it receives.
TCP Based Echo Service
One echo service is defined as a connection based application on TCP. A server listens... | stackexchange_codegolf |
We define \$R_n\$ as the list of remainders of the Euclidean division of \$n\$ by \$2\$, \$3\$, \$5\$ and \$7\$.
Given an integer \$n\ge0\$, you have to figure out if there exists an integer \$0<k<210\$ such that \$R_{n+k}\$ is a permutation of \$R_n\$.
Examples
The criterion is met for \$n=8\$, because:
we have \$R_8... | stackexchange_codegolf |
Given a volume level V in the range 1-10. Your program should draw the following ASCII art.
When V=1:
\
|
/
When V=2:
\
\ |
| |
/ |
/
When V=3:
\
\ |
\ | |
| | |
/ | |
/ |
/
And etc. Trailing spaces are allowed.
This is a code-golf challenge so the shortest solution wins.
| stackexchange_codegolf |
Deserializing binary trees depth-first is pretty easy, but doing it breadth-first is (hopefully) harder. Your mission, should you choose to accept it, is to do the latter.
The input will be a 1-D list of positive integers representing node values and some other consistent value representing the absence of a child (I'll... | stackexchange_codegolf |
makina is a cell-based esolang composed of automata which move around a grid. These automata follow paths of instructions that direct their movement. Your task is to, given a makina program using only the below instructions (so a subset of normal makina) as input, output two distinct values depending on whether or not ... | stackexchange_codegolf |
The challenge
Make 2 programs which convert decimal to and from base 94, or a bidirectional program.
Base 94?
Base 94 is like any other base, but instead of 0 to 9 and letters, it uses ASCII characters 33 to 126. Not 127 because chr(127) is DEL. Not 32 because that's a space.
Examples
0 - ! or empty string
1 - "
93 - ~... | stackexchange_codegolf |
Given an input of a list of words and their abbreviations, output the pattern
by which the abbreviations can be formed.
Let us take the example input of
potato ptao
puzzle pzze
as an example (that is, the abbreviation for potato is ptao, and the
abbreviation for puzzle is pzze).
Consider all possible ways to obtain pt... | stackexchange_codegolf |
Your challenge is to exactly output the following box:
..................................................
..................................................
.. ..
.. ..
.. ++++++++++++++++++++++++++++++++++++++++++ ..
.. ++++++... | stackexchange_codegolf |
Inspired by, and in memory of, our beloved genius,
R.I.P.
He invented and implemented dfns — his magnum opus and the subject of the challenge.
For the interested: latest full dfns documentation and videos with John.
Task
Given an ASCII source code, answer in which of the following four categories it belongs:
Dyadic d... | stackexchange_codegolf |
Probably a simple code-golf challenge. Given 2 positive integers m and n, make a list of n values that are positive integers whose sum is equal to the number m. Either all values in the output are the same value or the difference is exactly 1.
Examples
For example
m=6 and n=3 would become 2, 2, 2
m=7 and n=3 would bec... | stackexchange_codegolf |
Strangely never asked before, this question pertains to the generation of a list of prime numbers within a given range using the shortest possible code. Several algorithms, such as the Sieve of Eratosthenes and trial division, are known to be effective for this purpose, but require significant code length. Is there an ... | stackexchange_codegolf |
A guess the word game
The agreed dictionary. All words are 6 letters long with all letters distinct
Rules: This is a game of two players and the task will be to implement Player 2.
Player 1 chooses a word from the agreed dictionary
Player 2 repeatedly guesses a word from the agreed dictionary.
At each turn, Player 1 ... | stackexchange_codegolf |
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... | stackexchange_codegolf |
Anomalous Cancellation (from Wolfram Alpha):
Anomalous cancellation is a "canceling" of digits of a and b in the numerator and denominator of a fraction a/b which results in a fraction equal to the original. Note that if there are multiple but differering counts of one or more digits in the numerator and denominator t... | stackexchange_codegolf |
Ruby comes with a built-in REPL, which is quite handy.
Your challenge is to crash it in the least amount of code!
The definition of "crash" is "make it exit in an unintended way." This means exit, quit, abort, irb_exit, irb_quit, et. al. are not valid answers.
Furthermore, you may not cause any side-effect to any othe... | stackexchange_codegolf |
With roughly one second (plus or minus 10 ms) between outputs, output anything.
The first output must be at most one second after the start of the program, but can be as soon as right when the program starts.
So, the first output can be up to a second after the program starts, the second exactly one second after that, ... | stackexchange_codegolf |
If I need to get the number of diagonal squares in all directions:
I do the following formula 2 N − 2 − |x − y| − |x + y − N − 1|
The above example has 13 and that's what the formula gives.
Now, what if you wanted to get the diagonal squares, but only in one direction?
The top right has 4 squares, the top left has 3, ... | stackexchange_codegolf |
Given a set of letters, output all strings made of those letters. (This is Kleene star of the set.) For example, for {'a','b'}, the strings are:
'', 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', 'aab', ...
Input: A non-empty collection of distinct letters a..z. These may be characters or single-character strings.
Output: A... | stackexchange_codegolf |
Here's yet another Steenrod algebra question. Summary of the algorithm: I have a procedure that replaces a list of positive integers with a list of lists of positive integers. You need to repeatedly map this procedure over a list of lists and flatten the output until you reach a fixed point. Then for each sublist, if i... | stackexchange_codegolf |
A man from the stars has come to Earth! Luckily the president of the United States, Donald Trump, has an infinity-sided die. Using this die, he can conjure up a number which you, the mayor of Podunk, must use to determine who should be sent to stop the invader! But be careful, you can only send a limited amount of byte... | stackexchange_codegolf |
Fourward (Introduction)
I have an unhealthy obsession with the number 4. I love it so much, in fact, that seeing any other digit is frustrating to me. I therefour wish to create a 'Fourier Transformation': a way to represent any integer value with an expression that uses only the digit 4.
Fourmat (Challenge)
I wish to ... | stackexchange_codegolf |
No, not this. And not this either. This question is nothing like those
Write the shortest code to print/return the following output:
/\ /\ /\
/ \ / \ / \
/ /\ \ / /\ \ / /\ \
/ / \ \/ / \ \/ / \ \
\ \ / /\ \ / /\ \ / /
\ \/ / \ \/ / \ \/ /
\ / /\ \ / /\ \ /
\/ / \ \/ / \ \/... | stackexchange_codegolf |
/o\ Jimmy has been receiving a lot of attention on this site recently and it has caused Jimmy to get a little stressed. The bodybuilder Jimmys /-o-\ started bad mouthing the OG / acrobat /o\ Jimmys saying they are way cooler because they are bigger. But of course the acrobat Jimmys thinks they are way cooler since afte... | stackexchange_codegolf |
In 256 bytes or fewer write a function, \$f\$, from the positive integers to the positive integers that is:
Monotonic: larger inputs always map to larger outputs. (\$a < b \implies f(a) < f(b)\$)
Non-linear: does not have asymptotic order notation \$O(n)\$. (\$\displaystyle\forall c: \exists n:c\cdot n < f(n)\$)
Your... | stackexchange_codegolf |
The challenge involves printing the difference between ICMP originate and receive timestamps.
The idea is being able to determine which asymmetric internet path is responsible for packet delay.
One can use hping with --icmp-ts option to gain the raw data on ICMP_TSTAMP. The task is complicated by the fact that hping d... | stackexchange_codegolf |
Given a ASCII string containing control characters, compute what it should look like when printed to a terminal. Imagining the behaviour of a cursor, this is how to treat each character in the input:
0x08 backspace (\b): go left one (if already at the start of a line, do not go up)
0x09 horizontal tab (\t): go right o... | stackexchange_codegolf |
Background
A maximal domino placement (MDP) on a rectangular grid is a non-overlapping placement of zero or more dominoes, so that no more dominoes can be added without overlapping some existing domino.
Alternatively, it can be thought of as a tiling using dominoes and monominoes (single square pieces) so that no two m... | stackexchange_codegolf |
The event scheduler is a recurrent theme in event-driven architectures: something triggers an event that needs to be checked in the future one or more times. I has particular use in trading where you want to correlate one market event with price movements in the future at several time deltas (1ms, 100ms, 1s, 1 min, etc... | stackexchange_codegolf |
Repost and improvement of this challenge from 2011
A vampire number is a positive integer \$v\$ with an even number of digits that can be split into 2 smaller integers \$x, y\$ consisting of the digits of \$v\$ such that \$v = xy\$. For example:
$$1260 = 21 \times 60$$
so \$1260\$ is a vampire number. Note that the dig... | stackexchange_codegolf |
I have the following Haskell code to generate the the values of the Fibonacci sequence which are even as an infinite list:
z=zipWith(+)
g=z((*2)<$>0:0:g)$z(0:g)$(*2)<$>scanl(+)1g
This works by starting with 0,2 and then defining every following term to be the sum of:
twice all prior terms
the previous term
twice the ... | stackexchange_codegolf |
In this challenge you will receive a list of positive integers \$W\$ called a word, and a square symmetric matrix \$M\$. Your task is to determine if the word can be turned into the empty list by applying a series of valid moves.
The valid moves are:
If two consecutive values in the list are equal you may remove them ... | stackexchange_codegolf |
Background
Shadow transform of a 0-based integer sequence \$a(n)\$ is another 0-based integer sequence \$s(n)\$ defined with the following equation:
$$
s(n) = \sum_{i=0}^{n-1}{(1 \text{ if } n \text{ divides } a(i), 0 \text{ otherwise})}
$$
i.e. \$s(n)\$ is the number of terms in \$a(0), \cdots, a(n-1)\$ that are divis... | stackexchange_codegolf |
In honor of national pi day, create a program that, when given an integer, n, as input, will create a circular "pie" constructed of these smaller pies:
Your program should output the image in a closed polygonal shape, and the number of outputted images should be equal to the value of the nth digit of pi.
Below are som... | stackexchange_codegolf |
Define the "maximum sub-array" of a given array as "a (consecutive) sub-array that has the biggest sum". Note there's no "non-zero" requirement. Output that sum.
Give a description of your code if possible.
Sample input 1:
1 2 3 -4 -5 6 7 -8 9 10 -11 -12 -13 14
Sample output 1: 24
Description 1:
The biggest sum is yie... | stackexchange_codegolf |
The sci-fi shooter Destiny 2 contains guns which have the ability to regenerate ammunition directly into the magazine if, and only if x (precision) shots are landed (in a fixed amount of time), returning y bullets to the magazine. For example, the perk (ability) "Triple Tap" will return 1 bullet to the magazine if 3 pr... | stackexchange_codegolf |
Background
Lambda calculus is a model of computation using lambda terms.
A variable \$x\$ is a lambda term.
If \$E\$ is a lambda term, the lambda abstraction \$\lambda x. E\$ is a lambda term.
If \$E_1, E_2\$ are lambda terms, the lambda application \$E_1 E_2\$ is a lambda term.
The rule of computation is called \$\b... | stackexchange_codegolf |
Let's have a ragged list containing no values, only more lists. For example:
[[[],[[]],[],[]],[],[[],[],[]],[]]
And the list will be finite, meaning that eventually every path terminates in an empty list [].
It's simple enough to determine if two of these are structurally equal. Check each element in order for equali... | stackexchange_codegolf |
Polystrips are a subset of polyominoes conforming to the following rules:
each piece consist of 1 or more cells
no cell can have more than two neighbours
the cells should not enclose a hole
Free polyominoes are distinct when none is a rigid transformation (translation, rotation, reflection or glide reflection) of ano... | stackexchange_codegolf |
Given a ragged list, e.g.
[[4, 7], [5, 3, [], [6, [2]]]]
Your challenge is to sort only the numbers in it. For example, with the above, the result would be
[[2, 3], [4, 5, [], [6, [7]]]]
The shape of the output should remain the same, only the numeric contents should change.
This is code-golf, shortest code wins!
All... | stackexchange_codegolf |
Given an expression, your task is to evaluate it. However, your answer cannot show more digits than necessary, as this gives the impression of having more precise measurements than reality.
The number of significant figures that a number has is how many digits it has when written in scientific notation, including zeros... | stackexchange_codegolf |
For the purposes of the current challenge to "outline" a word means to surround it successively with its own letters, starting with the last one, and finally to replace the original word in the center with spaces:
oooooo
onnnno
on -> on no
onnnno
oooooo
Task:
Given a list of words, con... | stackexchange_codegolf |
Your task will be to write a Haskell function that takes a list of integers and returns a sorted version of the same list. You are to do this without the use of builtins
What are builtins?
To keep ourselves from having to navigate edge case hell we are going to limit answers to Haskell (sorry if Haskell is not your fa... | stackexchange_codegolf |
A polyglot is a program which can be run by several different language's interpreters/compilers without failing.
For example, the stackoverflow 404 page contains a polyglot which runs in Python, Perl, Ruby, C, brainfuck and befunge, each time printing 404 to stdout.
Now, my challenge is to create a polyglot which, whe... | stackexchange_codegolf |
Write a program which, according to whether the script has access to the internet, produces an output which is "Truthy/Falsey". You may try and connect to any existing site, at your own discretion (don't use a shady site which only has 10% uptime - try to keep to above 80% annual uptime). If the site is down, your prog... | stackexchange_codegolf |
What tips do you have for golfing in (,)? I've found that there are so many ways to make code shorter, and I want more ways. I doubt there even are any tips for (,) that are applicable in the majority of programming languages, but if there are, feel free to include them.
Please, one tip per answer.
| stackexchange_codegolf |
3D-modeling software mainly uses UV Mapping to map textures onto a 3D object. The valid values for both U and V are usually located in an inclusive [0..1] range.
Challenge
You bought a new 3D-modeling software which is super-easy to use. However there is one issue with it: it adds or subtracts a random integer number f... | stackexchange_codegolf |
Given a string of text, output it as a 'tower'.
Each slice of the string (of the form 0:n) is repeated 5*n times, so the first character is repeated 5 times, then the first and the second 10 times, etc.
Examples:
'hello' ->
['h']
['h']
['h']
['h']
['h']
['h', 'e']
['h', 'e']
['h', 'e']
['h', 'e']
['... | stackexchange_codegolf |
The Challenge
Given a multiline string, return the longest substring of leading whitespace present in every line, ignoring empty lines or lines composed only of whitespace. If input is empty or whitespace, return nullish or the empty string--up to you.
Update: Per Meta consensus, the input may also be treated as an ar... | stackexchange_codegolf |
Challenge:
Given a list of non-negative integers, determine by how much you should increase each item to create the closest binary box with the resulting integer-list.
What is a binary box?
A binary box is where the first and last rows consists of 1-bits; the first and last columns consist of 1-bits; and everything els... | stackexchange_codegolf |
Caves and Cliffs edition
Part 1, Very related
You're given a piece of ASCII art representing a piece of land, like so:
/‾\ _ __
__/ _/ \‾
_/ __/‾\ |
/ / ‾\ |
\_/‾ \_/
But unlike in the previous challenge, the terrain is mountainous, with caves and cliffs, and can turn b... | stackexchange_codegolf |
You've recently made an account on a dodgy gambling site, where for a fee of 25 dollars, they will pay you back a random amount between 0 and 50 dollars. After getting around 5 dollars twice, you decide to prove the site is a scam. After accessing their external firewall with the default password, you find your way ont... | stackexchange_codegolf |
Consider the problem of N queen on an (NxN) chessboard. Two queens are said to attack each other if they are on the same row, column,
or diagonal. Implements backtracking algorithm to solve the problem i.e. place N non-attacking queens on the board.
| stackexchange_codegolf |
Inspired by this Stack Overflow question: Sorting a list: numbers in ascending, letters in descending. Your task is to solve the following problem and, as this is code-golf, you should do so in as few as bytes as possible.
You should take a list of objects as input containing letters (any reasonable form: string, char,... | stackexchange_codegolf |
Note: I have accepted an answer, but I'm willing to accept a better answer if it comes.
Write a program that computes operations on sets. You may take input either from standard input or from command line arguments. Your program must be able to compute unions, intersections, relative complements, and cartesian products... | stackexchange_codegolf |
Your task
Given a string of lowercase letters, output the "alphabet checksum" of that string, as a letter.
Example
Let's say we have the string "helloworld". With a = 0, b = 1, c = 2 ... z = 25, we can replace all of the letters with numbers:
h e l l o w o r l d
7 4 11 11 14 22 14 17 11 3
Now, we can sum th... | stackexchange_codegolf |
A number is in base-b simplified Goodstein form if it is written as
b + b + ... + b + c, 0 < c ≤ b
The simplified Goodstein sequence of a number starts with writing the number in base-1 simplified Goodstein form, then replacing all 1's with 2's and subtracting 1. Rewrite the result in base-2 simplified Goodstein for... | stackexchange_codegolf |
Context
If a0 and b0 are two decimal numbers, with a and b representing the decimal expansion of all digits but the least significant one, then we know that
$$\frac{a0}{b0} = \frac{a{\not\mathrel0}}{b{\not\mathrel0}}= \frac{a}{b}$$
Phony fraction
A phony fraction is a fraction where the numerator and denominator share ... | stackexchange_codegolf |
Background
Entombed is an Atari 2600 game released in 1982, with the goal of navigating through a continuous mirrored maze as it scrolls upwards. In recent times, the game has been subject to research — despite the strict hardware limitations of the Atari 2600, it somehow manages to create solvable mazes every time. By... | stackexchange_codegolf |
As you may know, the typical binary floating point numbers in a computer language are quite different than the typical integer numbers in a computer language. Floating point numbers can represent a much larger range, and can represent fractional amounts, however there is a trade-off that is frequently elided.
The dista... | stackexchange_codegolf |
Cyclically self-describing lists
A list \$L\$ of positive integers is cyclically self-describing, if the following conditions hold.
\$L\$ is nonempty.
The first and last elements of \$L\$ are different.
If you split \$L\$ into runs of equal elements, the element of each run equals the length of the next run, and the e... | stackexchange_codegolf |
Given a string that is one of the directions on a 16-point compass rose
output the two directions that are immediately adjacent to the input direction, in clockwise order.
Specifically, you need to handle these (and only these) input/output pairs:
Input Output
N NNW NNE
NNE N NE
NE NNE ENE
ENE NE E
E ... | stackexchange_codegolf |
Your task is to create a program which, given an input string, will output the first Google autocomplete result for that search. The format of input/output is up to you.
Rules
Your program must take 1 input, a string, and output the top Google autocomplete/auto-fill suggestions result. The format of input/output is up... | stackexchange_codegolf |
Per the fundamental theorem of arithmetic, for a given number \$n\$, it is possible to find it's prime factors, and they are unique. Let's imagine we talk only of \$n\$ that is non-prime (composite).
We can also find the factors of all the composite numbers smaller than \$n\$. For example if \$n\$ is 10, then it has f... | stackexchange_codegolf |
Task
Any one of these two:
Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position.
List all the valid positions in any order.
Make sure to describe your input (if not listing all) and output formats.
The 2368 vali... | stackexchange_codegolf |
Challenge
In this challenge, you have to fill an \$M\$ x \$N\$ rectangle grid with the most \$A\$ x \$B\$ rectangle pieces possible.
Requirements:
The sizes of the \$M\$ x \$N\$ rectangle grid is always bigger than the sizes of the \$A\$ x \$B\$ rectangle pieces. In other words, \$min(M, N) ≥ max(A, B)\$
You can freel... | stackexchange_codegolf |
Input
A calendar year from 927 to 2022.
Output
You can use any three distinguishable outputs. As an example,
“K” (short for King)
or
“Q” (short for Queen)
depending on which of the two England had in that year. If there was both a King and Queen in that year you can output either.
If there was no King or Queen for th... | stackexchange_codegolf |
A listening party is an event where a bunch of people get together to listen to some music (like a viewing party, but for music). In the age of the internet you can do Listening Parties online with friends, where you just all hit play together.
The problem is on the internet everyone is in different time-zones so you ... | stackexchange_codegolf |
Given a ray with a point and a vector and a plane with a point and a normal vector to the plane. You have to find the intersection point of the plane and the ray..
So your job if you choose to accept is to write a shortest function that will do the job.
RULES:
The submission must be a complete program
And that's all
I... | stackexchange_codegolf |
The Challenge
Write a program that can calculate how many times and how long a ball will bounce based on a few input variables.
Input
There are three variables that will be passed. You can accept these however you like (user input, function call, etc). The variables are as follows:
height
velocity
"bounciness"
They ... | stackexchange_codegolf |
An Automorphic number is a number which is a suffix of its square in base 10. This is sequence A003226 in the OEIS.
Your Task:
Write a program or function to determine whether an input is an Automorphic number.
Input:
An integer between 0 and 10^12 (inclusive), that may or may not be an Automorphic number.
Outpu... | stackexchange_codegolf |
Write a program that inputs the dimensions of a painting, the matting width, and the frame width for a framed portrait. The program should output a diagram using the symbol X for the painting, + for the matting, and # for the framing. The symbols must be space-separated. Trailing whitespace is alright, as long as the o... | stackexchange_codegolf |
Introduction and credit
Assume you're a bartender. You have many happy people in your bar at most times, but many only ever drink the very same drink and too few for your taste and you want to change that. So you introduce a system where the price of a drink is variable, depending on how many have already been sold, bu... | stackexchange_codegolf |
There are 21 items in Minecraft that you can craft using only wood and items crafted from wood:
axe
boat
bowl
button
chest
crafting table
door
fence
gate
hoe
ladder
pickaxe
planks
pressure plate
shovel
sign
slab
stairs
stick
sword
trapdoor
This list assumes that the 6 different types of wooden planks/slabs/doors/etc... | stackexchange_codegolf |
Given a number n, find x such that x! = n, where both x and n are positive integers. Assume the input n will always be the factorial of a positive integer, so something like n=23 will not be given as input.
Examples: n=1 -> x=1 (0 is not a positive integer), n=24 -> x=4
Shortest code wins.
| stackexchange_codegolf |
Dealing with colors in non-markup languages often complicates things.
I would like to see some variations of how color is used in different languages.
The object of this competition is to output 'Hello World' in the seven colors of the rainbow.
According to Wikipedia, these are the 7 colors.
Red #FF0000 (RGB: 255,... | stackexchange_codegolf |
Introduction (may be ignored)
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers. This is the second challenge in this series. The first challenge can be found here.
In this challenge,... | stackexchange_codegolf |
Overview
Given a 3 line string, figure out if the structure falls to the left, balances, or falls to the right.
Input structure
You can imagine the structure as metal rod with stuff on top, all being balanced on top of a vertical rod.
1 7 4 a
===============
|
The first line is the items. Each item's w... | stackexchange_codegolf |
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... | stackexchange_codegolf |
A simple FizzBuzz using strings.
Given
1 word or phrase (string)
2 unique characters
Output
The word or phrase with each occurrence of the first character replaced with fizz and each of the second character replaced with buzz
Rules
The first letter in both Fizz and Buzz must remain capitalized
For the rest of the wo... | stackexchange_codegolf |
This is a cops-and-robbers puzzle, the cops' thread can be found here.
Your task will be to find an anagram of the provided programs in the cops' thread that performs its left inverse.
Once you crack an answer post the solution as an answer below and notify the original answerer.
You will be scored on the number of pro... | stackexchange_codegolf |
The Challenge
Given two strings/an array of strings, output the first string slowly shrinking and expanding back into the second string.
You can assume the strings will always start with the same character.
Example
Input:
"Test", "Testing"
Output:
Test
Tes
Te
T
Te
Tes
Test
Testi
Testin
Testing
First you output the fi... | stackexchange_codegolf |
This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here.
Assume I have some number of black shirts and some number of white shirts, both at least 1. Both colors of shirt have a non-zero durability. All shirts of a given color start with the same durability.
Every day, I ... | stackexchange_codegolf |
Bi-directional translator
The challenge is to create a translator that can translate a [a-zA-Z ] string into another string according to the mappings below. The translator should also be able to translate translated text back into its normal form (hence bi-directional). Case doesn't have to be maintained and can be eit... | stackexchange_codegolf |
Your program must take as input a line of characters, like this:
@+.0
And output the characters sorted by how dark they are, like this:
.+0@
Requirements:
You must use a monospaced font for darkness detection.
You must find out how many pixels each character takes up. You must actually draw the character and count p... | stackexchange_codegolf |
For the purpose of this challenge, we say that a regex pattern matches a string if the entire string is matched by the pattern, not just a substring.
Given two regex patterns A and B, we say that A is more specialized than B if every string that is matched by A is also matched by B but not the other way around.
We sa... | stackexchange_codegolf |
Modern regular expressions (regexes) have many features (\d, {n,m}, \1, etc.), but to define a regular language (modern regexes can define broader classes of languages, in their defense), all you need are three operators: concatenation (+), union (|), and the Kleene star (*). Here are some examples:
a - Matches the str... | stackexchange_codegolf |
Not exactly sure if it belongs in this site, but I always have trouble thinking of all the certain edge cases in any kind of competitive programming or puzzles.
For example, take this kind of problem
Find the size of the smallest list of squares that add up to n
f(16)-> 1 (16)
f(17)-> 2 (16+1)
One intuitive approach ... | stackexchange_codegolf |
The Caesar cipher is a simple and famous cipher, where the letters of the alphabet are rotated by some secret amount. For example, if our secret rotation is 3, we would replace a with d, b with e, w with z, x with a and so on.
Here is an example (rotation amount: 10):
Robo sc kx ohkwzvo
This cipher is very weak, becau... | stackexchange_codegolf |
An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write \$abcbac\$ and then I would draw the lines as:
Or I might write \$abbcac\$
Once I've drawn these lines I try to draw cl... | stackexchange_codegolf |
Given a nonempty list of nonempty rows of numbers, compute the column wise sum, which is another list that has the length of the longest input row. The first entry of the output list is the sum of all the first entires of the input rows, the second one is the sum of all the second elements (if available) etc. I think f... | stackexchange_codegolf |
In your grandparents' day, dialing a phone number was done with a rotary dial like this:
To dial each digit, put your finger in the corresponding hole, pull it over to the finger stop, and release it. A mechanism will cause the dial to spin back to its resting position, and the phone will disconnect and reconnect a c... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.