instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Suppose I have a linear inequality like
x0A0 + x1A1 + ... + xnAn <= C
with xi a non-zero positive integer and Ai and C a positive non-zero multiple of 0.01. Find all the positive integer n-tuples {x1,...,xn} such that:
D <= x0A0 + x1A1 + ... + xnAn <= C
where D is also a positive non-zero multiple of 0.01.
Challen... | stackexchange_codegolf |
Your task is simple, write a single code snippet that when executed in one language outputs only the string 'abc' and when executed in another language outputs only the string 'cba'. The program should take no input.
This is a code-golf challenge.
| stackexchange_codegolf |
Related: Rather similar (but much easier) challenge horizontally: There I fixed it (with tape)
Challenge:
Given a string only containing upper- and/or lowercase letters (whichever you prefer) and new-lines, put rope vertically to fix it. We do this by checking the difference of two adjacent letters in the alphabet (ign... | stackexchange_codegolf |
I want an n*n table that is filled with black or white and the following conditions are satisfied in it:
All cells of a 2*2 square in this table should not be the same color.
All black and white cells must be connected horizontally or vertically.
Acceptable examples:
Can anyone design a function that takes n as inpu... | stackexchange_codegolf |
For this challenge, a slice of a string is defined as an upper and lower index that can "cut" a piece of a string. All characters from the string in the range [start, end) (or [start, end] if you don't speak practlang) are part of that slice. If the upper index exceeds the string's length, the overflow is ignored. For ... | stackexchange_codegolf |
Given a list of integers find the "trajectory" that results from indefinitely moving the instructed steps to the right (left if negative), wrapping if necessary, starting at the first element.
A "trajectory", here, is defined as a list containing the elements that are visited only one time, in the order they are visite... | stackexchange_codegolf |
Note: the title was misspelled intentionally.
Given a string s, swap the first vowel runs of every 2 words. For this challenge, y is considered a vowel.
For example, given an input of "great day sir":
1. Input: "great day sir"
2. Identify pairs of words: "[great day] [sir]" (No word for sir to pair with)
3. Identify th... | stackexchange_codegolf |
MD5 checksums are relatively easy to crack. For this challenge you will create two separate programs, the first one writing Hello, World! and the second one writing Goodbye Cruel World! but with the source code having identical MD5 hashes.
The source code of both programs must not be identical.
The programs can use th... | stackexchange_codegolf |
Problem
You're a staircase engineer on a house and realize you only have n rectangles to create a staircase. So you are tasked with finding the number of ways to use n rectangles to tile a stairstep shape for the architects.
Your task is to write a program that takes a non-negative integer n as input and calculates the... | stackexchange_codegolf |
For our purposes, a trend is a contiguous subsequence of an array that falls into one of three categories:
increasing, e.g. [1,2,3,10,239]
decreasing, e.g. [8,5,0,-3,-50]
stable, e.g. [7,7,7,7]
Note that [1,1,2,3] is not a valid trend. It can be broken up into a stable trend [1,1] and an increasing trend [1,2,3]. In ... | stackexchange_codegolf |
A superior highly composite number is an integer where the ratio of its count of divisors to some power of the number is as high as possible. Expressing this as a formula:
Let d(n) be the number of divisors of n, including the number itself. For a given integer n, if there exists a number e such that d(n)/n^e is greate... | stackexchange_codegolf |
It's time for CGCC to demonstrate our musical talent! In this challenge, you're going to compose songs while keeping your byte count as small as possible.
On Day 0, multiple answerers will post a function or program that outputs nothing/an empty string. They will also give a single line that next day's answers must out... | stackexchange_codegolf |
So I was playing around with my compose key, and found some cool things, one of them being that by pressing compose + ( + alphanumeric + ), you get that character inside a bubble, like so: ⓐ.
Your task in this challenge is simple, to convert ordinary text to bubble letter text.
Here are the ascii chars, the bubble char... | stackexchange_codegolf |
I could not think of a better title.
This is a tips question. I'm asking for tips on golfing my code.
I recently took part in a code golf competition in C. The competition ended and I lost. The problem is:
Input a line with a number n.
Then input n lines, each line contains only a set of cards in descending order, e. ... | stackexchange_codegolf |
You need to produce the word codegolf
Rules:
None of the characters of the word codegolf (i.e. 'c', 'o', 'd', 'e', 'g', 'o', 'l' and 'f') in either case can exist anywhere in the code.
Case of the word must be one of three:
All Upcase (CODEGOLF)
All Downcase (codegolf)
Capitalized (Codegolf)
You only need to produ... | stackexchange_codegolf |
Inspired by this unassuming StackOverflow question.
The idea is simple; given a String and an array of Strings, remove any instances of words in the array (ignoring case) from the input String other than the first, along with any additional whitespace this may leave. The words must match entire words in the input Strin... | stackexchange_codegolf |
A string is dot-heavy when its morse representation contains more dots than dashes. For example, the letter E is a single dot, which means it is Dot-heavy.
Input
The input string will only contain characters in the range of [a-z] or [A-Z]. You can decide if they should all be upper case, or all lower case. AAA is fine... | stackexchange_codegolf |
In this fastest-code challenge, you are provided with a set of \$n\$ identical blocks and need to determine how many unique buildings can be constructed with them. Buildings must satisfy the following rules:
No overhangs - each block must either be on the ground or supported by one or more blocks directly underneath i... | stackexchange_codegolf |
Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the other, like such:
2 1
10 01
1 0
1001
0 1
0110
some examples:
Input
Binary
Conversion
Output
... | stackexchange_codegolf |
This is a pretty simple one. if the user enters "Hello World" your code should output "dlroW olleH"
I was inspired by the multiplication question recently posted. I know this is probably easy in bash.
As this is code-golf, least bytes wins.
| stackexchange_codegolf |
Or maybe it's not really a labyrinth, but still.
Rules:
Input is a two-line string, consisting of *, 1, x and X. That string is a labyrinth to walk through. The lines have the equal length.
You could take the input as a string with , (comma) or any convenient separator between these two lines. Or you could take both l... | stackexchange_codegolf |
You will be given a nested array. Your program has to visualize the array.
But.. How?
For example, let's assume we have a nested array, like [["1","2"],[["1","2"],"3"],"4",[[[["5"]]]],"6"].
This nested array can be visualised as:
->1
->2
-->1
-->2
->3
>4
---->5
>6
Examples
Input 1:
["Atom",["Proton",["Up Quark", "Up... | stackexchange_codegolf |
Doing my history reading and note-taking, I can't help but get tired of writing out all these long dates –– 1784 is six entire pencil lifts! jǝǝz!
As you can see, I –– like most challenge posters on this site –– am lazy when it comes to writing stuff. Thus, I ask you to please help me shorten some dates. Of course, you... | stackexchange_codegolf |
Task
Given an integer, n, where 3 <= n < 2^32, calculate the area of a regular n-gon, with an apothem of 1, using the formula A = n * tan(π / n).
The apothem of a regular polygon is a line segment from the center to the midpoint of one of its sides.
Output the area of this regular polygon as a floating point value sh... | stackexchange_codegolf |
I have 2 inputs: 1 single number and some numbers separated by whitespace:
1
1 2 3 4 5
I want to loop over the second input, and I don't need the first input. I did this, which works:
input()
for x in input().split():somecode()
But can I go directly to the second input without doing the input() at the beginning or wi... | stackexchange_codegolf |
Setup: For two sets \$A,B\$, we say \$A \subseteq B\$ if every element in \$A\$ is also in \$B\$.
Another way of saying this, is that we can order the elements of \$A,B\$ into two lists \$L_A,L_B\$, such that \$L_A[i] = L_B[i]\$ where \$i\$ ranges over the indices of \$L_A\$.
We proceed to extend this idea, to define ... | stackexchange_codegolf |
It's one of these again :D
Your task, if you wish to accept it, is to write a program/function (without any uppercase letters) that outputs/returns its string input/argument. The tricky part is that if I convert your source code to uppercase, the output must be reversed.
For simplicity, you can assume that the input is... | stackexchange_codegolf |
Coders are always trying to flatten arrays into boring 1-dimensional entities and it makes me sad.
Your task is to unflatten an arbitrary string of characters, outputting a lovely city skyscape.
Consider the string: aaabbbbbccqrrssstttttttPPw
It looks much better like this:
tt
tt
bb tt
... | stackexchange_codegolf |
Background
We all know about distributivity, i.e. \$a(b+c) = ab + ac\$. This is a property on 2 different operations, namely addition and multiplication. But indeed, nothing can stop us from studying distributivity of 1 operation. In this challenge, you will be studying a kind of left-distributive operation.
Task
Given... | stackexchange_codegolf |
For this challenge, a slice of a string is defined as an upper and lower index that can "cut" a piece of a string. All characters from the string in the range [start, end) (or [start, end] if you don't speak practlang) are part of that slice. If the upper index exceeds the string's length, the overflow is ignored. For ... | stackexchange_codegolf |
Given a string, consisting of a prefix and then "illion", convert this number into standard form.
For example:
"million" -> 10^6
"trillion" -> 10^12
"quattuordecillion" -> 10^45
The program needs to be able to handle input going up to Centillion, which is 10^303. A list of names and their standard form values can be ... | stackexchange_codegolf |
The bots are looking for love. Can you help them?
The rules
The goal of this game is find the bot you have the highest compatibility with. However, robots, who are inexperienced at dating are unable to tell how well a date went.
In the game, bots take turns "speed dating" some other bot. After each date, each bot choos... | stackexchange_codegolf |
Related: Multiply Quaternions
Challenge
Given a string made of ijk, interpret it as the product of imaginary units of quaternion and simplify it into one of the eight possible values 1, -1, i, -i, j, -j, k, -k.
The evaluation rules are as follows:
$$
ii = jj = kk = -1 \\
ij = k, \quad jk = i, \quad ki = j \\
ji = -k, \... | stackexchange_codegolf |
Your task is to create a program or function which randomly errors. Specifically, there must be a nonzero probability of erroring, but also a nonzero probability of running without error.
An error is anything that causes a program to terminate abnormally, such as dividing by zero or using an uninitialized variable. Thi... | stackexchange_codegolf |
You will be given a positive integer N as input. Your task is to build a Semi-Zigzag, of N sides, each of length N. Since it is relatively hard to clearly describe the task, here are some examples:
N = 1:
O
N = 2:
O
O O
N = 3:
O O
O O
O O O
N = 4:
O O O O O
O O
O O
O ... | stackexchange_codegolf |
Today we'll look at a sequence \$a\$, related to the Collatz function \$f\$:
$$f = \begin{cases}
n/2 & \text{if } n \equiv 0 \text{ (mod }2) \\
3n+1 & \text{if } n \equiv 1 \text{ (mod }2) \\
\end{cases}$$
We call a sequence of the form \$z, f(z), f(f(z)), …\$ a Collatz sequence.
The first number in our sequence, \$a(... | stackexchange_codegolf |
Challenge:
Given an integer \$n\$, guaranteed to be \$\geq2\$ and a power of 2, we are going to draw multiply boards either side-by-side or below one another, where the first has dimensions of \$n\$ by \$n\$; the second \$\frac{n}{2}\$ by \$\frac{n}{2}\$; the third \$\frac{n}{4}\$ by \$\frac{n}{4}\$; etc.; until the fi... | stackexchange_codegolf |
In this challenge you have to find out which nth second it is now in this year, current date and time now. Or in other words, how many seconds have passed since New Year.
An example current Date is (it's not given, you'll have to find the current Date):
March 5, 2021 1:42:44 AM
For which the answer is 5449364 (or opti... | stackexchange_codegolf |
Your task is to modify the original Plan 9 cat tool for UNIX, in order to make it a fully turing complete language interpreter. You may make use of ANSI escape codes and the backspace character (\x08) to aid in this.
You must submit:
A modified version of the Plan 9 cat tool
A hexdump of the turing machine that can be... | stackexchange_codegolf |
What is Crazyhouse Chess?
Crazyhouse Chess is a chess variant that is basically normal chess except you can place a piece you previously captured back on the board instead of a regular turn.
Bot interface
Only JavaScript bots are allowed.
A bot is a JavaScript function that takes 3 arguments (board, side, bank) and ret... | stackexchange_codegolf |
Mama Say Mama Sa Mama Coosa
I'm sure all of you have heard of Michael Jackson and some of you have listened to MJ's song "Wanna be starting something". The line "Mama Say Mama Sa Mama Coosa" is repeated throughout the song.
Specification
In this line, the word "Mama"occurs three times, "Say", "Sa", "Coosa" occurs once... | stackexchange_codegolf |
There are a few questions on this site about balancing brackets, and checking whether brackets are balanced. I propose it's now time to use those balanced brackets for something!
In mathematics and programming, brackets are like bubbles, isolating everything inside form everything outside so that whatever's inside can ... | 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 Minecraft, pistons are blocks that can move other blocks. However, they can only move at most twelve blocks, and won't work at all if any obsidian is in the way. Also, slime blocks are sticky and stick to other blocks, except for obsidian.
Your challenge
Take as input a 5x5 matrix or similar, containing one piston a... | stackexchange_codegolf |
Your task is to write a program or function that takes as input a list of positive integers and determines if there are any two integers in the list, that both appear the same number of times.
For example the list
[1, 2, 3, 2]
Has one 1 and one 3 so it satisfies the condition.
But the list
[3, 2, 2, 1, 2, 3]
does not... | stackexchange_codegolf |
Create a Pascal's Triangle that is a nested list and contains zeros in the unused spots.
In the output array, the numbers of Pascal's Triangle are separated by zeroes and padded by zeroes on each side so that they are centered. For example, the bottom row (last sub-array) must have no zeroes on the left and the right; ... | stackexchange_codegolf |
Introduction
A childhood game designed to help children learn to count in french in Canadian schools is played as follows:
Students go around the room counting up to 11
A number greater than 11 cannot be said
A student can say either 1, 2, or 3 numbers
If a student says the number 11 then they are removed from the nex... | stackexchange_codegolf |
This is a King of the Hill challenge in a round robin. It's a battle to find the best gunman of the west!
To be able to compete in this contest you need to make two functions. The first one sets the attributes of your gunman and the second is the main logic function for the gunman.
Attribute Function
function () {
... | stackexchange_codegolf |
Given two numbers, the first is greater than the second, check whether the first number is divisible by the second without a remainder. If divisible, answer "yes"(or any other string), otherwise "no"(or any other string you like).
Conditions: You cannot use conditional operators, loops, arrays, bitwise operations, func... | stackexchange_codegolf |
Intro
So I've been wasting my time again researching suffix sorting algorithms, evaluating new ideas by hand and in code. But I always struggle to remember the type of my suffixes! Can you tell me which type my suffixes are?
Left-most what?
A lot of suffix sorting algorithms (SAIS, KA, my own daware) group suffixes int... | stackexchange_codegolf |
Curling is a sport where two teams aim to place stones as close to the centre of a target as possible. The winner of a curling end is the team whose stone is closest to the centre – they score as many points as the number of their stones closer to the centre than any of their opponents.
Task
Given two lists of pairs of... | 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 |
A space cleaner is a special character which removes all spaces between it and the first non space character to its left and it is represented by a '!' character.
If it reaches the beginning of the string it stops.
Given a string output the string in any reasonable format after the cleaning process.
Trailing spaces at ... | stackexchange_codegolf |
Write a program or function that takes in a positive integer \$N\$ and a grid of decimal digits (\$0\$ to \$9\$) with width \$W\$ and height \$H\$ (which are also positive integers). You can assume that \$N\$ will be less than or equal to the larger of \$W\$ and \$H\$ (\$N \le \max(W,H)\$).
Print or return the largest ... | stackexchange_codegolf |
You are given a list, L, with the length N. L contains N random positive integer values. You are only able to select from the outer edges of the list (left/right), and after each selection every value in the remaining list increase by a factor of the current selection. The goal is to maximize the total sum of the selec... | stackexchange_codegolf |
Write an indefinitely-running program that reports how many instances of itself are currently running. Each instance of the program should also report the order in which it was opened out of all other currently-running instances.
Example
The user launches the program for the first time - we'll call this Instance 1. Ins... | stackexchange_codegolf |
Using only printable ASCII (hex codes 20 to 7E), write a square N×N core program without comments that is surrounded by 4 more layers, creating a (N+8)×(N+8) square program (N > 0). For N = 3 the layout (to be replaced by actual code) looks like this:
44444444444
43333333334
43222222234
43211111234
4321CCC1234
4321CCC1... | stackexchange_codegolf |
Your challenge, should you choose to accept it, is to write a program in a language of your choice that, when given a string (limited to printable ASCII) as input, outputs a new program in the same language that outputs that string without using any characters from that string in the code.
But this task is impossible a... | stackexchange_codegolf |
Task
Given two positive integers \$m,n\$, imagine a chessboard of size \$m \times n\$. A chess queen is on the upper-left corner. In how many ways can it reach the lower-right corner, by moving only right, down, or diagonally right-down (possibly moving many steps at once, because it's a queen)?
The resulting 2D sequen... | stackexchange_codegolf |
Background
Two numbers, \$a\$ and \$b\$, are said to be connected by a Brussels choice operation* if \$b\$ can be reached from \$a\$ by doubling or halving (if even) a substring (the substring must not be empty and may not contain any leading 0s but it can be 0) in the base-10 representation of \$a\$
*This operation is... | stackexchange_codegolf |
This is a cops and robbers challenge - Cop's Thread
Each of the cops have been tasked to write a program that terminates after exactly 60 seconds, or as close as possible. For example:
#include <unistd.h>
int main(int argc, char **argv){
sleep(60);
return 0;
}
Your goal is to take any of the uncracked submissi... | stackexchange_codegolf |
Write a program which can encode text to avoid reusing characters, and convert back.
Both normal and encoded forms are restricted to a particular character set: the space character with code point 32, the tilde character ~ with code point 126, and all characters between. This is 95 total characters. It's a printable s... | stackexchange_codegolf |
Let's define a pristine program as a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of \$N\$ characters, where \$1 \le N < \text{program length}\$.
For example, the three character Python 2 program
`8`
is a pristine program (thanks, Sp) because all the... | stackexchange_codegolf |
The Ackermann function is notable for being the one of the simplest examples of a total, computable function that isn't primitive recursive.
We will use the definition of \$A(m,n)\$ taking in two nonnegative integers where
$$\begin{align}
A(0,n) & = n+1 \\
A(m,0) & = A(m-1,1) \\
A(m,n) & = A(m-1,A(m,n-1))
\end{align}$$... | stackexchange_codegolf |
Write an interactive program or function which allows the user to play The Coinflip Game! The object of the game is to repeatedly flip a coin until you get the same result \$n\$ times in a row.
Specific behavior of the program/function is as follows:
At the start of the game, the user inputs a positive integer \$n>1\$... | stackexchange_codegolf |
Definition (from Wikipedia)
A Pythagorean triple consists of three positive integers a, b, and c, such that a² + b² = c².
The typical example of a Pythagorean triple is (3,4,5): 3² + 4² = 9 + 16 = 25 which is 5²
Task:
Given an integer number c, write a program or function that returns the list of pythagorean triples wh... | stackexchange_codegolf |
The other day, our team went to an escape room. One of the puzzles involved a board of six mechanical switches where you had to find the correct combination of on and off in order to unlock a box, somewhat like this:
-v-v-v-
-v-v-v-
Being developers, we decided it would be more efficient to try every single one of 2^6... | stackexchange_codegolf |
A ragged list is a (finite depth) list where each element is either a positive integer or a ragged list.
A ragged list is properly tiered if it contains either all positive integers or all properly tiered ragged lists.
For example [1,2,3,6] is properly tiered because it is a list of only positive integers. [[1,2],[[1]... | stackexchange_codegolf |
Supreme Sum String
Given an input string, return the word with the highest sum of each of its unicode characters.
Rules
The input should be seperated by whitespace
The value of each word is based on the sum of each character in the word's UTF-16 code
The output should be the first word with the highest value (in case... | stackexchange_codegolf |
The following data contains the (approximate) population of each UTC timezone in the world (source):
UTC;Population (in thousands)
-11;57
-10;1853
-9.5;8
-9;639
-8;66121
-7;41542
-6;272974
-5;332101
-4.5;31923
-4;77707
-3.5;499
-3;248013
-2;4855
-1;3285
0;285534
+1;857443
+2;609921
+3;496279
+3.5;81889
+4;129089
+4.5;3... | stackexchange_codegolf |
Related.
Given a positive integer \$n\$, output all integers \$b\$ (such that \$1<b<n-1\$) where \$n\$ can be written as the sum of any number of consecutive powers of \$b\$.
Example:
Let's say \$n=39\$.
\$3^1+3^2+3^3\$
\$= 3 + 9 + 27\$
\$= 39\$
This does not work for any other \$b\$, so our output is [3].
Test cases... | stackexchange_codegolf |
The string tut-tutut-tut-tuttut-tut can be constructed with overlapping or concatenated instances of the word tut-tut:
tut-tutut-tut-tuttut-tut
tut-tut
tut-tut
tut-tut
tut-tut
The string tut-tututut-tutut-tut cannot:
tut-tututut-tutut-tut
tut-tut^
|tut-tut
| tut-tut
... | stackexchange_codegolf |
What general tips do you have for golfing in Go? I'm new to Code Golfing and looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Go.
Please keep to one tip per answer.
| stackexchange_codegolf |
plorcly borglar is a "mod" created by jan Misali for the constructed language toki pona that makes words sound funny.
It involves substituting the 14 toki pona letters for funnier versions plus 2 extra rules. The substitutions are:
toki pona letter
plorcly borglar letter
m
bl
n
gl
p
b
t
pl
k
cl
s
scr... | stackexchange_codegolf |
Programming is very rigid. You can't tell a program to "output the banana count", you have to tell it to print(bananas).
But when you do that, you end up with a problem: you don't know how many bananas you have beforehand, so you don't know whether to use a plural.
Sometimes, programmers go the lazy way. Instead of che... | stackexchange_codegolf |
Rules
No cell range references (A2:B3).
Maximum 9 rows and 9 columns.
No circular references or formula errors.
Empty cells evaluate to 0.
Data are numbers only, but may be taken as strings.
Formulas are strings.
Implementation choices
You must state your choices in these matters:
Require formulas to be prefix... | stackexchange_codegolf |
In this challenge, you'll print out the SBCS of Jelly, a popular golfing language. Its code page looks like this:
_0
_1
_2
_3
_4
_5
_6
_7
_8
_9
_A
_B
_C
_D
_E
_F
0_
¡
¢
£
¤
¥
¦
©
¬
®
µ
½
¿
€
Æ
Ç
Ð
1_
Ñ
×
Ø
Œ
Þ
ß
æ
ç
ð
ı
ȷ
ñ
÷
ø
œ
þ
2_
!
"
#
$
%
&
'
(
)
*
+
,
-
.
/
3_
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
4... | stackexchange_codegolf |
Disclaimer
It is bad practice to draw out your molecules in 2 dimensions because that is not how they are. I chose to do this in 2D because it is easier to explain.
Note that the bond angles are wrong too: the angle in CH4 is 109.5°, not 90° as I said and the bond angle in NH4 is 107°. BHCl2 does have a bond angle of ... | stackexchange_codegolf |
Task
You will be given a set of circles in the plane with their centers on the line y=0. It is guaranteed that no pair of circles has more than one common point.
Your task is to determine into how many regions into which the circles divide the plane. A region is an inclusion-maximal contiguous set of points not interse... | stackexchange_codegolf |
Given a number, find an expression in words equaling that number, with a length of that number.
Thus, to an input of 15, you might output sixteen minus one, which has fifteen characters (not counting spaces). If multiple solutions exist, print whichever you want. If none exist, print impossible
Use only the operators p... | stackexchange_codegolf |
Given \$ i = \sqrt{-1} \$, a base-\$ (i - 1) \$ binary number \$ N \$ with \$ n \$ binary digits from \$ d_{0} \$ to \$ d_{n - 1} \$ satisfies the following equation.
$$ N = d_{n - 1} (i - 1) ^ {n - 1} + d_{n - 2} (i - 1) ^ {n - 2} + \cdots + d_{1} (i - 1) + d_{0} $$
For example, a decimal number \$ 15 \$ is \$ 1000111... | stackexchange_codegolf |
Consider a sorted array of positive floating point numbers such as:
input = [0.22, 2.88, 6.35, 7.17, 9.15]
For each integer \$i\$ from 1 up to the last value in input rounded up, output the mean of all values less than \$i\$.
In this case the output should be:
[0.22 0.22 1.55 1.55 1.55 1.55 3.15 4.155 4.155 5.154 ]
I... | 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 |
In crossword terminology, the grid is the region into which the crossword answers are inserted, consisting of white and black squares. The crossword answers, called entries, are inserted into contiguous sequences of white squares in a row or column, separated by black squares.
For straight (American) crosswords, the g... | stackexchange_codegolf |
The round function in Python 3 will round values of the form \$k+\frac{1}{2}\$ (with \$k\$ being an integer) to the nearest even integer, which is apparently better than the rounding method taught in school
Your task is to recreate this functionality: write a program of function that given a (real) number as input, out... | stackexchange_codegolf |
Today we're going to build a pyramid out of letters! Here's an example letter pyramid for the first 5 letters:
Write the first 5 letters with a space between, first ascending and then descending.
A B C D E D C B A
Do the same thing for the first four letters on the line above, but with two extra leading spaces:
A B... | stackexchange_codegolf |
The Euclidean algorithm is a widely known algorithm for calculating the greatest common divisor (GCD) of two positive integers.
The algorithm
For the purpose of this challenge, the algorithm is described as below:
Display the two input as adjacent lines of a certain character
e.g. an input of 3,4 can be represented by... | stackexchange_codegolf |
I've been developing some programs involving me fetching a vector from a url using Alpha-2 country codes (such as GET /jp.svg for Japan). Except, oh no! All the country data on my computer uses Alpha-3! That just won't do...The task is simple: Take an Alpha-3 country code (e.g. UKR) and return its Alpha-2 equivalent (... | stackexchange_codegolf |
We define \$a(n)\$ as the 1-indexed position of \$n\$ in the sequence of positive integers with the same binary weight, i.e. the same number of 1's in their binary representation. This is A263017.
Given a positive integer \$n\$, your task is to determine how many positive integers \$k\$ satisfy:
$$k-a(k)=n$$
For instan... | 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 |
Modern regular expressions (regexes) have many features (\d, {n,m}, \1, etc.), but to define a regular language (modern regexes can define broader classes of languages, in their defense), all you need are three operators: concatenation (+), union (|), and the Kleene star (*). Here are some examples:
a - Matches the str... | stackexchange_codegolf |
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 |
Given no input, your task is to generate the following:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
... | stackexchange_codegolf |
A "rhyme scheme" is a string of letters a to z, such that the first occurrences of the characters are in ascending order (without gaps), starting from a. For example (with first occurrences marked):
abccdbebdcfa
^^^ ^ ^ ^
The number of rhyme schemes of length N is given by the Bell numbers B(N). (OEIS A000110)
The C... | stackexchange_codegolf |
If elected president, Donald Trump plans to implement a system of four income tax brackets (full details can be found on his website here). Your job is to take two inputs, annual income and filing status (single, married, or head of household), and output the income tax that must be paid.
Income Tax Brackets
(We are o... | stackexchange_codegolf |
Consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. We are interested in computing the exact expected minimum Hamming distance between any pair. The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.... | stackexchange_codegolf |
Introduction
Every string has an "alphabet", composed of the characters that make it up. For example, the alphabet of \$abcaabbcc\$ is \${a, b,c}\$. There are two operations you can do with alphabets: getting the alphabet of a string, and seeing if another string has a given alphabet.
Challenge
Given two strings, you m... | stackexchange_codegolf |
Consider the following alphabetically sorted list of words:
balderdash
ballet
balloonfish
balloonist
ballot
brooding
broom
All of the words start with b, and the first 5 start with bal. If we just look at the first 2 words:
balderdash
ballet
we could write instead:
balderdash
+let
where the ' ' is used where a wor... | stackexchange_codegolf |
Dennis puts in a huge amount of effort for this community, including as moderator, language designer, and provider of TIO.
Unfortunately, his four-year-old daughter has caught a cold, so let us all help him keep track of her recovery (may it be speedy) by providing him with a thermometer:
.-----------.
| |
| ... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.