instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Prime Wednesdays
Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.
Input
The input to your program/function will be a year (eg 2016) and is flexible. The year wi... | stackexchange_codegolf |
Your task, should you choose to accept it, is to take two input values \$a\$ and \$b\$,
where \$a\$ and \$b\$ are in the set \$\{T, U, F\}\$, and compute and output their logical conjunction in a three-valued logic system.
A three valued logical conjunction is this transformation:
a
b
output
U
U
U
U
F
F
F
... | stackexchange_codegolf |
Adam West passed away, and I'd like to honor his memory here on PPCG, though I doubt he knew of our existence. While there are many, many different things that this man is known for, none are more prominent than his role as the original batman. I'll always remember my step-father still watching the old-school Batman an... | stackexchange_codegolf |
The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
Let P be a binary string of length n and T be a binary string of length 2n-1. We can compute the n Hamming distances between P and every n-length substring of T in order from left to ri... | stackexchange_codegolf |
It has been proven that the following 13 square Wang tiles always tile the plane aperiodically. This means that when the squares are arranged in a grid with all neighboring sides the same color, a translation of the pattern will never match up with itself.
We'll represent each tile textually by a 3×3 grid filled with ... | stackexchange_codegolf |
Cops post
A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string:
Split the string into equal sections.
Reverse the string, and starting from the start of each string.
Put ru... | stackexchange_codegolf |
One way to generalize the concept of a range from the integers to the Gaussian integers (complex numbers with integer real and imaginary part) is taking all numbers contained in the rectangle enclosed by the two ends of the range. So the range between two Gaussian integers a+bi and c+di would be all Gaussian integers x... | stackexchange_codegolf |
Each natural number (including 0) can be written as a sum of distinct powers of integers (with a minimum exponent of 2). Your task is to output the smallest power required to represent \$n\$.
For example:
2 = 1^2 + 1^3 // Output 3
9 = 1^2 + 2^3 = 3^2 // Output 2
15 = 2^2 + 2^3 + 1^4 + 1^5 + 1^6 // Output 6
20 = 2^2 + ... | stackexchange_codegolf |
Using the matchstick numbers here: Count the Matchsticks
_ _ _ _ _ _ _ _
| | | _| _| |_| |_ |_ | |_| |_|
|_| | |_ _| | _| |_| | |_| _|
How many matchsticks must be moved and/or removed to change one number into another?
You will take two single digit number... | stackexchange_codegolf |
Your task is simple: output the letter x a random number of times. Every possible length of xs must have a non-zero probability of being output.
Of course, there must be some lengths whose probabilities tend to \$ 0 \$, in order for the total probabilities to sum to \$ 1 \$, but all must still be theoretically possible... | 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 |
Pre-Note
Because of popular demand, and to avoid disqualifying certain languages, the dictionary can now be provided as input parameter.
Intro
Given a dictionary of words, you should write an autocomplete program or function.
Autocompletion
"Autocomplete, or word completion, is a feature in which an application predict... | stackexchange_codegolf |
Introduction:
Inspired by a discussion that is already going on for many years
regarding the expression \$6÷2(1+2)\$.
With the expression \$6÷2(1+2)\$, mathematicians will quickly see that the correct answer is \$1\$, whereas people with a simple math background from school will quickly see that the correct answer ... | stackexchange_codegolf |
You know those letterboards outside old-style cinemas which show upcoming films - perhaps you have a miniature one in your home?
If you've operated one, you'll know that you can normally add letters from either side of a row. But the slots (in which you slide letters) are thin, so it's impossible to swap the order of ... | stackexchange_codegolf |
May this challenge serve as (another) tribute to Stan Lee, who passed away aged 95.
Stan Lee has left us an invaluable legacy and a peculiar catch word: Excelsior. So here's a small challenge based on what he said it was its meaning:
Finally, what does “Excelsior” mean? “Upward and onward to greater glory!” That’s wh... | stackexchange_codegolf |
The task is simple. You're given an arbitrary string message. Return that message prefixed with a number, such that the length of that number plus the message equals the number. In other words, the length in your output must be the total length of your output.
If multiple candidates exist, you can output any of them.
F... | stackexchange_codegolf |
Input
An integer \$n\$ greater than or equal to 1.
Output
The number of bits in the binary representation of the integer that is the product of the first \$n\$ primes.
Example
The product of the first two primes is 6. This needs 3 bits to represent it.
Given unlimited memory and time your code should always output the ... | stackexchange_codegolf |
The sum of the squares of the first ten natural numbers is,
\$1^2 + 2^2 + \dots + 10^2 = 385\$
The square of the sum of the first ten natural numbers is,
\$(1 + 2 + ... + 10)^2 = 55^2 = 3025\$
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is
\$3025 − 385... | stackexchange_codegolf |
inspired by thejonymyster's idea
Rules
This challenge is about finding languages that are very suitable for one task but quite the opposite in the other. The two tasks share a theme, but Task 1 is designed to be number-oriented while 2 is string-oriented. You can participate in three categories:
Numbers: Choose a lang... | stackexchange_codegolf |
I wrote a code that separates the numbers from 1 to 9999 by comma
void p(n){printf("%d,",n);if(n<9999){p(n+1);}}main(){p(1);}
Is there a way to make this short code without using a repeat statement?
| stackexchange_codegolf |
You are given a string \$s\$ of characters from a to z. Your task is to count how many unique strings of length \$n\$ you can make by concatenating multiple prefixes of the string \$s\$ together.
Since the result can be superlative you can either choose to output the whole result, the result mod \$2^{32}\$ or the resul... | stackexchange_codegolf |
The goal of this challenge is to print the following tongue twister:
She sells seashells by the seashore,
The shells she sells are seashells, I'm sure.
So if she sells seashells on the seashore,
Then I'm sure she sells seashore shells.
This is more complicated than just calling your language's print equivalent. Since ... | stackexchange_codegolf |
End the tabs versus space war
So, there has been a great deal of debate of whether to use tabs or spaces to indent/format code. Can you help the university settle the dispute, by going to an incredibly crazy unique method of formatting.
Your job is to write a full program or function which expands all tabs into four s... | stackexchange_codegolf |
For golfing practice, I have been doing the assignments in my girlfriend's Intro to Python class. I found that for this assignment, there were multiple strategies that came very close in character count, and I'm sure people here can find even better ways. Although I am most interested in ways to do this in Python, I wo... | stackexchange_codegolf |
Let's do an exercise together, shall we? Simply follow the movements of the stickman. What stickman you ask? The one we are about to create!
Make a program that allows for a string-input only containing integers, and outputs the following nine stick-figures with an interval in between:
@ \@/ |@_ _@| @/ \@ |@| \@\ /... | stackexchange_codegolf |
Challenge:
Find the number of ways to climb some stairs with n steps and with some limitations. You should be able to run the tests below on TIO https://tio.run/ without timing out. – 60 seconds. (Typically a fraction of a second is well within reach for most languages if a good optimizing strategy is applied).
The in... | stackexchange_codegolf |
Task
Your task is to write whole program, which will align given input to a block of given size.
Input:
40
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea ... | stackexchange_codegolf |
Introduction
In a general election, one would like to calculate a constant price per parliament seat. This means that for N >= 0 seats to be distributed and a list ns of votes per party, we would like to find a number d such that
sum(floor(n/d) for n in ns) == N
To make things interesting (and more like the real worl... | stackexchange_codegolf |
Given a random code written using Brainfuck commands. You program should translate that code into the following ascii art: each Brainfuck command represents as 5x9 array of A and B symbols. All commands are concatenated with 5x3 arrays of A symbols. Symbols A and B you choose yourself.
For example, when input is ><+,.[... | stackexchange_codegolf |
My school has its Homecoming dance next week, and there's someone in mind I want to ask. But I don't want to ask her the normal way. I want to send her a program that prints "Rachel, will you go to Homecoming with me?" However, if I just send her print"Rachel, will you go to Homecoming with me?", it'll be way too obvio... | stackexchange_codegolf |
Your task is to write 2 functions/programs. They may share code.
The first function must, given a string and a character, output a new string that does not contain that character.
The second function must, given the string from the previous function and the excluded character, reconstruct the original string.
All input... | stackexchange_codegolf |
The challenge is to find the maximum number you can get from a list of integer using basic arithmetic operators (addition, substraction, multiplication, unary negation)
Input
A list of integers
Output
The maximum result using every integer in the intput.
The input order doesn't matter, result should be the same.
You do... | stackexchange_codegolf |
If you cannot see this post, you can use this image
Your task is to create a markdown parser that outputs Unicode. It should support , , , and ̲̲̲̲̲̲̲̲̲.
Every alphabetical character should be converted into Math Sans. This includes the characters before an underline character.
Underlines: Add a ̲ character (code point... | stackexchange_codegolf |
Well, last time I asked for an arithmetic sequence, now comes the geometric sequence
Challenge
In this challenge, the input will be an unordered set of numbers and the program should be able to tell if the set of numbers is a Geometric Sequence.
Input
The input will be a set separated by ,(comma).
Output
The Output ... | stackexchange_codegolf |
The task is to find the smallest paper size on which it is possible to print a picture of the dimensions given in milimetres. The image will be printed without margins.
Input:
Two integers (bigger than zero) and a letter a, b, or c, for example:
290
200
A
Output:
Paper size, for example:
A4
Another examples:
218,297... | stackexchange_codegolf |
Background
Conway's Soldiers is a version of peg solitaire played on an infinite checkerboard. The board is initially full of pegs below an infinite horizontal line, and empty above it. Following the ordinary peg solitaire rules (move a peg by jumping over another one horizontally or vertically, removing the one that w... | stackexchange_codegolf |
When it comes to eating candy, I hold myself to higher standards than the typical layperson. There is a delicate balance between "mixing it up" and "saving the best for last."
In this challenge, you will be given a string of characters in which each character represents a piece of candy. Different characters (case-se... | stackexchange_codegolf |
Did you know that Heronian Tetrahedra Are Lattice Tetrahedra? A Heronian tetrahedron is a tetrahedron where
the length of each edge is an integer,
the area of each face is an integer, and
the volume of the tetrahedron is an integer.
It's always possible to place such a tetrahedron in space such that all of the vertic... | stackexchange_codegolf |
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... | stackexchange_codegolf |
Here is the (quite scary) Five little ducks song(it is not long):
Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.
Four little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack... | stackexchange_codegolf |
We often see music videos on Youtube. Many Youtube channels that host music videos are "powered by VEVO". Those can be easily identified by both embedding VEVO at their video thumbnails and appending VEVO to their channel name.
Now write some code to test whether a string given by user is a VEVO user account or not.
Re... | stackexchange_codegolf |
Given an input of two integers n and m, output an ASCII ladder of length
n and size m.
This is an ASCII ladder of length 3 and size 3:
o---o
| |
| |
| |
+---+
| |
| |
| |
+---+
| |
| |
| |
o---o
This is an ASCII ladder of length 5 and size 1:
o-o
| |
+-+
| |
+-+
| |
+-+
| |
+-+
| |
o-o
This is an AS... | stackexchange_codegolf |
A near-repdigit number is a positive integer where all the digits are the same, except one. For example 101 and 227 are near-repdigits. A near-repdigit prime is a near-repdigit that is also prime. For example:
101, 113, 131, 151, 181, 191, 199, 211, 223, 227, 229, 233, 277, 311, 313, 331, 337, 353, 373, 383, 433, 443, ... | stackexchange_codegolf |
Given an input value \$n\$, construct an array of \$n\$ random 128 bit (unsigned) integers. The integers should be uniformly random.
Your code can use any in built random number generation function it has or you can implement your own. Clearly this challenge is harder (and more fun) in lower level languages.
| stackexchange_codegolf |
This code golf challenge is to show directions through numbers.
When the user enters a number, then that means a direction change as follows:
0 means stay still
1 means forward (initially from left to right and initially start with `:`)
2 means turn right
3 means turn left
4 means go backward
I will show you an exampl... | stackexchange_codegolf |
This is based off this challenge.
Given an input string, check whether the string is blurry.
What's a blurry string?
A blurry string is a string that's contained in the set of all blurrified pure-ASCII strings.
Take a non-blurrified pure-ASCII string abc as an example. You repeat every character of this twice:
aabbcc
... | stackexchange_codegolf |
The task is simple, given two IP adresses a and b, output all addresses within that range.
Examples
Example #1:
f(a = 192.168.0.1, b = 192.168.0.4)
192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
Example #2 (TIO will truncate this, use a smaller range when testing):
f (a = 123.0.200.0, b = 124.0.0.0)... | stackexchange_codegolf |
Given a \$2\times N\$ maze, determine if you can get from the start top left corner to end bottom right corner using only up, down, left, and right moves.
Input
A \$2\times N\$ block (\$1 \le N \le 100\$) of your choice of two distinct characters, one representing walls and the other representing empty tiles that can b... | stackexchange_codegolf |
Challenge
Write a program or a function that returns or prints a square-random-symmetrical matrix.
Input
N: The size of the matrix i.e 6 x 6
Output
The matrix. You can either print it, return it as string (with the newlines) or as a list/array of lists/arrays.
Rules
You need to use at least N different characters, ... | stackexchange_codegolf |
Once upon a time I wanted to order custom tokens for a board game. They say they can do it, and then they present me their price list. I was confused because they charge per inch of head movement, and I have no idea how much will my tokens cost.
INPUT: a 2d grid:
|,-,\,/ are straight cuts. Each has a length of 1.
┌,┐,... | stackexchange_codegolf |
Inspired by certain puzzles on Flow Free: Warps.
Background
We all know that L-triominos can't tile the 3x3 board, and P-pentominos can't tile the 5x5 board. But the situation changes if we allow the board to wrap around in both dimensions:
L-triominos can tile 3x3 toroidal grid
The 3rd tile wraps around through all fo... | stackexchange_codegolf |
The Home Prime of an integer \$n\$ is the value obtained by repeatedly factoring and concatenating \$n\$'s prime factors (in ascending order, including repeats) until reaching a fixed point (a prime). For example, the Home Prime (\$\text{HP}(n)\$) of \$10\$ is \$773\$ as:
$$\begin{align}
10 & = 2 \times 5 \to 25 \\
25 ... | stackexchange_codegolf |
I have previously posted a challenge, smallest number of steps for a knight in chess.
Now I would like to go a step further by adding the possibility to choose your piece.
If you place a piece on any square of a chessboard, what is the smallest number of steps to reach every possible position?
Rules
It is an 8 by 8 bo... | stackexchange_codegolf |
Someone's given us a string, but all bracket-like characters have been changed into normal ones, and we don't know which, or even how many there were. All we know is that if L1,L2,L3,...,LN were different kinds of left brackets and R1,R2,R3,...,RN were different corresponding kinds of right brackets, all being distinct... | stackexchange_codegolf |
This challenge is related to some of the MATL language's features, as part of the May 2018 Language of the Month event. Associated challenge: Function clipboard: copy.
Introduction
MATL's function clipboard stores ("copies") the inputs to the four most recent calls to normal, input-taking functions. Normal functions a... | stackexchange_codegolf |
The task
In this challenge, your task is to write a program in a programming language L that takes a positive integer n, and outputs the sum of the proper divisors of n (sequence A001065 on OEIS).
It should return the correct output for any 1 ≤ n ≤ 10 000.
Here are the first 10 outputs:
0, 1, 1, 3, 1, 6, 1, 7, 4, 8
Fu... | stackexchange_codegolf |
A straight-chain alk*ne is defined as a sequence of carbon atoms connected by single (alkane), double (alkene), or triple bonds (alkyne), (implicit hydrogens are used.) Carbon atoms can only form 4 bonds, so no carbon atom may be forced to have more than four bonds. A straight-chain alk*ne can be represented as a list ... | stackexchange_codegolf |
Background
Combinatory logic is a system where a term is written using a finite set of combinators and function application between terms, and reduction rules are defined for each combinator. The well-known S and K combinators have the following reduction rules:
$$
\begin{aligned}
S\;x\;y\;z & \overset{S}{\implies} x\;... | stackexchange_codegolf |
The Simpson index is a measure of diversity of a collection of items with duplicates. It is simply the probability of drawing two different items when picking without replacement uniformly at random.
With n items in groups of n_1, ..., n_k identical items, the probability of two different items is
For example, if you ... | stackexchange_codegolf |
Given the 2-dimensional positions and velocities of a pair of billiard balls right before impact, calculate their velocities after a perfectly elastic collision. The balls are assumed to be ideal spheres (or equivalently: circles) with the same radius, same mass, uniform density, and no friction.
Input consists of 8 nu... | stackexchange_codegolf |
If you're sad, that's wrong. We need to scrub out ALL sadness.
This is a sad face, for reference:
......
.S..S.
........
...SS...
..SS..SS..
.S......S.
........
Where S is a consistent pixel, . is any pixel other than S, and is any pixel. Note that the sad face is not a perfect square, only the . shoul... | stackexchange_codegolf |
Every digital clock contains a small creature that has to advance the time every minute [citation needed]. Due to the popularty of digital clocks and the popularity of catching them in the wild, they are nearly extinct in nature which is why in this challenge we try to automate this task:
Given your string of a given t... | stackexchange_codegolf |
In this challenge you will be asked to take a knot and determine if it can be colored in a particular way.
First we draw a diagram of the knot. We use the standard way of drawing knots where we put gaps in strands where they pass under each other. Here is an example of some knots drawn this way:
Taken with permissio... | stackexchange_codegolf |
You've seen the amazing alphabet triangle, the revenge of the alphabet triangle and now it's time for the revenge of the revenge of the alphabet triangle!
Introducing...
THE ALPHABET DIAMOND!
Your task is to output this exact text, lowercase/uppercase does not matter, though newlines do:
bcdefghijklmnopqrstuvwxyzazyxw... | stackexchange_codegolf |
You are to create a program which, when given a positive integer \$n\$, outputs a second program. This second program, when run, must take a second positive integer \$x\$ and output one of two distinct values depending on whether \$x\$ is divisible by \$n\$. Those values must be consistent for a given \$n\$ but can be ... | stackexchange_codegolf |
The code has a lot of names, but is very simple:
1 2 3 4 5
1 A B C D E
2 F G H I J
3 L M N O P
4 Q R S T U
5 V W X Y Z
A letter is coded by its coordinates, with the row first, then the column. Ex:
M = 3, 2
V
1 2 3 4 5
1 A B C D E
2 F G H I J
>3 L M N O P
4 Q R S T U
5 V W X Y Z
Note the letter 'K' i... | stackexchange_codegolf |
Robbers thread
In this cops-and-robbers challenge, your task is to write a program h that outputs "Hello Shue!". Next, you have to choose a string i and also write a Shue program p, so that p(i)=h. Your score is len(p)+len(i). Your answer will contain the language of h, i and your score (please write the score as len(p... | stackexchange_codegolf |
The bank has been broken into, and all the local mafia thugs have an unusual alibi: they were at home playing Connect 4! In order to assist with the investigation, you are asked to write a program to validate all the Connect 4 boards that have been seized in order to check that the positions are indeed positions from ... | stackexchange_codegolf |
Given a positive input \$n\$, output a random pair of primes whose difference is \$n\$. It's fine if there's another prime between them.
Every pair should possibly appear and the program should have zero possibility to fall into infinite loop.
It's promised that such pair exist, but not always infinite, so beware. You ... | stackexchange_codegolf |
For an integer n that satisfies n > 0, write its value as a right-descending path based on its binary representation.
Rules
The first (most significant) set bit is always in the top-left corner.
When the next bit is set (a 1), draw a character ("filled") on the next line in the same column as the previous character dr... | stackexchange_codegolf |
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... | stackexchange_codegolf |
Problem
Given a value n, imagine a mountain landscape inscribed in a reference (0, 0) to (2n, 0).
There musn't be white spaces between slopes and also the mountain musn't descend below the x axis.
The problem to be solved is: given n (which defines the size of the landscape) and the number k of peaks
(k always less tha... | stackexchange_codegolf |
Golf a Venn Diagram generator
In order to properly celebrate John Venn's 180th birthday, today your task will be creating a program that outputs a Venn Diagram!
Input:
A positive integer N that will define the range of numbers appearing in the diagram (From zero to N) and three sets of positive integers.
Output:
A 3 s... | stackexchange_codegolf |
This challenge was inspired by Yeah But No But Yeah.
maxb´s colleague recently sent him the following piece of JavaScript as a joke:
let butScript = (nrOfButs) => {
for(var i = 0; i < nrOfButs; i++){
if(i % 3 == 0){
console.log("Yeah")
}
if(i % 2 == 0){
console.log("... | stackexchange_codegolf |
SE will be down/read only today 2017-05-04 at 00:00 UTC until 00:20 UTC.
Your challenge is to output a truthy value if SE is down/read only and a falsy value if SE is not. You may not have any input, and you must use date builtins to determine if SE is down/read only (no actually querying the SE api!) Example output:
1... | stackexchange_codegolf |
Sometimes, I will think it is one day of the week (e.g Friday) when in reality, it's earlier in the week (e.g Tuesday).
Your challenge is to display the number of days my estimates are off by.
Challenge
Given a day of the week I think it is, and the day of the week it actually is, output/return the number of days betwe... | stackexchange_codegolf |
Implement a function or program that can run simplified BitCycle code. The functions you must implement are:
<^>v: Change the direction of a bit to the direction this is pointing.
+: Turn all 0s left and all 1s right.
\ and /: Reflect one bit 90 degrees, then become inactive. In regular BitCycle, this is displayed as -... | stackexchange_codegolf |
Consider, for a given positive integer \$k\$, the sequence \$(a, a+1, a+2, ..., a+k)\$, where \$a\$ is some positive integer. Is there ever a pair \$a, k\$ such that for each element \$a+i\$ in the sequence, either \$\gcd(a, a+i)\$ or \$\gcd(a+i, a+k)\$ are greater than 1?
This was investigated by Alan R. Woods as part... | stackexchange_codegolf |
Background
A bijective base b numeration, where b is a positive integer, is a bijective positional notation that makes use of b symbols with associated values of 1 to b.
Unlike its non-bijective counterpart, no symbol has a value of 0. This way, each non-negative integer n has a unique representation in bijective base ... | stackexchange_codegolf |
Related: Program my microwave oven. Inspired by Generate lazy microwave input.
The lazy value of the non-negative integer N is the smallest of the integers that are closest to N while all their digits are identical.
Return (by any means) the lazy value of a given (by any means) N.
N ≤ the largest integer that your lang... | stackexchange_codegolf |
The cool stuff
The following rosace can help calculate numbers modulo 7.
In order to do that, you must start at 0 and turn clockwise a number of steps given by the first digit. Then, for each successive digit, follow the arrow and then turn clockwise the number of steps given by that digit.
Here is how you proceed for... | stackexchange_codegolf |
Challenge
Your goal is to find the furthest point on a graph (from a provided start node). Your code doesn't need to handle cycles in the graph properly, but it might pose a fun challenge. For this question, you can assume the graph is actually a tree.
Input data
Input can be provided in any suitable format for the lan... | stackexchange_codegolf |
NOTE: This question was migrated from https://stackoverflow.com/q/27134588/1442685
PHP QUESTION
Almost purely out of curiousity, how can I take an array like this:
array( 'fruit' => 'banana', 'drink' => 'milk')
And convert it to an array like this:
array( 'fruit=banana', 'drink=milk')
Requirements
Cannot use anonymo... | stackexchange_codegolf |
Find the max number of Xs you can fit onto a rectangular tic-tac-toe board of length l and height h without ever having 3 consecutive Xs in a row diagonally, horizontally, or vertically.
This is a code-golf challenge so shortest code wins!
Input
A single line containing values l and h, representing the length and heigh... | stackexchange_codegolf |
Introduction
A function that adds months to a date (without overflowing ends of months) is implemented in many languages/packages. In Teradata SQL it's ADD_MONTHS, here are some examples:
ADD_MONTHS('2021-01-31', 1) => 2021-02-28
ADD_MONTHS('2021-01-30', 1) => 2021-02-28
ADD_MONTHS('2021-02-28', 1) => 2021-03-28
... | stackexchange_codegolf |
Write a cat program, a quine, and a Hello World in the same language such that when two specific programs of the three are concatenated in a certain order, you get the third program. It does not matter which program is the first, second, and third are as long as all three types are represented once each.
e.g. if \$A\$ ... | stackexchange_codegolf |
EDIT
It appears that there has been some confusion following my typo in the original post which used a lowercase o to define the plane and then an uppercase later. Unfortunately this bug did not get picked up in the Sandbox. Since many members have written answers with both and since the typo was my fault I will allow ... | stackexchange_codegolf |
For each node in a balanced binary tree, the maximum difference in the heights of the left child subtree and the right child subtree are at most 1.
The height of a binary tree is the distance from the root node to the node child that is farthest from the root.
Below is an example:
2 <-- root: Height 1
... | stackexchange_codegolf |
First challenge!
What is an ambigram?
Ambigrams are word(s) that read the same word(s) or another word given a certain transformation and possibly stylistic alterations.
Example:
That's an example of a rotational ambigram; it reads the same word, even when flipped around.
The Challenge
You are to create a function, pr... | stackexchange_codegolf |
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 ... | stackexchange_codegolf |
How can I shorten:
p=gets.to_i
a=gets
b=gets.to_i
If my input is an integer, followed by a string, followed by an integer?
| stackexchange_codegolf |
There are popular check digit algorithms such as Luhn and then there are good ones, for example the Damm algorithm. The only possible reason behind the popularity of algorithms such as Luhn is that there exist code golfed implementations of them. This means that we as a community have the power to change the world by p... | stackexchange_codegolf |
Define the (unnormalised) Willmore energy of a surface as the integral of squared mean curvature over it:
$$W=\int_SH^2\,dA$$
For surfaces topologically equivalent to a sphere \$W\ge4\pi\$, and \$W=4\pi\$ iff it is actually a sphere. Thus the energy quantifies how spherical a surface is.
In September 2020 I asked on Ma... | stackexchange_codegolf |
Your goal is to write a perfect player for the game of Wythoff's Nim.
Rules of Wythoff's Nim
Wythoff's Nim is a deterministic two-player game played with two piles of identical counters. Players alternate turns, in which they do one of these:
Remove one or more counters from the first pile
Remove one or more counters ... | stackexchange_codegolf |
Everyone knows the old minesweeper game that shipped with Windows XP. It's a simple grid with a 9x9 matrix of cells containing either a number (indicating how many mines are adjacent to it) or a mine.
The challenge is to generate a random 9x9 grid with 10 bombs given any integer seed (up to whatever your machine/langu... | stackexchange_codegolf |
(Randomly inspired by https://codegolf.meta.stackexchange.com/a/17272/42963)
Given a rectangular matrix of digits (i.e., 0 - 9), output the "pieces" of the matrix as if the digits are connected together forming a single piece, in ascending order by the digits. The pieces are guaranteed to connect only orthongonally -- ... | stackexchange_codegolf |
The Māori language has quite simple pronouns. It uses a single word for he/she/they/etc (ia), and the words for "you" and "me" are koe and au respectively.
There are also words for groups of exactly two people:
tāua - You and me (we, au and koe)
māua - Me and them (we, au and ia)
rāua - Them (third person plural - two... | stackexchange_codegolf |
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
| stackexchange_codegolf |
Task
Given a positive integer n, output n+1 if n is odd, and output n-1 if n is even.
Input
A positive integer. You may assume that the integer is within the handling capability of the language.
Output
A positive integer, specified above.
Testcases
input output
1 2
2 1
3 4
4 3
5 ... | stackexchange_codegolf |
The Scream™ Winter Sale is on and you just nabbed yourself an intense minimalist action game, Super Square. Upon playing it, you come to the realisation that either the game's just ridiculously hard or you're just really bad at it. In particular, there's this "rain" pattern that seems to get you every time...
Frustrat... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.