instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Inspired by Is this Flow Free puzzle trivial? by @Bubbler. Lengthy chunks of this challenge are borrowed from there. This may be one step of a solution for the linked challenge, depending on chosen strategy.
Background
Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dot... | stackexchange_codegolf |
Given three non-negative integers y, m, and d (of which at least one must be positive) and a valid date with a positive year (in any reasonable format that includes the year, month, and day, and no additional information), output the date that is y years, m months, and d days after the original date.
The Gregorian cale... | stackexchange_codegolf |
Assume we want to shift an array like it is done in the 2048 game: if we have two equal consecutive elements in array, merge them into twice the value element.
Shift must return a new array, where every pair of consecutive equal elements is replaced with their sum, and pairs should not intersect.
Shifting is performed... | stackexchange_codegolf |
Suppose we have a matrix like this:
11111
12221
12321
12221
11111
This matrix represents a terrain, and each cell represents a portion of terrain. The number in each cell represents the time the portion of terrain needs to be completely burnt (in minutes, if a measurement unit is needed), according to its combustibili... | stackexchange_codegolf |
Untouchable Numbersα
An untouchable number is a positive integer that cannot be expressed as the sum of all the proper divisors of any positive integer (including the untouchable number itself).
For example, the number 4 is not untouchable as it is equal to the sum of the proper divisors of 9: 1 + 3 = 4. The number 5 ... | stackexchange_codegolf |
In this challenge, bots (consisting of JS functions) move around an infinite factory (playing field), collecting characters. These characters can be used to build worker bots, or dropped for other bots to pick up.
This challenge is a modified redo of Bot Factory KoTH, which was broken by a mistake in the spec.
Results
... | stackexchange_codegolf |
Like the previous SmokeDetector challenge? This one is for you too ;)
Note: SmokeDetector is a bot that detects spam and offensive posts on the network and posts alerts to chat.
What to implement
Smokey's !!/coffee command uniformly at random picks one of these words (sorts of coffee):
Espresso
Macchiato
Ristretto
A... | stackexchange_codegolf |
NATO phonetic alphabet is a spelling alphabet that associate to each of the 26 letters of the English alphabet one word (table below) that is easy to understand over the radio or telephone. For example, if you want to communicate the word CAT over the telephone, you do the following spelling:
CHARLIE ALFA TANGO
But wha... | stackexchange_codegolf |
The task is to find a way to draw a horizontal line in an array of 16-bit integers.
We're assuming a 256x192 pixel array with 16 pixels per word. A line is a contiguous run of set (1) bits. Lines can start in the middle of any word, overlap any other words, and end in any word; they may also start and end in the same ... | stackexchange_codegolf |
Introduction:
I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post al... | stackexchange_codegolf |
Challenge:
Take a vector / list of integers as input, and output the largest number that's adjacent to a zero.
Specifications:
As always, optional input and output format
You may assume that there will be at least one zero, and at least one non-zero element.
Test cases:
1 4 3 6 0 3 7 0
7
9 4 9 0 9 0 9 15 -2
9
-4 -6... | stackexchange_codegolf |
A ragged matrix, is a matrix that has a different number of elements in each row. Your challenge is to write a program in any favorable language to find the indices of all occurrences of target in the ragged matrix.
Input:
A list of ragged lists (can be empty) of positive integers and a target range e.g. 26-56. The tar... | stackexchange_codegolf |
Given a matrix like this:
1 1 3 -2
3 -4 1 -1
1 1 1 0
0 -1 0 0
By taking a 2×2 "sliding sum", where the sum of every 2×2 region of the matrix is one element of the resulting matrix, we get:
1 1 1
1 -1 1
1 1 1
We can do this for sliding windows of any size. For example, a 1×3 sliding sum of the same input ... | stackexchange_codegolf |
I have string \$s\$ of length \$n\$ and some constant integer \$k\$ which is at most \$n\$. Give the fastest algorithm to sample a random string with Levenshtein distance \$k\$ from \$s\$ uniformly.
Your algorithm should output any of the strings with edit distance exactly \$k \leq n\$ from the input string \$s\$ with ... | stackexchange_codegolf |
If you have a small child in your house, you may have come across foam bath letters. These can be moistened and stuck to flat surfaces such as tiles and the side of the bath to make words and messages.
The range of words and messages is somewhat limited if you only have one set though, since you only get 36 characters:... | stackexchange_codegolf |
I recently saw this question on stackoverflow. It's a great question, but there's one fatal problem with the question. They are asking for the best way to do it. E.g, easiest to read, most idiomatic, neatest etc. Don't they know that isn't what matters? You're supposed to ask about how to do it with the fewest bytes of... | stackexchange_codegolf |
Given a positive number n, output all distinct multiplicative partitions of n in any convenient format.
A multiplicative partition of n is a set of integers, all greater than one, such that their product is n. For example, 20 has the following distinct multiplicative partitions:
2 * 2 * 5
2 * 10
4 * 5
20
Order does no... | stackexchange_codegolf |
The title is an homage of the Natural Number Game, which is a nice interactive tutorial into proving certain properties of natural numbers in Lean.
Given that the previous two were slightly too involved (either mathematically or technically) for newcomers to Lean (i.e. the vast majority of CGCC community), I decided to... | stackexchange_codegolf |
Challenge
Premise
Euler diagrams consist of simple closed shapes in a 2-D plane that each depict a set or category. How or whether these shapes overlap demonstrates the relationships between the sets.
I'm a spoilt brat who thinks Euler diagrams are hard to draw. For any Euler diagram, I want to know the minimum number ... | stackexchange_codegolf |
Introduction
Your mission in life is simple: Prove people wrong on the internet!
To do this you usually carefully analyze their statements and point out the contradiction in them.
It's time to automate this, but as we are lazy, we want to prove people wrong with the least effort (read: shortest code) possible.
Specific... | stackexchange_codegolf |
Inputs:
current hour: from 0 to 23 (inclusive)
delta of hours: [current hour] + [delta of hours] = withing the range of Integer
Output:
delta of days: the value which shows difference in days between day of current hour and day of sum [current hour] + [delta of hours]
Scoring
Answers will be scored in bytes with ... | stackexchange_codegolf |
Muriel is a language where the only way to loop is to create a quine and execute it. Your job is to create your own language with this property and an implementation of it in a pre-existing language.
We will define a Muriel-like language like as follows:
It has a built-in command for executing code in its own language... | stackexchange_codegolf |
In this challenge you will compute numbers from a curious sequence.
Your input is a single decimal nonnegative integer. Reverse the bits in this integer and then square the number to get the required output.
When reversing the bits you must not use any leading zeroes in the input. For example:
26 (base 10) = 11010 (bas... | stackexchange_codegolf |
Any two separate nodes in a binary tree have a common ancestor, which is the root of a binary tree. The lowest common ancestor(LCA) is thus defined as the node that is furthest from the root and that is the ancestor of the two nodes.
The following are binary trees and the lowest common ancestors of the some of their n... | stackexchange_codegolf |
In the burial place of King Silo of Asturias there is an inscription that reads SILO PRINCEPS FECIT (King Silo made this).
The first letter is found in the very middle, and from there one reads by going in any non-diagonal direction radiating outward. The final letter is found on all four corners. In this challenge,... | stackexchange_codegolf |
Everybody loves golfing code. Code is written in English (eh...). Therefore, everybody loves golfing English!
Your task is to write a program or function that takes a string as input, and then returns or prints the golfed version. There will be no newlines or tabs in the input.
This is how you golf a string. The order... | stackexchange_codegolf |
The set of all polynomials with integer coefficients is countable.
This means that there is a sequence that contains each polynomial with integer coefficients exactly once.
Your goal is it to write a function or program that outputs such a sequence.
Example (you may use another sequence):
// list of integers [i -> Z(i)... | stackexchange_codegolf |
Suppose an infinite tiling of hexagons composed of |/\ characters.
/ \ / \ / \ / \
| | | | |
\ / \ / \ / \ / etc.
| | | |
\ / \ / \ /
Given input n > 0, output a triangular portion of that tiling as depicted in the below examples, anchored with a _ in the middle of a hexagon:
n=1
\_/
n=2
\/ \/
... | stackexchange_codegolf |
You will be given two Arrays / Lists / Vectors of non-negative integers A and B. Your task is to output the highest integer N that appears in both A and B, and is also unique in both A and B.
You may assume that there is at least one such number.
Any reasonable Input and Output method / format is allowed.
These Looph... | stackexchange_codegolf |
Given \$A = (a_1,\dots,a_k)\ k\ge2 \$ a sequence of positive integers, in which all elements are different.
Starting from \$i=2\$, while \$a_i\in A:\$ (until the last element)
If \$d=|a_i-a_{i-1}|\$ is not already in \$A\$, append \$d\$ to \$A\$
Increase \$i\$
Output the completed sequence.
This is code-golf
Example
... | 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 |
Preamble
We've already proven we're good at adding two numbers, but many solutions only operate on tiny numbers like 2³²-1, honestly we can do a lot better.
The Challenge
Given two unsigned, non-negative integers, add them together and return the output.
Input may be taken in any convenient format (String, Array of byt... | stackexchange_codegolf |
Have you ever found a good challenge to answer, answered it and then found out somebody posted a solution with a better score in the same language?
Challenge
Write a program/function that takes a PPCG question ID and outputs a leaderboard.
A leaderboard consists of the rank, the language, the score, the author and the ... | stackexchange_codegolf |
Bowl Pile Height
The goal of this puzzle is to compute the height of a stack of bowls.
A bowl is defined to be a radially symmetric device without thickness.
Its silhouette shape is an even polynomial. The stack is described by a list of radii, each associated with an even polynomial, given as input as a list of coeff... | stackexchange_codegolf |
This is the robber's thread of a cops-and-robbers challenge. You can view the cop's thread here
A pretty common beginner style question is to print some string, but, there's a catch!, you need to do it without using any of the characters in the string itself!
For this challenge we will find out who is the best at prin... | stackexchange_codegolf |
Your task is to convert non-empty strings - between strings using the 26 letters, and programs, which are strings of bytes, where each byte has 256 possible values. You should use the same codepage your answer is written in for the possible values of bytes.
You need to do the following to do the conversion:
Convert th... | stackexchange_codegolf |
What's great about golfing is not having to deal with errors. Except this time you won't get off so lightly! I need to do some arithmetic with certain limitations, and I wan't to know what goes wrong if anything.
Challenge
Given a list of signed integer values [n1..n11], give the following result or the first error tha... | stackexchange_codegolf |
If you have a small child in your house, you may have come across foam bath letters. These can be moistened and stuck to flat surfaces such as tiles and the side of the bath to make words and messages.
The range of words and messages is somewhat limited if you only have one set though, since you only get 36 characters:... | stackexchange_codegolf |
Come November 1, Programming Puzzles and Code Golf will graduate, so in the next 11 months, we'll want to save some memories from when we were ungraduated.
Write a program that produces the PPCG favicon, seen below.
The image must be at least 64x64 pixels.
The blue must be the color #62B0DF. The background can be whi... | 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 |
Challenge:
Create a function or program that will take an input N (a number from 0 - 24) which represents the HOUR.
Output should draw an analog clock out of asterisks showing the hour N.
Notes:
•The minute hand must be longer than the hour hand (in terms of number of asterisks used)
•The minute hand must be at least... | stackexchange_codegolf |
This might be a very basic question in terms of math,
x % constant = x_modulus
(x + some_number) % constant = y_modulus
Given the value of x_modulus, y_modulus, (x + some_number) and constant(common in both), output the value of x itself based on these values.
| stackexchange_codegolf |
The pyramid begins with the row 1 1. We'll call this row 1. For each subsequent row, start with the previous row and insert the current row number between every adjacent pair of numbers that sums to the current row number.
$$
1\quad1\\
1\quad\color{red}{2}\quad1\\
1\quad\color{red}{3}\quad2\quad\color{red}{3}\quad1\\
1... | stackexchange_codegolf |
The above image is called a hexa-glyph. Hexa-glyphs are some cool patterns I made up while doodling during my DiffEq class. Here's how you make one:
Consider the following set of points, shaped like a regular hexagram. The inner hexagon is what will contain the final glyph, while the outer 6 points form a star and... | stackexchange_codegolf |
Challenge
Given an integer, \$s\$, as input where \$s\geq 1\$ output the value of \$\zeta(s)\$ (Where \$\zeta(x)\$ represents the Riemann Zeta Function).
Further information
\$\zeta(s)\$ is defined as:
$$\zeta(s) = \sum\limits^\infty_{n=1}\frac{1}{n^s}$$
You should output your answer to 5 decimal places (no more, no le... | stackexchange_codegolf |
It's time to conclude the series of John Conway challenges of mine.
Background
A FRACTRAN program consists of an ordered list of fractions. The program starts by taking a single integer as input. Each iteration of the program, it searches the list for the first fraction such that multiplying the number by that fraction... | stackexchange_codegolf |
Toki Pona is a constructed language with 137ish words, designed to constrain the speaker to expressing ideas in a simple and straightforward manner, reducing ideas to more essential forms.
Often, people attempt to avoid directly expressing numeric quantities in Toki Pona, opting to express them in more practical terms.... | stackexchange_codegolf |
A celebration of the many faces of APL
Given a string among those in column 1 or column 2 of the below table, return the string's neighbor to its right. In other words, if given a string in column 1 then return column 2's string on that row, and if given a string in column 2 then return column 3's string on that row.
T... | stackexchange_codegolf |
Let \$n=42\$ (Input)
Then divisors are : 1, 2, 3, 6, 7, 14, 21, 42
Squaring each divisor : 1, 4, 9, 36, 49, 196, 441, 1764
Taking sum (adding) : 2500
Since \$50\times 50=2500\$ therefore we return a truthy value. If it is not a perfect square, return a falsy value.
Examples :
42 ---> true
1 ---> true
246 ---> true
1... | stackexchange_codegolf |
ProSet is a classic card game that is played normally with 63 cards. One card has 6 colored dots on it, like below
The rest of the cards are missing some of these 6 dots, but each card has at least 1 dot. Every card in the deck is different. Below are some example valid cards.
A ProSet is a nonempty set of cards such... | stackexchange_codegolf |
You task here is very simple:
Given a positive integer n without leading zeroes as input, split it in all possible ways
Examples
Input->Output
111 -> {{111}, {1, 11}, {11, 1}, {1, 1, 1}}
123 -> {{123}, {12, 3}, {1, 23}, {1, 2, 3}}
8451 -> {{8451}, {845, 1}, {8, 451}, {84, 51}, {84, 5, 1}, {8, 45, 1}, {8, 4, 51}... | stackexchange_codegolf |
For this golf, you will need to use more than one language.
The task
A Rube Goldberg machine is a contraption that takes an enormous number of complicated steps in order to execute a very simple task. The goal of this golf is to output Rube Goldberg... but not directly.
The machine
Your "machine" is the source code tha... | stackexchange_codegolf |
Consider an array A of integers of length n. The k-max subarray sum asks us to find up to \$k \leq 3\$ (contiguous) non overlapping subarrays of A with maximum sum. If A is all negative then this sum will be 0. If A = [-1, 2, -1, 2, -1, 2, 2] and k=2 for example, then the two subarrays could be [2, -1, 2] and [2, 2] ... | stackexchange_codegolf |
Specification
This challenge is simple to state: your input is a non-empty array of nonnegative integers, and your task is to partition it into as few substrings as possible, such that each substring is a permutation of a consecutive integer range.
More formally, if the input array is A, then the output is minimum numb... | stackexchange_codegolf |
Background
A binary tree is a rooted tree whose every node has at most two children.
A labelled binary tree is a binary tree whose every node is labelled with a positive integer; moreover, all labels are distinct.
A BST (binary search tree) is a labelled binary tree in which the label of each node is greater than the l... | 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 |
Yes, I know there is a similar question, but this one specifically concerns any possible words, even with letters left over, while the linked one restricts to a permutation of the input
Objective
Have you ever had those moments in a Scrabble game where you're staring at your letters, trying to find a good word, and y... | stackexchange_codegolf |
Back to basics...
As a teacher at the local primary (grade?) school, you need a way to teach your class their times tables. At your disposal, you have hundred squares and a load of red pens. You need to also be able to show your class the correct answers quickly.
Now, you're clever enough to write a program that can do... | stackexchange_codegolf |
Introduction
Jim and Bob are playing badminton doubles against two other players, but mid-game they face a dilemma:
After a fast-paced rally they have no idea who has to serve next and where they have to stand for the next serve.
Bad enough they only know the scores in order.
Rules:
To help them out, you have to know t... | stackexchange_codegolf |
Challenge
Given a string input, output the demolished version of it.
The Process
P
r Pr r
o o o
g g g
r r r rogr r
a -> a -> a -> a -> a -> -> -> -> ->
m m m m m
m m ... | stackexchange_codegolf |
Background
K functions have a feature called projection, which is essentially partial application of values to a function. The syntax for projections is a natural extension of the regular function call syntax:
f[1;2;3] / call a ternary function f with three arguments 1, 2, 3
f[1;2;] / the third argument is missi... | stackexchange_codegolf |
One aspect of password strength testing is runs of adjacent letters on the keyboard. In this challenge, a program must be created that returns true if a string contains any runs of adjacent letters.
What counts as a run of adjacent letters?
For this simplified version of a password strength tester, a run of adjacent ch... | stackexchange_codegolf |
History
There's a room on StackOverflow in Russian where you can see such an interesting discussion:
Just because there are not enough real discussing in that room, @Grundy "plays ping-pong" to keep it unfrozen.
Task
Implement a bot for StackExchange that posts "ping!" to the 115624 room if the previous message was ... | stackexchange_codegolf |
Wren is a small, fast, class-based concurrent scripting language. Does anyone have any tips for this language?
Please make sure to post 1 tip per answer, and don't post answers like "remove whitespace".
| stackexchange_codegolf |
Write a program that counts up forever, starting from one.
Rules:
Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.
Your program must be a full, runnable program, and not a function or snippet.
Your program must output each number with a separating character in between (a newlin... | stackexchange_codegolf |
yes, from coreutils, is 91 lines long. Many of them are comments, but that is still WAY too long.
Edit from September 2019: the source file grew over the past five years and is now 126 lines long.
Write a program that imitates yes:
outputting to stdout an infinite stream of "y\n"'s
there must be an option to stop it o... | stackexchange_codegolf |
This is a challenge inspired by Chebyshev Rotation. I suggest looking at answers there to get inspiration for this challenge.
Given a point on the plane there is a unique square (a rectangle with equal sides) that is centered on the origin and intersects that point (interactive demo):
Given a point p and a distance d,... | stackexchange_codegolf |
Quines have been around forever. It's a fun challenge: write a program that, when executed, generates its own source code as output. But how do you know it's actually producing its own source code? Generally, you have to look at it and compare it, but with quines generally being composed of tricky and intricate code... | stackexchange_codegolf |
Your challenge is to output the number of twisted corners given a 2x2 Rubik's Cube scramble.
For the purpose of this challenge, twisted corners are defined as corners where the colour of the top/bottom face before (usually white or yellow) is not facing the top/bottom after the scramble.
Eg. if the cube were to be orie... | stackexchange_codegolf |
Introduction
If \$\newcommand{\fib}{\operatorname{fib}}\fib(x)\$ calculates the \$x\$th Fibonacci number, write a program that calculates \$\fib(\fib(m))\$ for any integer value of \$m \ge 0\$. (Of course, there will be practical limits based on the language, so lesser limits are acceptable. Also, it's okay to stop at ... | stackexchange_codegolf |
Note: This is the cops' thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer.
Task: Write the shortest safe program which multiplies the square root of an integer n by the square of n
This is cops-and-robbers, so the rule... | stackexchange_codegolf |
Bobby's booby-trapped safe requires an n-digit code to unlock it. Alex has a probe which can test combinations without typing them onto the safe. The probe responds Fail if no individual digit is the same as that in its corresponding position in Bobby's code. Otherwise it responds Close, including when all digits are c... | stackexchange_codegolf |
At 1998, Brian Kernighan, while working on the book "The Practice of Programming", wanted to demonstrate realisation of regular expression engine. But struggled to find small engine, that cod could fit in the book.
So Brian Kernighan asked Rob Pike to write one for him, and Rob did it gracefully. Here is original sourc... | stackexchange_codegolf |
Given a positive integer n, simplify the square root √n into the form a√b by extracting all square factors. The outputted a,b should be positive integers with n = a^2 * b with b as small as possible.
You may output a and b in either order in any reasonable format. You may not omit outputs of 1 as implicit.
The outputs... | stackexchange_codegolf |
Given a matrix like this:
1 1 3 -2
3 -4 1 -1
1 1 1 0
0 -1 0 0
By taking a 2×2 "sliding sum", where the sum of every 2×2 region of the matrix is one element of the resulting matrix, we get:
1 1 1
1 -1 1
1 1 1
We can do this for sliding windows of any size. For example, a 1×3 sliding sum of the same input ... | stackexchange_codegolf |
Write a program to generate a rectangular word-search of size 6x9. Words may go downwards, rightwards and diagonally (downwards and to the right), they may also overlap on the board.
The challenge is to include as many different English words as possible from https://www.ef.co.uk/english-resources/english-vocabulary/to... | stackexchange_codegolf |
Introduction
Factorials are one of the most frequently used examples to show how a programming language works.
A factorial, denoted \$n!\$, is \$1⋅2⋅3⋅…⋅(n-2)⋅(n-1)⋅n\$.
There is also the superfactorial (there are other definitions of this, but I chose this one because it looks more like the factorial), denoted \$n$\$,... | stackexchange_codegolf |
Commentscript is a variant on Javascript that I made up for the purpose of this question. Only commented-out code is evaluated.
Javascript has two types of comments:
// this is a single line comment, which starts with `//` and ends on a newline.
/*
This is a multiline comment.
It starts with /* and ends with */
Examp... | 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 |
Your boss managed to read the secret hidden message. He didn't end up firing you, though, he just made you a secretary and forbade you from writing code.
But you're a programmer. You need to write code. You must code.
Therefore, your code needs to look as similar to English as possible, make sense, and look as little l... | stackexchange_codegolf |
Introduction
A farmer needs help calculating the least time it will take him to pick his fruit each day.
Challenge
This farmer has X orchards.
Each orchard has Y fruits in it. If the orchard has no fruits, then it will contain the string "none".
The farmer has a list, this list contains the fruit he must pick.
The f... | stackexchange_codegolf |
Most square numbers have at least 1 different square number with which their Levenshtein distance is exactly 1. For a given square \$x\$, each square that meets this condition is called a Levenshtein neighbour of \$x\$. For example, \$36\$ is a Levenshtein neighbour of \$16\$, as only 1 edit (\$1 \to 3\$) is required. ... | stackexchange_codegolf |
Task
Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results.
The words in the list will be distinct and so should be the output.
You may assume that for given inputs a solution exists. If there is more than one, you may ou... | stackexchange_codegolf |
I was challenged by one of my friends to solve this coding problem:
Given a non-negative number represented as an array of digits, add one to the number. The digits are stored such that the most significant digit is at the head of the list. Return the value as a new list.
This was my solution, which does not work if [9... | stackexchange_codegolf |
NOTE: This challenge is currently dead, as I'm unable to install the languages needed to run a match. If someone else has the time and interest to do it, I'm not opposed.
See the bottom of the post for a leaderboard.
This is a semi-cooperative king-of-the-hill challenge, where the bots construct paths through a two-dim... | stackexchange_codegolf |
There's a payment machine for laundry in my building which does a few frustrating things. The ones relevant to this challenge are:
It doesn't make change. So if you pay over the amount then you are not getting that over-payment back.
It doesn't accept coins smaller than 20c. Meaning the only coins it accepts are 20c... | stackexchange_codegolf |
What general tips do you have for golfing in TypeScript's type system? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to TypeScript's type system (e.g. "remove comments" is not an answer).
Please post one tip per answer.
If you're not familiar with program... | stackexchange_codegolf |
A function is said to have a cycle of length n if there exists an x in its domain such that fn(x) = x and fm(x) ≠ x for 0 < m < n, where the superscript n denotes n-fold application of f. Note that a cycle of length 1 is a fixed point f(x) = x.
Your task is to implement a bijective function from the integers to themsel... | stackexchange_codegolf |
Challenge
Given a grid size, obstacles' positions, player position and target position your task is to find a path for the player to get to the target and avoid the obstacles at the same time (if necessary).
Input
N: Grid size N x N
P: Player's position [playerposx, playerposy]
T: Target's position [targetposx, targ... | stackexchange_codegolf |
Definition
An "integer triangle" is one with integer coordinates. For example the following triangle is an integer triangle:
(0, 0), (0, 1), (1, 2) with perimeter 1 + sqrt(2) + sqrt(5) ≈ 4.650.
Task
The goal of this challenge is to count all integer triangles (up to congruence) with perimeter less than n.
Input and Ou... | stackexchange_codegolf |
Background
The special linear group \$ SL_2(\mathbb{Z}) \$ is a multiplicative group of \$ 2 \times 2 \$ matrices whose elements are integers and determinant is 1.
It is known that every member of \$ SL_2(\mathbb{Z}) \$ is a product of some sequence of the following two matrices \$ S \$ and \$ T \$ (reference pdf):
$$
... | stackexchange_codegolf |
Traditionally when you compare two strings you use lexicographical comparison. That can be described by the recursive algorithm:
$$
f(x, y)=
\left\{\begin{array}[rr] \\
\mathrm{EQ} & \mathrm{if}\,\mid x\mid=0\,\mathrm{and}\,\mid y\mid=0 \\
\mathrm{GT} & \mathrm{if}\,\mid x\mid>0\,\mathrm{and}\,\mid y\mid=0 \\
\mathrm{L... | stackexchange_codegolf |
Lean is a theorem prover and programming language. It's also as of writing the Language of the Month!
What tips do people have for golfing in Lean? As always, tips should be specific to to Lean (e.g. "Remove comments" is not an answer), and stick to a single tip per answer.
| stackexchange_codegolf |
Description
Here's a very superstitious hotel elevator in Shanghai:
It avoids the number 13, because thirteen is unlucky in the Western world, and it avoids the digit 4, because four is unlucky in parts of Asia. What if this hotel was taller?
Read a positive even integer n from STDIN, representing the n... | stackexchange_codegolf |
Is there a way in Golfscript to bring all of the diagonals of an array into a single array?
For example, for the array
[[1 2 3][4 5 6][7 8 9]]
return
[[7][4 8][1 5 9][2 6][3]]
(not necessarily in that order) and for
["ABCD""EFGH""IJKL"]
return
["I""EJ""AFK""BGL""CH""D"]
(not necessarily in that order). Assume the l... | stackexchange_codegolf |
We already have a challenge for computing the GCD of two Gaussian integers, but that challenge explicitly allows to choose any of the four possible values.
Your task now is to bring the Gaussian integer computed by the GCD in the following normal form:
The result differs from the original number by a factor of 1,i,-1 ... | stackexchange_codegolf |
In the popular (and essential) computer science book, An Introduction to Formal Languages and Automata by Peter Linz, the following formal language is frequently stated:
$$\large{L=\{a^n b^n:n\in\mathbb{Z}^+\}}$$
mainly because this language can not be processed with finite-state automata.
This expression mean "Languag... | stackexchange_codegolf |
Given a ragged array, find the length of the largest subarray that contains the depth of that subarray. The base array layer has a depth of 0.
Here is an example:
[1, 2, [3, 4, [2, 5]], 0]
Here, the subarray [2, 5] contains its own depth 2 and has a length of 2 as well.
But in the outermost subarray is a 0, its depth.... | stackexchange_codegolf |
As we all know, limericks are short, five-line, occasionally-lewd poems with an AABBA rhyming scheme and an anapestic meter (whatever that is):
Writing a Limerick's absurd
Line one and line five rhyme in word
And just as you've reckoned
They rhyme with the second
The fourth line must rhyme with the third
You... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.