instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
I came across this picture the other day: (Credit to Josep M Batlle I Ferrer)
Your job is to generate this picture. This graph is generated by repeatedly applying newton's method to the graph of:
$$f(x)=\cosh(x)-1$$
In other words, repeatedly apply the following function to every point till the rectangular distance is... | stackexchange_codegolf |
Background
On a Rubik's cube there are 54 moves that you can execute, for example, turn the right face anti-clockwise, or rotate the top face and the horizontal slice twice. To notate any move, each face (or slice) has a letter assigned to it. To move that face clockwise once, you just write the letter on its own, so f... | stackexchange_codegolf |
Write a program that converts a mathematical expression to words, evaluates the expression, and prints how the equation would be spoken aloud.
Input
The input must only contain numbers and the symbols +, -, *, and /. There cannot be any whitespace in the input.
The input does not say what the expression is equal to.
... | stackexchange_codegolf |
For a given positive integer, try to find out the smallest possible rotation resulted by rotating it 0 or more bits.
For example, when the given number is 177, whose binary representation is \$10110001_{(2)}\$:
\$ 10110001_{(2)}=177 \$
\$ 01100011_{(2)}=99 \$
\$ 11000110_{(2)}=198 \$
\$ 10001101_{(2)}=141 \$
\$ 00011... | stackexchange_codegolf |
I feel tired to do "find the pattern" exercise such as
1 2 3 4 (5)
1 2 4 8 (16)
1 2 3 5 8 (13)
Please write a program that finds the pattern for me.
Here, we define the pattern as a recurrence relation that fits the given input, with the smallest score. If there are multiple answers with the same smallest score, using... | stackexchange_codegolf |
Create a function which given a number of lines n, makes a bigA.
The horizontal bar of bigA must be at the middle row, or the lower of the two if n is even
Assume a monospace font for output
Output should be a string (or similar, eg character array) with clear linebreaks to break up the lines, and with correct whites... | stackexchange_codegolf |
Introduction
According to the Riemann Hypothesis, all zeroes of the Riemann zeta function are either negative even integers (called trivial zeroes) or complex numbers of the form 1/2 ± i*t for some real t value (called non-trivial zeroes). For this challenge, we will be considering only the non-trivial zeroes whose ima... | stackexchange_codegolf |
Inspired by Greg Martin's "Shiny cryptarithm" puzzle.
A cryptarithm is a game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters of the alphabet. The goal is to identify the value of each letter. They are usually represented by an addition operation, such as SEND + MORE... | stackexchange_codegolf |
We will say a string \$x\$ is cyclic maximal if there is no way to cycle its elements to get a lexicographically larger string. In other words there is no \$a\$ and \$b\$ such that \$a \oplus b = x\$ and \$b \oplus a > x\$, where \$\oplus\$ is concatenation.
For example [3,2,3,3] is not cyclic maximal because you can c... | stackexchange_codegolf |
Sandbox Post
Intro
The information panels are everywhere. When the technology became cheaper, the paper posters were transformed into luminous signs that show words that appear on one side and come out on the other, like the one on the figure:
When one of these signs starts up, it usually starts empty and the text lea... | stackexchange_codegolf |
Given a nonempty list of nonnegative integers, consider rewriting it as an arithmetic problem where:
A plus sign (+) is inserted between pairs of numbers that increase from left to right (a.k.a. from the start of the list to the end).
A minus sign (-) is inserted between pairs of numbers that decrease from left to rig... | 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 |
Since I want to celebrate this definitely not nerdy event, your job is to calculate the piversary (pi-anniversary) of a given date.
Input
Your code has to have a possibilty to input a date in the format DD/MM/YYYY. You can expect, that the input is valid and the year is 0000<YYYY<9996.
Output
You have to release two da... | stackexchange_codegolf |
And then the King said: You fought bravely, Knight, and your deed will not be forgotten for centuries. For your valor I grant you this castle and the lands around it. Things rush me, and I can not take you to the castle. Therefore, I will give you the way from this place to the castle. Now go and come back after the de... | stackexchange_codegolf |
Challenge
Given an integer greater or equal to 4, n, print a rounded rectangle of as close as possible (with a gap of 1) sides and a perimeter of n characters.
Rules
n is always 4 or greater, because otherwise the output wouldn't be a square
The characters for the perimeter can be any non-whitespace character
The rect... | 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
Ah, INTERCAL...
As much as I'd like encourage everyone to Try it Online, text output is just painful.
According to the docs it uses the "Turing Text Model".
While an... interesting concept, using it is about as much fun as shooting yourself in the foot.
And what do we do with a task like this? Automate it.... | stackexchange_codegolf |
I like golfing in tinylisp:
(d M(q((x)(i x(i(disp x)0(M x))0
But I also like posting explanations with nicely formatted code:
(d M
(q
((x)
(i x
(i (disp x) 0 (M x))
0))))
Can you help me generate the ungolfed code for my explanations?
The task
Given a line of tinylisp code, return or output the same cod... | stackexchange_codegolf |
Background
Scrabble is a word game in which players collaboratively build a board consisting of letter tiles that spell words. Each word must be connected to another word, and players gain points based on the letters they use and where they are placed. Words can be spelled either from left-to-right or top-to-bottom, an... | stackexchange_codegolf |
Preamble
There was a unit test in our codebase which was shuffling a string of length \$52\$ formed from the set of letters \$[A-Z]+[A-Z]\$ and then using the first \$20\$ characters of that shuffled string.
It failed quite a while after being written due to no repeated character being present in those twenty and we wo... | stackexchange_codegolf |
Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries at those same positions of the pattern.
For example, the input
s = [-5, 9, 4, 13, 11, -6, 0]
p = [7, -4, 1, -8, 4, -3, ... | stackexchange_codegolf |
Challenge:
Write a program that produces the following output:
. E .. I ... S .... H
...- V
..- U ..-. F
..--
.- A .-. R .-.. L
.-.-
.-- W .--. P
.--- J
- T -. N -.. D -... B
... | stackexchange_codegolf |
The input message consists of ASCII characters
The encoded output message consists of blocks of 0
A block is separated from another block by a space
Two consecutive blocks are used to produce a series of same value bits (only 1s or 0s):
After the ACSII character(s) have been converted to binary, go through the string:
... | stackexchange_codegolf |
EDIT: The incorrect A rhomb substitution has been fixed. Apologies to anoyone who had started working on a solution.
Consider the following substitutions, where the substituted rhomb(us) is scaled up and shown in red:
EDIT: Note the anchor points (circle) created where a corner of each new rhomb touches the substituted... | stackexchange_codegolf |
Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable),
defined by p(k) ∝ k.
E.g. if n = 3, then p(1) = 1/6, p(2) = 2/6, and p(3) = 3/6.
Your code should take constant expected time, but you are allowed to ignore o... | stackexchange_codegolf |
Introduction
I have some ASCII cars that have velocity and direction. Their velocity is represented by their number. If a car is <> then it has stopped. For example:
<>
1>
2>
3>
After one second, I get
<>
1>
2>
3>
After two, I get
<>
1>
2>
3>
If two cars are too close, they crash.
1> <1
1> <2
Afte... | stackexchange_codegolf |
Input
A string S of length between 2 and 30. The only letters in the string will be a or b.
Output
All strings within Levenshtein distance 2 of S. You must output all the strings without duplicates but in any order you like.
Example
If S = aaa then the output would be (in any order):
aa
abab
ab
aabba
aaaa
abaa
bbaaa
ab... | stackexchange_codegolf |
Background
The monkeys need help organizing their defense and have asked you, Benjamin the code monkey, to create a program that will list all tower upgrade options. Each tower has three unique upgrade "paths", each having a tier represented by a number between 0 and 5 inclusive, 0 meaning no upgrade. Up to two paths m... | stackexchange_codegolf |
You are the first engineer in a hot new startup, Lexographical. Our company is making waves by digitizing and indexing all words, real or not. The core of our product... Our secret sauce... Well, that's why we hired you :)
Because we're bleeding edge, we're enforcing the latest standards. Even the latest ones aren't go... | stackexchange_codegolf |
Let \$\sigma(n)\$ represent the divisor sum of \$n\$ and \$\sigma^m(n)\$ represent the repeated application of the divisor function \$m\$ times.
Perfect numbers are numbers whose divisor sum equals their double or \$\sigma(n) = 2n\$. For example, \$\sigma(6) = 12 = 2\times6\$
Superperfect numbers are numbers whose twic... | stackexchange_codegolf |
You are given a string, which will contain ordinary a-z characters. (You can assume this will always be the case in any test, and assume that all letters will be lowercase as well). You must determine how many unique combinations can be made of the individual characters in the string, and print that number.
However... | stackexchange_codegolf |
The system
Assume the Earth is flat and that it extends infinitely in all directions. Now assume we have one infinitely long train railway and n trains in that railway. All trains have different speeds and all trains are going in the same direction. When a faster train reaches a slower train, the two trains connect (be... | stackexchange_codegolf |
So simple: Provide some code that outputs foo and with the reversed source outputs bar. But before you come up with something like this boring python 2:
print "foo"#"rab" tnirp
you should know the score: You multiply the number of bytes with (1 + dead bytes), where dead bytes are bytes that can be changed to most othe... | stackexchange_codegolf |
Your challenge is to take an array of strings and output the longest string in the array. So for
["tiny", "small", "bigger", "biggest"]
the output would be biggest.
If two elements of the array have the same length, you should choose the one that appears first in the array. That means if the array looks like this:
["o... | stackexchange_codegolf |
Write a program that outputs the number 0.
That's a bit trivial, isn't it?
Let the length of your program be \$S\$. Write a program that outputs the number 0. When your program is cyclically shifted \$i < S\$ bytes left, it should output \$i\$. To cyclically shift a string \$i\$ bytes left means to move the last \$i\$ ... | stackexchange_codegolf |
You have two values each of which is either 0 representing "unknown", or one of 1,2,3. Merge them into a single value as follows:
If both values are nonzero and equal, output that value:
(3,3) -> 3
If both values are nonzero but unequal, output 0 for unknown:
(1,2) -> 0
If one value is zero and the other is not, outpu... | stackexchange_codegolf |
Introduction
In this challenge your task is to generate the ISBN-10 code for books given its ISBN-13 code, assuming that such a code exists. Such an ISBN-13 code consists of several parts separated by -:
978-GG-PPPP-TTT-C
The letters G (group), P (publisher), T (title) and C (checksum) all stand for one digit. For the... | stackexchange_codegolf |
Expand a number
Your task is to expand an integer greater than 0 in the following manner:
Split the number into decimal digits and for each digit generate a list according to these rules:
if the digit is odd, the list starts with the digit and goes down to 1;
if the digit is even, the list starts with the digit and go... | stackexchange_codegolf |
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
X coordinate
Y coordinate
String
How?
We know that a Cartesian plane contain 2 axes \$(X, Y)\$ and 4 quadrants where the signs of the \... | stackexchange_codegolf |
With roughly one second (plus or minus 10 ms) between outputs, output anything.
The first output must be at most one second after the start of the program, but can be as soon as right when the program starts.
So, the first output can be up to a second after the program starts, the second exactly one second after that, ... | stackexchange_codegolf |
You've inherited a server that runs several apps which all output to the same log.
Your task is to de-interleave the lines of the log file by source. Fortunately, each line begins with a tag that indicates which app it is from.
Logs
Each line will look something like this:
[app_name] Something horrible happened!
App ... | stackexchange_codegolf |
With this challenge we pay homage to everyone around the whole world fighting against the coronavirus crisis; particularly represented are the people tied to medicine, as the Rod of Asclepius is a symbol associated with medicine and health care.
For that matter, we resort to some ASCII art found at asciiart.eu (wrongfu... | stackexchange_codegolf |
Task
Given integers x and y which are both at least 2, find the smallest positive number whose y-th power is divisible by x.
Example
Given x=96 and y=2, the output should be 24 since 24 is the smallest positive n satisfying n^2 is divisible by 96.
Testcases
x y output
26 2 26
96 2 24
32 3 4
64 9 2
27 3 3
Scoring
This... | stackexchange_codegolf |
Pyth is perhaps the most successful general-purpose golfing language. Though it is somewhat in decline as a result of newer languages, from 2014 to 2016 Pyth's concise syntax, constant updates, overloading, and (for its era) many builtins made it a favorite for the majority of questions.
Pyth code is often difficult to... | stackexchange_codegolf |
A triangular number is a number that can be expressed as the sum of consecutive positive integers, starting at 1. They can also be expressed with the formula n(n + 1) / 2, where n is some positive integer.
A number's digitangular counterpart is calculated in the following way:
Split a number into an array of its digit... | stackexchange_codegolf |
This challenge is about writing code to solve the following problem.
Given two strings A and B, your code should output the start and end indices of a substring of A with the following properties.
The substring of A should also match some substring of B.
There should be no longer substring of A that satisfies the firs... | stackexchange_codegolf |
In calculus, the derivative of a mathematical function defines the rate at which it changes. The derivative of a function f(x) can be marked as f'(x), and these can sometimes be abbreviated to f and f'.
The derivative of the product of two functions fg is f'g + g'f. The derivative of three fgh is f'gh + fg'h + fgh'. In... | stackexchange_codegolf |
I'm currently scanning a bunch of handwritten documents and converting them to .txt files. Since I have a terrible handwriting the .jpg->.txt converter converts some of my umlauts to the "normal" letter encased by '
Task
Write a program or a function that:
Is given a string
you can choose any I/O codepage as long as
... | stackexchange_codegolf |
In Conway's Game of Life, there is an infinite square grid of cells, each of which is alive or dead. The pattern changes each "generation". A dead cell with exactly 3 live neighbors (orthogonal or diagonal) becomes a live cell. A live cell only lives to the next generation if it has 2 or 3 live neighbors. These simple ... | stackexchange_codegolf |
Do randomly generated drum loops sound good?
A drum loop is a \$5\times 32\$ matrix \$A\$ of \$1\$s and \$0\$s such that
\$A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1\$,
for each \$i\$, the \$i\$th row has exactly \$f(i)\$ different \$1\$s, where \$ f(1)=3, f(2)=2, f(3)=6, f(4)=8, f(5)=5\$,
for each \$j\equiv 1\bmod 4\$, the ... | stackexchange_codegolf |
Here's a very simple little problem that I don't believe has been asked before.
Challenge
Write a program or a function that takes in four positive integers that represents the lengths of movable but unbreakable and unbendable straight fences. Output the area of the largest rectangular yard that can be fully encompasse... | stackexchange_codegolf |
Codidact post, CGCC Sandbox, Codidact Sandbox
Given three positive integers as input, animate an ascii-art polygonal loading symbol on the screen.
Intro
You will be given three inputs, \$n\$, \$l\$, and \$d\$...
\$n\$ (one of \$3\$, \$4\$, \$6\$, or \$8\$), is the number of sides of a polygon:
... | stackexchange_codegolf |
The natural numbers including 0 are formally defined as sets, in the following way:
Number 0 is defined as the empty set, {}
For n ≥ 0, number n+1 is defined as n ∪ {n}.
As a consequence, n = {0, 1, ..., n-1}.
The first numbers, defined by this procedure, are:
0 = {}
1 = {{}}
2 = {{}, {{}}}
3 = {{}, {{}}, {{}, {{}}}... | stackexchange_codegolf |
Challenge inspiration was this that I saw somewhere:
The word "nun" is just the letter n doing a cartwheel
Your challenge is to take a string and determine if it is the first letter doing a cartwheel.
Rules
A string is a letter doing a cartwheel if:
The first letter is the same as the last letter. (The letter can't ... | stackexchange_codegolf |
Does anyone have any suggestions as to how I could shorten this program?
_=map(ord,raw_input());_=[10if y==88else 0if y==45else 58-_[x-1]if y==47else y-48for x,y in enumerate(_)];t=0;exec('t+=sum(_[:2+(_[0]+_[1]>=10)]);_=_[2-(_[0]==10):];'*10);print t
Run it online
I'd like to write a bowling calculator. I'm fairly pr... | stackexchange_codegolf |
Miller-Rabin test
Given a base \$b\$ and an odd number \$n\$:
Write \$n\$ as \$2^{s}\times d + 1\$ where \$d\$ is odd
\$n\$ is a strong probable prime if either:
\$b^d\equiv 1 \pmod n\$
\$b^{d\cdot2^r}\equiv -1 \pmod n\$
for any non-negative \$r\$ strictly less than \$s\$.
A strong probable prime which is composite ... | stackexchange_codegolf |
Introduction
Inspired by Dyalog Ltd.'s 2016 student competition. The challenge there is to write good APL code, but this is a code-golf and it is open to all languages. Derived from this closed challenge.
The real challenge here is to combine the various (quite trivial) parts of the problem in a byte-efficient way by r... | stackexchange_codegolf |
Introduction
Let's observe the following string:
AABBCCDDEFFGG
You can see that every letter has been duplicated, except for the letter E. That means that the letter E has been de-duplicated. So, the only thing we need to do here is to reverse that process, which gives us the following un-de-duplicated string:
AABBCCD... | stackexchange_codegolf |
Briefing
You are a bot, in a 2D grid that extends infinitely in all four directions, north, south, east and west. When given a number, you must move the bot so that you get to the target number.
Here's how the grid works:
You can move in 4 directions: north, south, east or west. Once you move off a cell, you are not al... | stackexchange_codegolf |
Consider this nested array
[[1,2,4],[1,2,3],[2,3]]
In each subarray in which 1 appears, a 2 appears. You might say that 1's presence is dependent on 2's presence.
The converse is not true, as 2 appears in a subarray without 1.
Additionally, 3 is dependent on 2, and 4 is dependent on 1 and 2.
Task
Given a list of lists ... | 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 |
This code golf challenge is about making a rocket liftoff sequence.
Your output (STDOUT) should be equal to this:
Liftoff in T-10
Liftoff in T-9
Liftoff in T-8
Liftoff in T-7
Liftoff in T-6
Liftoff in T-5
Liftoff in T-4
Liftoff in T-3
Liftoff in T-2
Liftoff in T-1
LIFTOFF!
Rules:
Your output must print to STDOUT.
Yo... | stackexchange_codegolf |
The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism!
The Challenge
When people use the term "average," they generally mean the arithmetic mean, which is the sum of the numbers divided by the number of numbers. There are, however, many ... | stackexchange_codegolf |
A field in mathematics is a set of numbers, with addition and multiplication operations defined on it, such that they satisfy certain axioms (described in Wikipedia; see also below).
A finite field can have pn elements, where p is a prime number, and n is a natural number. In this challenge, let's take p = 2 and n = 8,... | stackexchange_codegolf |
When I saw this title in the Hot Network Questions I thought it was going to be a PPCG challenge. I was a little disappointed when it was on Mathematica.
So now it is on PPCG:
Challenge
Given an input string, output the ROT13, flipped value. The input will contain characters from the following alphabet: [abcdefghijklmn... | stackexchange_codegolf |
Write a function that calculates a row of the pascal triangle and returns the middle number, if there are 2 it should return their sum.
Example:
5
would return
20
Example 2:
4
would return
6
EDIT:
To be clear:
a) if the number inputted is odd then find then return the middle number of a row on the pascal triangle.
... | stackexchange_codegolf |
Given two points A and B, find the angle from line AO to line BO about point O where O is the origin ((0,0)). Additionally, the angle may be positive or negative depending on the positions of the points (see examples). Input will be points A and B, and may be given in any convenient form. Output will be the angle in de... | stackexchange_codegolf |
Given a PPCG user's user ID, calculate how much times is their Each SE site reputation is from average reputation in the Stack exchange sites they have made accounts.
Let me explain, If someone's total network reputation (Total reputation in the stack exchange sites he has participated) is 10k, and if he has participat... | stackexchange_codegolf |
I like anagrams. I like programs that reference their own source code. So this challenge combines them!
Input.
The input to the program could be anything, including letters, numbers, symbols, you name it.
Output.
A truthy value if the input's characters can be rearranged to give the source code, and a falsy value if th... | stackexchange_codegolf |
Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro.
I am an evil farmer, and to drive up the price of wheat in my area, I've decided to burn the fields of all the farmers around me. I would really like to see the fields go up in flames (... | stackexchange_codegolf |
Create a program (any language) which, given positive integer m, outputs a valid C expression that:
Uses a single variable x assumed of 32-bit unsigned type (i.e. uint32_t)
Would evaluate to range [0, m) for any of the 2³² possible x, reaching any of the m possible outcomes either 2³² / m or 2³² / m + 1 times (where /... | stackexchange_codegolf |
The Method of Finite Differences is a technique used to find the next term in a sequence of numbers, given that the sequence is governed by consecutive values of a certain polynomial. Given a list of n terms, the Method will be able to determine the degree of the polynomial, which is a maximum of n+1.
The Method works ... | stackexchange_codegolf |
A sturdy square (akin to a magic square) is an arrangement of the integers 1 to \$N^2\$ on an \$N\$ by \$N\$ grid such that every 2 by 2 subgrid has the same sum.
For example, for \$N = 3\$ one sturdy square is
1 5 3
9 8 7
4 2 6
because the four 2 by 2 subgrids
1 5
9 8
5 3
8 7
9 8
4 2
8 7
2 6
all sum to the same amoun... | stackexchange_codegolf |
Challenge
Challenge is writing a program that takes a positive numbers a and a nonzero number b and outputs a^b (a raised to the power b). You can only use + - * / abs() as mathematical functions/operators. These can only be applied to scalar values, but not to whole lists or arrays.
Examples:
1.234 ^ 5.678 = 3.29980... | stackexchange_codegolf |
Write a program that reads a string, and inserts commas to divide large numbers in groups of 3. i.e. 10000 => 10,000. It should 'fix' incorrectly formatted numbers as described below.
It must work for all numbers on the same line
It should not modify numbers after a decimal point. i.e. 1234.5678 => 1,234.5678
Leading... | stackexchange_codegolf |
Take a list of 2-digit hexadecimal numbers as input, and output the binary value, replacing each 1 with an 'X', and each 0 with a space.
For example
Input = FF, 81, 47, 99.
FF = 11111111 in binary, so print XXXXXXXX
81 = 10000001 in binary, so print X X
47 = 01000111 in binary, so print X XXX
99 = 10011001 in ... | stackexchange_codegolf |
Background
You have again, again been given the task of calculating the number of landmines in a field. But this time, the field is foggy.
You must calculate the landmine score given a list/string of numbers, the landmine number, and the land distance (all are numbers).
The landmine number tells you where landmines are... | stackexchange_codegolf |
Background:
Take this input as an example:
1 1 2 1 1 2 1 3 1 3
If you look only at the first few digits, between 1 1 2 and 1 1 2 1 1 2 1, this input appears to consist of the pattern 1 1 2 repeating indefinitely. This would make its period 3, as there are 3 numbers in the pattern.
Given only the first number, the peri... | stackexchange_codegolf |
Given an input string containing only letters and numbers, write a program or function that prints the possible printable ASCII characters (Hex 20-7E) that correspond with the string's value in bases 8, 10, and 16 (where possible). The characters must be written in increasing order in terms of the bases with which they... | stackexchange_codegolf |
The Narrative
You are a bad musician. You never bothered to learn how to count rhythms. To remedy this shortcoming, you decide to write a program that will tell you how to count in any given time signature. You are still a bad musician, but you can at least pretend that you can count rhythms.
The Objective
Given a time... | stackexchange_codegolf |
Create a program which prints the amount of characters its source has in English words.
If your program is nine letters long it should print "nine".
Capitalization is ignored: in case you're printing "one" (somehow) you can print "one", "oNe", "ONE" or anything else.
Base ten is required.
Proper spacing is also require... | stackexchange_codegolf |
For this challenge, a linked list looks like this:
[1, 2, 4, 0, 6, 1, 3, 1]
You'll notice there's no data; each item in the list is just a reference to the index of the next one. Your task is to write a program or function which will follow a linked list like this forever, outputting each item as it is encountered. Fo... | stackexchange_codegolf |
Background
Challenge is inspired by this question.
The 1-expression is a formula that in which you add and multiply the number 1 any number of times. Parenthesis is allowed, but concatenating 1's (e.g. 11) is not allowed.
Here is an example to get the 1-expression for \$19\$:
(1+1)*(1+1)*(1+1+1+1)+1+1+1 = 19
Total num... | stackexchange_codegolf |
It's the ending of another well played chess game. You're the white player, and you still have a rook and your king. Your opponent only has his king left.
Since you're white, it's your turn. Create a program to play this chess match. Its output can be a sequence of moves, a gif animation, ASCII art or whatever you like... | stackexchange_codegolf |
What general tips do you have for golfing in Smalltalk? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Smalltalk (e.g. "remove comments" is not an answer).
Smalltalk is a purely object-oriented language created by Alan Kay. The two links are GNU Small... | stackexchange_codegolf |
Given positive integers \$w\$ and \$h\$ output \$w\$ columns and \$h\$ rows of text as described below.
The first row begins with 11 0s, the second row with 10 1s, third with nine 2s and so on down the the tenth row with two 9s. On each of these first ten rows, following the initial run of consecutive digits, the next ... | 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 |
Background
An Eisenstein integer is a complex number of the form \$ z = a + b\omega \$ where \$a, b\$ are integers and \$\omega\$ is the third root of unity \$\frac{1-\sqrt3i}{2}\$. The Eisenstein integers can be viewed as the triangular lattice points, as shown in the image below (from Wikipedia):
Following the trian... | stackexchange_codegolf |
From Wikipedia:
The centroid of a non-self-intersecting closed polygon
defined by n vertices (x0,y0),
(x1,y1), ...,
(xn−1,yn−1) is the point (Cx,
Cy), where
and where A is the polygon's signed area,
In these formulas, the vertices are assumed to be numbered in order of
their occurrence along the polygon... | stackexchange_codegolf |
Background
I have a string in Python which I want to convert to an integer. Normally, I would just use int:
>>> int("123")
123
Unfortunately, this method is not very robust, as it only accepts strings that match -?[0-9]+ (after removing any leading or trailing whitespace). For example, it can't handle input with a dec... | stackexchange_codegolf |
Output this table:
-2*
-1*
-
0
-
1
2
-1*
0
1
-
2
3
4
1
2
3
-
4
5
6
3
4
-
5
-
6
7
5
6
-
7
-
8
9
6
7
8
-
9
10
11
8
9
10
-
11
12
13
10
11
-
12
-
13
14
You can output one string with two types of split, 1D string array with one type of split, or 2D string array
If your language support mix... | stackexchange_codegolf |
Background
There's a terrible problem in my console - the quotes never get included inside the arguments! So, when given this argument:
["abc","def","ghi","jkl"]
it says that the argument is like this:
[abc,def,ghi,jkl]
It would be very nice if you can fix this problem!
Challenge
Add double-quotes (") in order to sur... | 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 |
Challenge
Given a string as input, golf down the Fourier program which outputs that string.
In Fourier there is no easy way to output a string: you have to go through each character code and output that as a character.
Fourier
The language is based upon an accumulator, a global variable which is initialised to 0 at the... | stackexchange_codegolf |
I didn't invent this challenge, but I find it very interesting to solve.
For every input number, e.g.:
4
Generate a range from 1 to that number:
[1 2 3 4]
And then, for every item in that list, generate a list from 1 to that number:
[[1] [1 2] [1 2 3] [1 2 3 4]]
Then, reverse every item of that list.
[[1] [2 1] [3 2... | stackexchange_codegolf |
Sequence Definition
Construct a sequence of positive integers a(n) as follows:
a(0) = 4
Each term a(n), other than the first, is the smallest number that satisfies the following:
a) a(n) is a composite number,
b) a(n) > a(n-1), and
c) a(n) + a(k) + 1 is a composite number for each 0 <= k < n.
So we start with a(0) =... | stackexchange_codegolf |
For each character in your program, the program with that character removed must produce a number smaller than the program with the next character removed. Your base program isn't required to do anything, and may be invalid.
An example submission could be abcd, where bcd outputs 1, acd outputs 4, abd outputs 5, and abc... | stackexchange_codegolf |
Given a positive integer n, compute the nth Wilson number W(n) where
and e = 1 if n has a primitive root modulo n, otherwise e = -1. In other words, n has a primitive root if there does not exist an integer x where 1 < x < n-1 and x2 = 1 mod n.
This is code-golf so create the shortest code for a function or program t... | stackexchange_codegolf |
I have a coding problem that goes like this:
Given a positive integer \$N\$, return a list of all possible pairs of positive integers \$(x,y)\$ such that $$\frac1x+\frac1y=\frac1N$$
I already solved the problem using Python, but I was wondering how I can code golf it. The following is my attempt at golfing (I try to ... | stackexchange_codegolf |
Problem
Inspired by a previous challenge doing something similar
Given positive integer input n output a shape that follows this pattern:
input n=1:
* *
*
* *
input n=2:
** **
****
**
****
** **
input n=3:
*** ***
*** ***
*****
***
*****
*** ***
*** ***
and so on...
It has these properties:
n*2+1... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.