instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Given a date, output the X and Y position of the current day of the date on a digital calendar. The digital calendar is sort of the calendar that gets shown when you click on your computers clock (at least on windows), and it looks something like this:
If we assume that the given date is 25.09.2017, the result would b... | stackexchange_codegolf |
Your task to to solve the SLCSC problem, which consists in finding the shortest possible code to solve the Longest Common Subsequence problem.
A valid solution to the LCS problem for two or more strings S1, … Sn is any string T of maximal length such that the characters of T appear in all Si, in the same order as in T.... | stackexchange_codegolf |
There's a visual method for multiplication that is taught to Japanese schoolchildren [citation needed] that uses lines and crossings to get the answer.
Image Source
Your task is to implement this in ASCII art. You will be given two numbers to multiply. The output should be the corresponding ASCII art made up of \, /, ... | stackexchange_codegolf |
Write a "palipolyquine": a program that is a quine, a polyglot, and a palindrome.
Rules:
The number of polyglot languages is more preferable than code size.
The shortest answer (in bytes) wins, in case of a tie.
Polyglot and Quine rules see here: Write a Polyquine.
My example (I have a repository Freaky-Sources with... | stackexchange_codegolf |
Task
Given a non-negative integer n, output 1 if n is 0, and output the value of n otherwise.
Input
A non-negative integer.
If you would like to accept the string as input, the string would match the following regex: /^(0|[1-9][0-9]*)$/, i.e. it must not have any leading zeroes, except when it is 0.
If you accept a re... | stackexchange_codegolf |
This is the robbers' thread. See the cops' thread here.
In this cops and robbers challenge, the cops will be tasked with writing an algorithm that computes some function of their choice, while the robbers will try to come up with their algorithm. The catch is, the 'algorithm' must be a single closed-form mathematical e... | stackexchange_codegolf |
Most everyone here is familiar with Pascal's Triangle. It's formed by successive rows, where each element is the sum of its two upper-left and upper-right neighbors. Here are the first 5 rows (borrowed from Generate Pascal's triangle):
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
We're going to take Pascal's Triangle and p... | stackexchange_codegolf |
First line is made with ceil(n/2) elements where each element is: <space><odd-number><space>
Second line is made with ceil(n/2) elements, but each element is / \ only.
You may assume n >= 0 and n <= 10.
Examples
Input: 3
1 3
/ \/ \
Input: 10
1 3 5 7 9
/ \/ \/ \/ \/ \
Example in Python 3, 103 bytes:
lambda a:p... | stackexchange_codegolf |
Read infinitely from stdin, and convert every number to the corresponding symbol on a US qwerty keyboard.
No string or character literals anywhere are permitted.
E.g. if the input is 117758326, the output is !!&&%*#@^.
Letters and symbols that aren't on numbers are left alone; 11g2;;'1g2311hh21930 turns into !!g@;;'!g... | stackexchange_codegolf |
You will be given a point (x,y) relative to the center of the Ulam spiral (the center being the point which represents one), and length z. The task is to check whether there exists a path from (0,0) to (x,y) of length z, assuming prime numbers are obstacles and each turn in path has an angle of 90 degrees. Path may not... | stackexchange_codegolf |
Starry is a funny esoteric programming language in which code consists only of +*.,`' where the actual command represented by each of those characters is determined by the number of spaces in front of it. That makes it tricky even to golf fixed-output challenges, because different commands can account for vastly differ... | stackexchange_codegolf |
Thanks to your help in the Mark My Mail challenge, PPCG-Post has successfully stamped all of its parcels with the generated barcodes!
Now, it's time to decode them.
In this challenge your program will, given a barcode generated from the Mark My Mail challenge, decode it and return the encoded integer.
But watch out! Th... | stackexchange_codegolf |
Brain-Flak is a stack-based esoteric language with eight commands:
() Evaluates to 1
<> Switch active stack; evaluates to 0
[] Evaluates to height of current stack
{} Pop current stack; evaluates to the popped number
(...) Execute block and push the result; evaluates as result
<...> Execute block; eva... | stackexchange_codegolf |
Your task is to write a full program that will continue to count down from 10 every time it is run.
The first time you run the program, it should print 10.
The next time, it should output 9.
The next time, it should output 8, and so on.
Instead of printing 0, the program should crash. You do not have to handle the pro... | stackexchange_codegolf |
Given the measures of two of the interior angles of a triangle (x and y; the other angle can be easily calculated with 180 - x - y), draw a line segment that cuts this triangle into two isosceles triangles. You need to output the angle measures of both of your triangles.
However, because the base angles are the same, y... | stackexchange_codegolf |
As you probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine.
The Challenge
Here is the flag:
The flag is divided horizontally across the middle into two equally sized stripes.
Stripe colors: (0,... | stackexchange_codegolf |
Find the digit which occurs the most in a range of prime numbers.
Input:
Two numbers, p and q, specifying the range; the range includes both p and q.
Output:
The digit that occurs most frequently in that range of prime numbers. If two or more digits are tied, all of them should be outputted.
Winning Criteria:
Fastest c... | stackexchange_codegolf |
Consider the equation $$\frac x {y+z} + \frac y {x+z} + \frac z {x+y} = n$$ for positive integers \$x, y, z\$ and \$n \ge 4\$. Your code will receive \$n\$ as an input, and output three integers \$x, y\$ and \$z\$ such that the equation holds. You may assume that a solution always exists.
Background
This equation is a ... | stackexchange_codegolf |
You can create a list of all rationals 0 < r ≤ 1 by listing them ordered first by denominator and then by numerator:
1 1 1 2 1 3 1 2 3 4 1 5 1 2 3 4 5
- - - - - - - - - - - - - - - - -
1 2 3 3 4 4 5 5 5 5 6 6 7 7 7 7 7
Note that we skip any rational number that already o... | stackexchange_codegolf |
Background
Celebrating the release of Dyalog APL 16.0, where the solution to this problem is {⊢⌺(≢⍵)⊢⍵}Explanation
Task
Given a printable ASCII string of odd length n, make an n × n square with the string centered horizontally, duplicated to be centered vertically, and with acrostics of the same string in each row and ... | stackexchange_codegolf |
Risky is a new language of mine, which features an interesting form of tacit programming. In this challenge, you'll take a Risky program as input, and visualize the parsing.
No knowledge of Risky is needed for this challenge, but it's a pretty interesting language so I'd recommend trying it :p.
Task
Risky's parsing is ... | stackexchange_codegolf |
I've been posting relatively hard challenges recently, so here goes an easy one.
Task
Given an array \$A\$ and a number \$n\$, calculate the sum of all numbers of \$A\$ multiplied by \$n\$, except the last one. All numbers (the elements of \$A\$ and the value of \$n\$) are positive integers, and \$A\$ is non-empty. Sho... | stackexchange_codegolf |
In this challenge, I have a field of avocados which I'd like to juice as quickly and completely as possible. Can you write a program or function to help me work out how to juice all the avocados perfectly?
As input, you'll get the avocados as an mxm square grid, where m is an integer between 3 and 6. Each square contai... | stackexchange_codegolf |
Challenge
Draw lines in ASCII corresponding to given inputs:
in the first line there are given size of rows and columns of the view and number of separators between each point
in the second line is given list of lines separated by space
a line contains the position of head and tail coordinates (within the size of colum... | stackexchange_codegolf |
Introduction
Our goal is to efficiently find the maximum of a large amount of (redundant) data.
We define the outer product of vectors \$A\$ and \$B\$ as a matrix containing the products of all entries of \$A\$ with each entry of \$B\$. (see outer Product)
$$
A\otimes B := A\cdot B^T = \left(\begin{array}{rrr}
A(1)\cdo... | stackexchange_codegolf |
I found it quite hard to achieve a range of numbers as rows in MySQL.
For example the range 1-5 is achieved by:
SELECT 1
UNION
SELECT 2
UNION
SELECT 3
UNION
SELECT 4
UNION
SELECT 5
will result in:
1
2
3
4
5
for 0-99 I can cross join two 0-9 tables:
CREATE TABLE nums as
SELECT 0 as num
UNION
SELECT 1
UNION
SELECT ... | stackexchange_codegolf |
This challenge is a harder version of this one.
A variable number of trits is an array of 0 or more trits (a trit is a ternary digit). So [0, 2, 2, 1] is a variable number of trits, but so is [].
Write a function or program that, given an non-negative integer returns a variable number of trits such that every integer h... | stackexchange_codegolf |
Your task is to input a string, and output the number of spaces in the string.
This is code-golf, so least number of bytes win. Your
Test Cases
Double quotes are not part of the test cases.
"test" => 0
"Hello, World!" => 1
"C O D E G O L F" => 7
" " => 6
| 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 |
\$723 = 3 \times 241\$ is a semi-prime (the product of two primes) whose prime factors include all digits from \$1\$ to \$n\$, where \$n\$ is the total number of digits between them. Another way to look at this is that the (sorted) digits in the factorisation of \$723\$ are all consecutive. The first 10 such semi-prime... | stackexchange_codegolf |
I just created a language on the spot, and it's called "interpreter". Called as such because the only valid word is "interpreter"!
A sample program in "interpreter" looks like this:
interpreter interpreterinterpreter interpreterinterpreterinterpreter interpreterinterpreterinterpreterinterpreter interpreterinterpreterin... | stackexchange_codegolf |
In mathematics an exclamation mark ! often means factorial and it comes after the argument.
In programming an exclamation mark ! often means negation and it comes before the argument.
For this challenge we'll only apply these operations to zero and one.
Factorial
0! = 1
1! = 1
Negation
!0 = 1
!1 = 0
Take a string of ... | stackexchange_codegolf |
Introduction
The LaTeX typesetting system uses macros for defining accents.
For example, the letter ê is produced by \hat{e}.
In this challenge, your task is to implement an ASCII version of this functionality.
Input
Your input is a non-empty string of printable ASCII characters.
It will not contain newlines.
Output
Yo... | stackexchange_codegolf |
Being a Haskell hacker, I prefer pointfree notation over pointful. Unfortunately some people find pointfree notation hard to read, and I find it hard to get the correct number of parentheses when I write in pointful.
Help me convert code written in pointfree to pointful notation!
About
In pointfree notation we use poin... | stackexchange_codegolf |
A Fermi-Dirac Prime is a prime power of the form \$p^{2^k}\$, where \$p\$ is prime and \$k \geq 0\$, or in other words, a prime to the power of an integer power of two. They are listed as integer sequence A050376. While a normal prime factorization generally does not contain a set of distinct primes (for example \$24=2... | stackexchange_codegolf |
Given an integer n as input, write a function that dynamically allocates n bytes and returns their address.
Rules
The allocator must be able to dynamically allocate memory at runtime.
It doesn't matter where the memory is allocated to or in what form, as long as it's allocated in a valid location which can be read fro... | stackexchange_codegolf |
Your task is to print the following:
I have a pen
I have an apple
Uh! Apple pen!
I have a pen
I have pineapple
Uh! Pineapple pen!
Apple pen...
Pineapple pen...
Uh! Pen Pineapple Apple Pen!
Remember, this is code-golf, so the code with the smallest number of bytes wins.
Leaderboards
Here is a Stack Snippet to generat... | stackexchange_codegolf |
Challenge
Given three numbers \$a\$, \$b\$, and \$n\$, you must expand \$(a + bx)^n\$ in ascending powers of \$x\$ up to \$x^3\$.
Binomial Expansion
Note that this method is an approximation
The binomial expansion works like so:
(a + bx)^n = a^n(1 + bx/a)^n
= a^n(1 + n(bx/a) + n(n -1)(bx/a)^2/2! + n(n-1)(n-1... | stackexchange_codegolf |
Consider a permutation of the integers 1, ..., n, such as this one for n = 6:
[5,2,4,3,6,1]
If you view the permutation as a mapping from [1,2,3,4,5,6] to [5,2,4,3,6,1], the permutation can be decomponsed into disjoint cycles. A cycle is a subset of elements that map to each other. For example, 1 gets mapped to 5, whi... | stackexchange_codegolf |
Challenge
Given the Cartesian coordinates of two or more distinct points in Euclidean n-space (\$\mathbb{R}^n\$), output the minimum dimension of a flat (affine) subspace that contains those points, that is 1 for a line, 2 for a plane, and so on.
For example, in 3-space (the 3-dimensional world we live in), there are a... | stackexchange_codegolf |
Input:
A positive integer n which is 1 <= n <= 25000.
Output:
In this sequence we start with the decimal number 1/n.
Then we take the sum of digits up until the n'th digit after the comma (1-indexed); followed by the sum of digits up until the (n-1)'th, then (n-2)'th, etc. Continue until n is 1.
The output is the sum ... | stackexchange_codegolf |
I was surprised to not find this asked already, though there is a great question on darts checkouts: Darts meets Codegolf
Your challenge is to calculate which scores are not possible with 'n' darts below the maximum score for 'n' darts. E.g. for n=3, the maximum possible score is 180 so you would return [163,166,169,17... | stackexchange_codegolf |
Your task is to write a non-empty program / function of byte count L, which, when repeated M times, checks whether a given positive integer N is equal to L × M.
You should, in theory, support an arbitrary number of repetitions (an arbitrary positive integer value of M), but it's fine if, due to language limitations, it... | stackexchange_codegolf |
Given a positive integer as input, output that integer, but with its bits rotated two times to the right. Also, think of the number as a donut of bits, eg. 21 -> (10101). If all of the bits suddenly decided to move to the right, they would wrap around. eg. rRot(21) -> (11010) = 26. Do what i explained 2 times (at the s... | stackexchange_codegolf |
A quine is a program that produces output that's identical to the program's source code. On this website, we generally only care about proper quines (at the time of writing, the current definition is "some part of the output is encoded by a different part of the program").
What advice do you have for writing proper qui... | stackexchange_codegolf |
Given a printable ASCII string representing a path to a file on a POSIX-compliant system, return just the filename, i.e. remove everything until and including the last slash (/):
/full/path/file.name.ext → file.name.ext
nopath.here → nopath.here
dir/.hidden → .hidden
/dirs.can/have.exts/file → file
./here → here
don't\... | stackexchange_codegolf |
Context
(Feel free to skip, doesn't really matter for the algorithmic explanation of the task)
European Portuguese is a fairly complicated language to learn, mostly because of its grammar. One particular annoying thing is conjugating the verbs correctly:
We have this mechanism that, when we have a verb followed by a no... | stackexchange_codegolf |
Challenge:
Input:
You take two inputs:
- A string only containing printable ASCII (excluding spaces, tabs or new-lines)
- A printable ASCII character
Output:
The first line will contain the string-input. Every i-modulo-3 first occurrence of this character will move in a South-East direction; every i-modulo-3 second occ... | stackexchange_codegolf |
In Golfenhagen, The people are allowed, and encouraged, to melt down old coins for scrap metal, if the smelter can make a profit off of it. There are 5 coins that make the Golfenhagen mint. The half-penny(0.5)(H), the penny(1)(P), the tea (5)(T), the flag (10)(F), and the driver (25)(D). Golfenhagen also mints bills, i... | stackexchange_codegolf |
For this, imagine that the following words are really nasty cuss words:
Frag, Smeg, Felgercarb, Blatherskite, Dadgum, Fnord, Smurf, Schmit
Now, I need to filter out swear words on my website.
Normally the site will search for these words and ** them out:
I hate this s****ing cussword filter! It won't let me f***ging s... | stackexchange_codegolf |
A composition of an integer \$n\$ is a representation of \$n\$ as a sum of positive integers. For example the eight compositions of 4 are as follows:
4, 3 + 1, 1 + 3, 2 + 2, 2 + 1 + 1, 1 + 2 + 1, 1 + 1 + 2, 1 + 1 + 1 + 1.
The challenge is to output the number of compositions of \$n\$ in which the greatest part is odd.... | stackexchange_codegolf |
Using your language of choice, write a function that takes a variable number of arguments and returns the number of arguments it was called with.
Specifics:
Your language needs to support variadic argument functions: something callable that takes an arbitrary number of arguments and returns a value.
Parameters must be... | stackexchange_codegolf |
Magic the gathering has many unique names for colour combinations in decks, as an example when Blue and White appear together in a deck, the deck maye sometimes be named after the Ravnican Guild that features those colours, namely 'Azorius'. There are some exceptions, and oddities though.
Below is a list of colour lett... | stackexchange_codegolf |
The wizard has a cunning cousin who is a witch. She looks down on the wizard, regarding him and his puzzles as mathematically naive. On reading his latest puzzle, she scorned him for always asking discrete problems with what she (unfairly) characterises as simple solutions, where the real, proper question should be co... | stackexchange_codegolf |
Poke is a really simple incomplete-information game. It's like "Poker", but simpler. At the start of every round, each player is dealt a hand. To simplify things, a hand is a uniformly distributed random number between 0 and 1. Each player only knows their own hand. The player that wins the round is the one whose hand ... | stackexchange_codegolf |
You are piloting a spaceship, outfitted with an engine that can accelerate you at 1km/s^2 in the direction the ship is facing (you have very good inertial dampers). You also have thrusters which can rotate you 180 degrees in 1s (rotating 45 degrees takes 0.25s, etc.).
You see on your scanner another ship, and decide t... | stackexchange_codegolf |
Today's problem is easy. You're given two strings A and B of equal length consisting of only the characters ( and ). Check whether after any number of operations you can make both strings balanced or not. The only operation allowed is swapping A[i] and B[i], where i is an arbitrary index.
Here is the definition of a ba... | stackexchange_codegolf |
In 2009, Hannah Alpert described the "far-difference" representation, a novel way of representing integers as sums and differences of Fibonacci numbers according to the following rules:
every two terms of the same sign differ in index by at least 4, and
every two terms with different signs differ in index by at least ... | stackexchange_codegolf |
Here's an array representing a standard deck of cards, including two Jokers.
[
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "K... | stackexchange_codegolf |
The RGB color value #00FF00 is a rather important one: it is used to make movies, TV shows, weather announcements, and more. It is the famous "TV green" or "green screen" color.
The Challenge
Your task is to write a program that takes two input images, both in PNG format (or in your image library's image object type) a... | stackexchange_codegolf |
Find a way to make circles of a given radius using characters in a console. Please specify the font name and size. Also, please provide at least one example of the output.
For example:
Input:
3
Output:
******
** **
** **
* *
** **
** **
******
...Well, something better looking... | stackexchange_codegolf |
Your task is to write a non-empty computer program comprised of some sequence of bytes. If we choose a particular byte in the program and remove all instances of it from the program, the modified program should output the removed byte.
For example if our program were
aabacba
Then bcb would output a, aaaca would need ... | stackexchange_codegolf |
Awhile back I encountered a simple programming puzzle to determine whether a string was a pangram, or a perfect pangram. (Although it's worth noting that this particular challenge gave a different meaning than the standard definition of a "perfect pangram," to mean any sentence where every letter appears n times for so... | stackexchange_codegolf |
The task
Today's special offer: consonants and punctuation for FREE!
Your program or function will be given as input the first 6 paragraphs of Lewis Carroll's famous novel Alice's Adventures in Wonderland, with all vowels [aeiouAEIOU] removed and all other characters left intact.
It must output the original text, byte-... | stackexchange_codegolf |
Surreal Numbers are one way of describing numbers using sets. In this challenge you will determine the value of a surreal number.
Intro
A surreal number consists of two sets: a left and right. The value of the surreal number must be greater than all numbers in the left set and less than all numbers in the right set. We... | stackexchange_codegolf |
Given two numbers in tape location #0 and tape location #1 in Brainfuck, compute their product into another tape location (specify with answer). Optimize for the least amount of time-units used, where the interpretation of any command uses one time-unit. As example, here is a quick C++ program to determine the number o... | stackexchange_codegolf |
Given a positive integer input n seconds, output the time in human readable format.
The time will be considered from 00:00:00, 1st January, 1 A.D.
Leap years must be taken into account.
Assume that the gregorian calendar was followed since the beginning.
(Gregorian Calendar: Every year that is exactly divisible by four... | stackexchange_codegolf |
I've been doing word searches recently, and I thought it would be so much easier if all of the words read left-to-right. But rewriting all the lines takes a lot of effort! So I'm enlisting code golfers to help.
(Disclaimer: The above story may or may not be remotely accurate.)
Your code will take a rectangular grid and... | stackexchange_codegolf |
TeaScript is a powerful JavaScript golfing language created by StackExchange, PPCG, user Downgoat. TeaScript compiles to JavaScript and contains many helpful features for golfing
This question is to list some TeaScript golfing tips
| stackexchange_codegolf |
What general tips do you have for golfing in Chef? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Chef (e.g. "remove unnecessary whitespace" is not an answer).
Please post one tip per answer.
| stackexchange_codegolf |
You need to produce output that is non-deterministic.
In this case, this will be defined to mean that the output will not always be the same result.
Rules:
A pseudo-random number generator that always has the same seed does not count.
You can rely on the program being run at a different (unknown) time each execution.
... | stackexchange_codegolf |
Write a program or function that:
Takes as input a list or array of 128 numbers.
Sends that array to a GPU
Performs a calculation on the GPU to square each element of the array and then sum them
Gets the answer from the GPU, and returns or displays it
So your program will simply return the sum of the squares of its i... | stackexchange_codegolf |
Given a multidimensional, rectangular array of nonnegative integers, sort it at every depth (lexicographically), starting from the innermost.
For example, with this array:
[ [ [5, 1, 4],
[10, 7, 21] ],
[ [9, 20, 2],
[4, 2, 19] ] ]
You'd sort at the deepest first:
[ [ [1, 4, 5],
[7, 10, 21] ],
[ [2,... | stackexchange_codegolf |
Matrix challenges are popular. There's an issue of how to provide test cases. A common method is the row-wise array-of-arrays representation, such as:
[[1,2],[3,4],[5,6]] -> a 3 by 2 matrix
This is good with vertical space, but there's always the task of converting the test cases into something your language can use, ... | stackexchange_codegolf |
Background
In Scrabble, players take turns placing tiles on a grid so that each contiguous set of (more than one) tiles in every row and column makes a word. In one play, tiles can be placed anywhere in a single row or column as long as there is a contiguous set of tiles that includes all of the ones placed.1 A word is... | stackexchange_codegolf |
Introduction:
Inspired by both Perfect License Plates and How many points does my license plate give?
Just like in the challenges above, me and my little brother had a game of our own with license plates as kids. We tried to create (random/funny) sentences with the (numbers and) letters of the license plates.
For examp... | stackexchange_codegolf |
Any general tips for golfing in VB.net?
This, similar to Pascal, is a very rarely used language, thus having very few resources online
Visual Basic.NET (VB.NET) is a multi-paradigm, managed, type-safe, object-oriented computer programming language. Along with C# and F#, it is one of the main languages targeting the .NE... | stackexchange_codegolf |
This one is inspired by Calvin's Hobbies recent multiplication table challenge.
Write a function or program that takes an integer N as input and prints or returns a N-by-N unique multiplication spiral. The code must (in theory) work for N between 0 and 1000 (outputting this can be hard though). The output should be equ... | stackexchange_codegolf |
In atomic physics and quantum chemistry, the electron configuration is the distribution of electrons of an atom in atomic orbitals. For example, the electron configuration of the neon atom is 1s2 2s2 2p6 (From Wikipedia)
Challenge
Your challenge is to take a number representing the atomic number of an element and out... | stackexchange_codegolf |
For this challenge, you will be required to write 3 programs:
The first program should be a quine, i.e, it should print it's own source code.
The second program should read the input and print all of it.
The third program should simply print the string "Hello, Permutations!", with or without quotes.
In addition to th... | stackexchange_codegolf |
This challenge was originally sandboxed by Magic Octopus Urn; I adopted and posted it with his permission.
This is the cops' thread. The robbers' thread is here.
The challenge
Step One: Write a piece of code (function or full program) which checks for primality.
Step Two: Remove pieces of your code by replacing charac... | stackexchange_codegolf |
Challenge :
Check if the given number forms a number staircase or not
Input :
A integer (greater than 0 and not decimal). NOTE : You can take input as string , array of digits.
Output :
a truthy / falsy value depending on whether the number forms a staircase or not
Number staircase :
A number staircase is an integer... | stackexchange_codegolf |
Background
The traveling salesman problem (TSP) asks for the shortest circuit that visits a given collection of cities. For the purposes of this question, the cities will be points in the plane and the distances between them will be the usual Euclidean distances (rounded to the nearest integer). The circuit must be "... | stackexchange_codegolf |
Your task is to write a program, function, or snippet that will output one value if run forward, and another if run backward. The program must run without errors.
The output can be any two distinct values, of the same data type. For example, 1 and 3, true and false, or 't' and 'f'. In languages without a concept of dat... | stackexchange_codegolf |
Overview
As most of y'all who visit chat know, I am Russian by ethnicity[citation not needed]. Recently, I switched from a keyboard that maps the letters 1-to-1 (mnemonic) to Windows' default mnemonic keyboard. Here are the letter mappings:
"`" -> "ъ"
"q" -> "я"
"w" -> "ш"
"e" -> "е"
"r" -> "р"
"t" -> "т"
"u" -> "у"
"i... | stackexchange_codegolf |
Implement a simple integer operation scriptable calculator.
Concept
The accumulator starts at 0 and has operations performed on it. At the end of the program output the value of the accumulator.
Operations:
+ adds 1 to the accumulator
- subtracts 1 from the accumulator
* multiplies the accumulator by 2
/ divides the a... | 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 |
Bounty is over, thephpdeveloper wins with Conway's Game of Life
The web platform today is advancing at a rapid rate. Features like CSS3 animations, transforms, drop shadows and gradients, <canvas>, <audio> and <video> tags, SVG, WebGL, and many more mean that you can do far more in the browser, and in far less code, t... | stackexchange_codegolf |
A magic square is an \$ n \times n \$ square grid, such that the sum of the integers on each row and column are equal. Note that the definition which will be used in this challenge is different than the one used by Wikipedia, since
diagonal sums are not accounted for
the numbers are not required to be distinct or in t... | stackexchange_codegolf |
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... | stackexchange_codegolf |
Given a positive integer \$n\$ and another positive integer \$b\$ (\$1 < b < 36\$), return the number of digits/length of \$n\$ in base \$b\$
1597 16 -> 3
1709 9 -> 4
190 29 -> 2
873 24 -> 3
1061 27 -> 3
289 26 -> 2
1575 34 -> 3
1135 15 -> 3
1161 22 -> 3
585 23 -> 3
1412 23 -> 3
1268 14 -> 3
714 12 -> 3
700 29 -> 2
100... | stackexchange_codegolf |
Create a program that interprets the programming language Bucket.
Bucket works on two buckets: the first can hold A and the second can hold B units of liquid. The things you can do with these buckets are:
f: fill bucket A
F: fill bucket B
e: empty bucket A
E: empty bucket B
p: pour units of liquid from A to B until one... | stackexchange_codegolf |
Let's have a list of positive integers
[6,1,9,3,7,4,6,3,2,7,6,6]
this will represent a river. We would like to skip a stone across this river. We can throw the stone as far as we want and whatever number it lands on it will skip that many places. So if we start by throwing it 2 spaces, it will land on the 1 skip fo... | stackexchange_codegolf |
Introduction
On 30 May 2020, NASA and SpaceX launched a crewed rocket to the international space station on the SpaceX Demo 2 mission. This is the first time humans have been launched into orbit from American soil since the retiring of the Space Shuttle in 2011, and the first time ever that a private company has launch... | stackexchange_codegolf |
Sum-It is a language I created (quite late) for the Language Design Contest in TNB, for which the theme was "Range". Naturally I interpreted this as "Mountain Range" and created a language about mountains.
Sum-It code takes the form of several ASCII art mountains, using only the / and \ characters. The mountains are th... | stackexchange_codegolf |
This is the inverse of "Encode the date in Christmas Eve format."
Write a program that takes as input the string Christmas, possibly followed by Eve between 1 and 365 times, and outputs the date encoded in YYYY-MM-DD format, or any format from which the year, month, and date can be easily obtained. Assume that the "Ch... | stackexchange_codegolf |
Similar to our threads for language-specific golfing tips: what are general tricks to shorten regular expressions?
I can see three uses of regex when it comes to golfing: classic regex golf ("here is a list that should match, and here is a list that should fail"), using regex to solve computational problems and regula... | stackexchange_codegolf |
Given a positive integer \$n\$ output the integers \$a\$ and \$b\$ (forming reduced fraction \$a/b\$) such that:
$$\frac a b = \prod ^n _{k=1} \frac {p^2_k - 1} {p^2_k + 1}$$
Where \$p_k\$ is the \$k\$ th prime number (with \$p_1 = 2\$).
Examples:
1 -> 3, 5
2 -> 12, 25
3 -> 144, 325
4 -> 3456, 8125
5 -> 41472... | stackexchange_codegolf |
Overview
I was playing with Desmos and discovered a really cool spiral:
Doing some research, I discovered that this spiral was the Archimedian spiral. Every point on the spiral is exactly \$\theta\$ away from the origin, where \$\theta\$ is the angle from the origin. That is, any point on the spiral has the polar coo... | stackexchange_codegolf |
Below on the left is a picture of a sorting network that can sort 4 inputs. On the right you can see it sorting the input 3,2,4,1.
A sorting network of size n consists of a set of n horizontal wires where two wires can be connected by a vertical wire. The inputs to a sorting network move from the left to the right on ... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.