instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
The task
Write a program or function whose input is a list/array X of integers, and whose output is a list of sets of integers Y, such that for each element e in each set Y[i], X[e] = i, and such that the total number of elements in the sets in Y equals the number of elements in X.
(This is basically the same operation... | stackexchange_codegolf |
Think of cleave as the conceptual inverse of map. If map applies a function to each number in a list...
map([1, 2, 3], x -> x * 5) -> [5, 10, 15]
then cleave applies each function in a list to a number.
cleave(5, [x -> x * 2, x -> x - 1, x -> x * x]) -> [10, 4, 25]
More formally, given:
\$n\$, an integer, and
\$L\$, a... | stackexchange_codegolf |
Challenge
Suppose you have a list of numbers, and a target value. Find the set of all combinations of your numbers which add up to the target value, returning them as list indices.
Input and Output
The input will take a list of numbers (not necessarily unique) and a target summation number. The output will be a set of ... | stackexchange_codegolf |
A radiation-hardened program is a program where, if any character of the code is removed, the program will still function the same. For this question, we'll be writing a program that detects when it is irradiated.
Write a program or function that, when any single byte is removed, the resulting program will output that ... | stackexchange_codegolf |
Because there are not enough simple code-golf challenges:
Create an optionally unnamed program or function that, given (by any means) an integer 1 ≤ N ≤ 10000, outputs your language's True value with a pseudo-random probability of 1/N, False otherwise.
Please note that the requirement for naming has been removed. Feel ... | stackexchange_codegolf |
Welcome back! I'm excited to present the 3rd CodeBots challenge. This one has been a long time in the making. This challenge will be split up in 3 sections: the short version, the long version, and additional details.
The Short Version
Each competitor will write a 24-command program. These bots will move around the ... | stackexchange_codegolf |
In the MMORPG Final Fantasy XIV, the Ninja class has the ability to use combinations of up to three handsigns (Ten, Chi and Jin) to perform a variety of ninjutsu skills.
The skill you cast depends on the last sign used, and using two or more of the same sign makes the ninjutsu skill fail and puts a little bunny on your... | stackexchange_codegolf |
Related: Sort these bond ratings
Credit rating agencies assign ratings to bonds according to the credit-worthiness of the issuer.
The rating business is mostly controlled by "Big Three" credit rating agencies (i.e. Fitch Ratings, Moody's, and Standard & Poor's (S&P)), which use a similar tiered rating system.
Task
For ... | stackexchange_codegolf |
This challenge was inspired by this non-challenge about the natural logarithm base \$e\$ and the following pandigital approximation to \$e\$ appearing on a Math Magic page:
$$\left|(1+9^{-4^{7×6}})^{3^{2^{85}}}-e\right|$$
$$\approx2.01×10^{-18457734525360901453873570}$$
It is fairly well-known that
$$e=\lim_{n\to\infty... | stackexchange_codegolf |
A binary relation on a set \$X\$ is simply a subset \$S \subseteq X \times X\$; in other words, a relation is a collection of pairs \$(x,y)\$ such that both \$x\$ and \$y\$ are in \$X\$. The number of different relations grows quickly with the size of the set: if \$X\$ contains \$n\$ elements, there are \$2^{n^2}\$ bin... | stackexchange_codegolf |
A huge storm is ravaging the world and as you and your family run away from it, you come across a gigantic shelter run by a girl. She tells you that "she sells sanctuary" and that different types of rooms are offered at different prices.
A room may only house one person.
The challenge
Write a program which takes in two... | stackexchange_codegolf |
A recent SO question asks for a convenient one-liner to generate a list of numbers and their negative counterparts in Python.
Given two integers \$1≤a≤b\$, generate all the integers \$x\$ such that \$a≤|x|≤b\$. The result may be printed or returned in any order or structure, as putting the result into a list and sortin... | stackexchange_codegolf |
Given integers N , P > 1 , find the largest integer M such that P ^ M ≤ N.
I/O:
Input is given as 2 integers N and P. The output will be the integer M.
Examples:
4, 5 -> 0
33, 5 -> 2
40, 20 -> 1
242, 3 -> 4
243, 3 -> 5
400, 2 -> 8
1000, 10 -> 3
Notes:
The input will always be valid, i.e. it will always be integers g... | stackexchange_codegolf |
Implement a function or program which raises x to the power of y. Inputs are 16-bit signed integers. That is, both are in the range [-32768, 32767]. The output should be in the same range. I chose this range because it should make it possible to do exhaustive testing to ensure all edge-cases are covered.
If the output ... | stackexchange_codegolf |
Problem
Assume you have a single 7-segment display without a decimal point, so 7 "lines" that can be labelled A through G as seen here.
This display will only show the numbers from 0 to 9 as usual, like so:
Any time this display changes from one number to another, some of its lights will have to change their state fr... | stackexchange_codegolf |
A metaquine is a program which is not a quine, but whose output, when run as a program in the same language, is a quine.
The goal of this challenge is to write a metaquine. This is code-golf, so shortest code wins, with earliest answer used as a tiebreaker. Note that only full programs are acceptable, due to the defini... | stackexchange_codegolf |
This challenge will have give you a positive integer \$n\$ and ask you to output \$t(n)\$, the number of triangles (up to congruence) satisfying the three conditions:
The triangles have perimeter of 1,
the triangles have side lengths \$\displaystyle\frac{a_1}{b_1}, \frac{a_2}{b_2}\$, and \$\displaystyle\frac{a_3}{b_3}... | stackexchange_codegolf |
Awhile back I encountered a simple programming puzzle to determine whether a string was a pangram, or a perfect pangram. (Although it's worth noting that this particular challenge gave a different meaning than the standard definition of a "perfect pangram," to mean any sentence where every letter appears n times for so... | stackexchange_codegolf |
Consider a string like:
a.push(c.push("a",["ad","bd",2,{"ard",duo}]).pop().replace(2,"tg").enc([3,{2,adf},"atr"],5)
Write a program that will verify whether a string is correctly bracketed. A correctly bracketed string can be defined as one in which all brackets are terminated (closed), and the inner brackets are term... | stackexchange_codegolf |
Task
Given two positive integers a, b and a Unicode mathematical inequality symbol c, determine if a c b is true.
You many take the character or its Unicode codepoint for the input c. You may output your language's truthy/falsy values, or two distinct values for true and false respectively.
Standard code-golf rules app... | stackexchange_codegolf |
Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N investors (N>=1), each i-th investor invested x[i]. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T a peer could be rewarded. But only if a following conditions are satisfied:
Minimum amount of investors should be gre... | stackexchange_codegolf |
This is a more difficult version of It's a find-a-movie challenge .
Input
Your code should take a BBFC rating and a number from 1 to 5 as input. It can do this in any way you find convenient.
Output
Your code should return the name of any movie which has a) that film rating and b) that number of stars in a Guardian fi... | stackexchange_codegolf |
My parents have an home theater device. The remote is broken making it incredibly difficult to navigate rightwards in a menu. Most the time it doesn't work but when it does it moves rightwards incredibly quickly.
This is obviously frustrating but it is most frustrating when you want to enter a movie title which requi... | stackexchange_codegolf |
For the purpose of this challenge, arguments are things you pass to a function at the call site, while parameters are what the function uses in its implementation. Or, more succinctly: arguments = external, parameters = internal.
While there are several modern languages that have support for argument labels for func... | stackexchange_codegolf |
Given a non-empty string of lowercase ASCII letters a-z, output that string with each consecutive “run” of the same letter lengthened by one more copy of that letter.
For example, dddogg (3 d’s, 1 o, 2 g’s) turns into ddddooggg (4 d’s, 2 o’s, 3 g’s).
This is code-golf: the shortest answer in bytes wins.
Test cases
aab... | stackexchange_codegolf |
This is the robbers' thread for 'Almost Illegal Strings'.
See the cop's thread for information on participating. A section from the post is included here for convenience.
The Robbers' Challenge
Find an uncracked answer. Write a program in the language specified that contains as a contiguous substring the almost illega... | stackexchange_codegolf |
Context
(Feel free to skip, doesn't really matter for the algorithmic explanation of the task)
European Portuguese is a fairly complicated language to learn, mostly because of its grammar. One particular annoying thing is conjugating the verbs correctly:
We have this mechanism that, when we have a verb followed by a no... | stackexchange_codegolf |
Base: part 1
This is part 2, Strongly suggest you go try out the first one if you haven't tried it.
Story
As one of the solvers, You've managed to get to the door of the base heaven. In front of the door stands the base guard @lyxal, they were angry that you all just left the encoded text on the ground, they demand tha... | stackexchange_codegolf |
A Window is an ASCII-art square with odd side length of at least 3, with a single character border around the edge as well as vertical and horizontal strokes in the middle:
#######
# # #
# # #
#######
# # #
# # #
#######
An MS Window is a window where the border is made only of the characters M and S. Your tas... | stackexchange_codegolf |
Consider the number 99999999. That number is obviously a palindrome. The largest prime factor of 99999999 is 137. If you divide 99999999 by 137, you get 729927. This number is also a palindrome.
The largest prime factor of 729927 is 101. 729927/101=7227 which again is a palindrome.
The largest prime factor of 7227 is... | stackexchange_codegolf |
You are piloting a spaceship, outfitted with an engine that can accelerate you at 1km/s^2 in the direction the ship is facing (you have very good inertial dampers). You also have thrusters which can rotate you 180 degrees in 1s (rotating 45 degrees takes 0.25s, etc.).
You see on your scanner another ship, and decide t... | stackexchange_codegolf |
Inspired and looted from this dice challenge by Arnauld
Input
You are given a 5x1 or 1x5 (your choice) dice matrix which consist of binary 3x3 sub-matrices.
Goal
Given a valid dice matrix, you are to score it using the rules of 6,5,4 which are as follows:
If the roll contains 6,5,4, add the other two dice together and... | stackexchange_codegolf |
Task similar to this one. Take a string of ASCII characters and convert it to base-3 equivalents separated by a space.
For example:
Hello, world!
Should be converted to
02200 10202 11000 11000 11010 01122 01012 11102 11010 11020 11000 10201 01020
The output should only contain numbers with the same number of digits. ... | stackexchange_codegolf |
It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal.
The 0 and 1 are plain characters, i.e. ASCII code 0x30 and 0x31 respectively.
Example: 0abcd prints 0 and halts, and 1abcd prints 1 infinitely. Then your submission is abcd, whose score is 4 bytes. The 0... | stackexchange_codegolf |
I have a list of images grouped numerically (YI0.png, YI1.png...YI20479.png). I want them sorted alphabetically, like so:
YI0.png -> YIA.png
YI1.png -> YIAA.png
without my last image having 20479 As in it.
Input
A directory name.
Output
All files in that directory will be alphabetically renamed.
Constraints
The patte... | stackexchange_codegolf |
Challenge
You must output the Chinese character for biáng. Your program must not access any external sources and must exactly reproduce this SVG in every way. Note that the image below is just a gif version of the image.
The output should be an SVG file. Your program must be a program, therefore you cannot hardcode the... | stackexchange_codegolf |
Write a program that takes two lists of strings and generates a javascript regex that fully matches all the strings in the first list and matches none of the strings in the second list.
To be specific when for all stings in the first list str.match(/[your-output]/) must produce a match for the full string and for all s... | stackexchange_codegolf |
Not a duplicate of the valid move challenge because that asks for specific pieces.
Backstory
The other night I was doing a little trolling with ChatGPT and chess. I was trying to get it to call me out for making illegal moves, as a lot of the time, you can feed it whatever nonsense you want. While doing so, I wondered ... | stackexchange_codegolf |
Challenge
For a given positive integers range, find the first and last prime number entirely composed of prime number digits, exceptionally including 0 (for the digits, a range of 0-2 should output 2-2). The range is inclusive. If no number is found, the expected output is 0. If there is only one such number, the expec... | stackexchange_codegolf |
INTRO
Let's say you write a passage and you are close to the end of the line wanting to write down a large word. In most languages, you just leave some blank and move to the next line, like a sir.
Example - English:
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah this man is ... | stackexchange_codegolf |
Introduction
Braincopter is an esoteric Brainf*** derivative that encodes a Brainf***
program as an image. As a 2D language, it uses two additional commands; they
rotate the instruction pointer (initially pointing right) clockwise and
counterclockwise. Braincopter is very similar to Brainloller, except that
instead of ... | stackexchange_codegolf |
There are several questions regarding this game, even a king-of-the-hill contest here. But I think all those challenges and contests need a way to automatically determine the winner of a game. So:
Challenge
Given two inputs in the range ["rock", "paper", "scissors", "lizard", "spock"] representing the selections for pl... | stackexchange_codegolf |
It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as \$0^2+0^2+0^2+1^2\$. Or, in general, for any non-negative integer \$n\$, there exist integers \$a,b,c,d\$ such that
$$n = a^2+b^2+c^2+d^2$$
Joseph-Louis Lagrange pro... | stackexchange_codegolf |
Introduction
This is a little challenge with the goal of identifying repeated pattern "blocks" in a string, and outputting them with their frequency of occurence from left to right.
A friend asked me this question and I realized it wasn't as simple as tossing what you've seen into a hash table and popping them off if p... | stackexchange_codegolf |
This is a brainfuck version of Largest Number Printable, and this.
Let's think about brainfuck interpreter such that,
Has array that can be stretched left & right arbitrary large
Each cell can contain arbitrary large integer
Can contain negative integer too
When the interpreter starts, every cell is intialized by ... | stackexchange_codegolf |
One problem on a website like this is that you often don't know if you are talking to a male or female. However, you have come up with a simple NLP technique you can use to determine the gender of the writer of a piece of text.
Theory
About 38.1% of letters used in English are vowels [a,e,i,o,u] (see References below, ... | stackexchange_codegolf |
Two words are isomorphs if they have the same pattern of letter repetitions. For example, both ESTATE and DUELED have pattern abcdca
ESTATE
DUELED
abcdca
because letters 1 and 6 are the same, letters 3 and 5 are the same, and nothing further. This also means the words are related by a substitution cipher, here with t... | stackexchange_codegolf |
Letters of the words want fairness.
They decided to appear same number of times in a sentence equally.
Example:
Priorities
Will become:
Ppprrioooritttieeesss
Each letter appears 3 times, as the most common letter was i, appearing 3 times.
It does not matter where you put the repeated letters, as long as they are next... | stackexchange_codegolf |
The hamburger joint maHburger has hired you to write a program for them.
It is simple: make an ASCII hamburger, using the key. Sounds simple right? Well these customers are super picky, but one thing is for sure, they do love onions.
Write a program that accepts the customer's orders, and prints a hamburger with as man... | stackexchange_codegolf |
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:
Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)
ω(n) = k the number of distinct prime divisors. (A001... | stackexchange_codegolf |
Your challenge is to create the longest run of characters with incrementing Unicode codepoints in a pristine program as you can. To keep things simple, I'll abridge the definition for this challenge to be "any program which produces no errors but will error if any one character is removed".
Let's define a codepoint run... | stackexchange_codegolf |
Context
Consider square matrices with n columns and rows containing the first n^2 (i.e. n squared) positive integers, where n is odd. The elements of the matrices are arranged such that the integers 1 through n^2 are placed sequentially in a counterclockwise spiral starting at the center and initially moving to the lef... | stackexchange_codegolf |
Write a program or function that, when given a string, filters out as many distinct bytes as it can and returns the cleaned string. However, since your program hates them, none of these bytes can be present in your own code.
Your score will be the number of distinct bytes your program filters out from the input, with t... | stackexchange_codegolf |
A Ken Thompson virus is a virus that infects your compiler and other programs. Since it infects all your tools, you can not detect it without using tools from before the virus was introduced.
Your will create a prototype for inserting the Ken Thompson virus into code. The goal of this virus will be to allow you to (fak... | stackexchange_codegolf |
You must write a program or function that takes a string of brackets and outputs whether or not that string is fully matched. Your program should print a truthy or falsy value, and IO can be in any reasonable format.
Rules and definitions:
For the purpose of this challenge, a "bracket" is any of these characters: ()[]... | stackexchange_codegolf |
Challenge
Choose any number of languages. Call this set L.
Write a program so that running it in any language in L produces an interpreter for a different language in L.
Each language in L must have exactly one interpreter for it. This is to prevent, for example, Nothing or Text being part of L and all interpreters be... | stackexchange_codegolf |
One of your acquaintances has a hobby of making make-shift electrical gadgets using various types of batteries. However, since they're thrifty, they want to use as few batteries as possible for their projects. This challenge uses several types of batteries; your job is to output the fewest number of batteries that will... | stackexchange_codegolf |
Related
Now you have some dice which you may roll several times. You need a uniform random integer between 1 and \$n\$, inclusive. Show a method that rolls the fewest times and behaves as an \$n\$-sided dice.
Alternative question: Given a set \$S\$ and \$n\$, pick the fewest elements from \$S\$(each element can be pick... | stackexchange_codegolf |
It's election time, and your job is to beat your competitor in a head-on rivalry! You are both trying to win over a city of 256 people in a 16x16 grid. Right now, the city hasn't been divided into voting regions yet, but that's where your gerrymandering skills come in! You can also campaign in arbitrary areas of the ci... | stackexchange_codegolf |
It is well known that a person on a grid under the influence of alcohol has an equal chance of going in any available directions. However, this common-sense statement does not hold in the realm of very small drunkards, whose behavior is very much as if they take every available path at once, and the possible paths they... | stackexchange_codegolf |
The robber's thread is here
The cops task is to write a function or program that, when given an input of itself, outputs a finite deterministic string. If the program is given a different input, it should return a different output.
Rules:
Submissions consist of
Language name
If any flags are used, they should be r... | stackexchange_codegolf |
The Pareto Distribution is a probability distribution that comes up a lot in nature. It has lots of special properties, such as an infinite mean. In this challenge, you will output a number sampled from this distribution.
The Pareto Distribution is defined to be greater than or equal to x with probability 1/x, for all ... | stackexchange_codegolf |
The challenge
Make 2 programs which convert decimal to and from base 94, or a bidirectional program.
Base 94?
Base 94 is like any other base, but instead of 0 to 9 and letters, it uses ASCII characters 33 to 126. Not 127 because chr(127) is DEL. Not 32 because that's a space.
Examples
0 - ! or empty string
1 - "
93 - ~... | stackexchange_codegolf |
This is a Hello World challenge! Those plain ones! Yeah....
However, it's different this time.
Because here, you can't use C or C++ or Stuck or ArnoldC or whatever you want. You can only choose raw x86 opcodes from this list, or any other x86 opcode lists.
It is also assuming you have no Protected Mode or any other thi... | stackexchange_codegolf |
You are to write a program which outputs a single positive integer \$n\$. The integer may have leading zeros and whitespace, and/or trailing whitespace.
Then, choose a positive integer \$m > 1\$. When the program is repeated exactly \$m\$ times, it should output \$m \times n\$ (and only \$m\times n\$). When repeated an... | stackexchange_codegolf |
Input
The code should take an integer \$n\$ between 1 and 1000.
Output
The code should output positive integers with \$n\$ bits. Accompanying each integer should be its full factorization. Each integer should be a uniformly random \$n\$ bit number.
Score
The score for your code will be the number of integers it outputs... | stackexchange_codegolf |
In this contest you have to write a program, that accepts a black and white pixel image, and tries to alter it, such that the white shape forms star domain, with as few changes as possible.
Allowed changes are turning white pixels into black ones and turning black pixels into white ones.
The output must again consist o... | stackexchange_codegolf |
I was messing around with Pyth's url request feature, and noticed that google always gave a response with a slightly different length for me, usually ~10500 characters.
So your task in this challenge is to print out the average length of the html response from http://google.com.
Specs
You will take an input n which is... | stackexchange_codegolf |
When it comes to eating candy, I hold myself to higher standards than the typical layperson. There is a delicate balance between "mixing it up" and "saving the best for last."
In this challenge, you will be given a string of characters in which each character represents a piece of candy. Different characters (case-se... | stackexchange_codegolf |
Working on something in probability theory, I stumbled across another combinatorical exercise. These are always fun to solve, searching for intelligent approaches. Of course, one can use brute force for the following task, but this challenge is restricted complexity, so this is not allowed.
Task
Given an integer Input ... | 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 |
Definition
For any \$a\equiv1\ (\text{mod }8)\$ and \$n\ge3\$, there are exactly 4 roots to the equation \$x^2\equiv a\ (\text{mod }2^n)\$. Now, let \$x_k(a)\$ be the smallest root to the equation \$x^2\equiv a\ (\text{mod }2^k)\$, then $$\{x_3(a),x_4(a),x_5(a),x_6(a),\cdots\}$$ is a smallest square root sequence (SSRS... | stackexchange_codegolf |
Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two points. Use any maths formula you like, such as
$$gcd(|x_2 - x_1|, |y_2 - y_1|) - 1$$
Input
Four integer coordinates of... | stackexchange_codegolf |
The challenge
Interpret the stack-based programming language underload.
The stack is a stack of strings that can be concatenated together.
Each underload program is a string of some of these instructions:
~: Swap the top two elements of the stack.
:: Duplicate the top element of the stack.
!: Discard the top element o... | stackexchange_codegolf |
Given an infix expression, determine whether all constants are of the same type.
Operators will consist only of these dyadic operators: +-/*
Your program or function should take a valid expression string as input, and output a truthy value if the constants in the expression are of the same time, and a falsey value othe... | stackexchange_codegolf |
One way to generalize the concept of a range from the integers to the Gaussian integers (complex numbers with integer real and imaginary part) is taking all numbers contained in the rectangle enclosed by the two ends of the range. So the range between two Gaussian integers a+bi and c+di would be all Gaussian integers x... | stackexchange_codegolf |
Given an integer 2n, find the number of possible ways in which 2n^2 black pawns and 2n^2 white pawns can be arranged on a 2n by 2n chess board such that no pawn attack another.
A black pawn can attack only a white pawn, and vice versa.
The usual chess rules of attacking follow, i.e, white pawns attack squares immediat... | stackexchange_codegolf |
For each row and then column of a matrix, we can add an extra entry with the sum of the last two entries in that row or column. For example with the following input matrix:
[ 1 1 1 ]
[ 2 3 4 ]
The resulting matrix would be:
[ 1 1 1 2 ]
[ 2 3 4 7 ]
[ 3 4 5 9 ]
Given an input of an integer N and an [X,Y] matrix of siz... | stackexchange_codegolf |
Whispers is February 2021's Language of the Month, so what tips do you have for golfing in it? Tips do not have to be specific to code-golf, so long as they apply to other types of challenges on the site. Tips should be at least somewhat specific to Whispers (e.g. "remove ignored code" is not an answer). Please post on... | stackexchange_codegolf |
Task
The task is to write a program that outputs a consistent but otherwise arbitrary positive integer \$x\$ (so strictly greater than 0). Here's the catch: when the source is repeated \$N\$ times (the code is appended/concatenated \$N-1\$ to itself), the program should have a \$\dfrac{1}{N}\$ probability of outputting... | stackexchange_codegolf |
I have the following Haskell code to generate the the values of the Fibonacci sequence which are even as an infinite list:
z=zipWith(+)
g=z((*2)<$>0:0:g)$z(0:g)$(*2)<$>scanl(+)1g
This works by starting with 0,2 and then defining every following term to be the sum of:
twice all prior terms
the previous term
twice the ... | stackexchange_codegolf |
Help! I printed a bunch of rational numbers with no spaces or other delimiters other than the / in the fractions. There is, however, good news! All the numbers are positive. There are no improper fractions, every numerator is less than its denominator and any integers are represented directly, not as fractions. Any non... | stackexchange_codegolf |
Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two points. Use any maths formula you like, such as
$$gcd(|x_2 - x_1|, |y_2 - y_1|) - 1$$
Input
Four integer coordinates of... | stackexchange_codegolf |
Here's an interview question I've seen on a few sites. People claim that an O(n) solution is possible, but I've been racking my brain these last 2 days and I couldn't come up with a solution, nor find one anywhere on the web.
Given an array of integers, find two disjoint, contiguous subarrays such that the absolute dif... | stackexchange_codegolf |
Backstory, skip if you like
Generating high quality pseudo random numbers is a tricky business but the fine engineers at < enter company you love to hate > have mastered it. Their progress bars effortlessly rise above the primitive notion of linearly passing time and add an exhilarating sense of unpredictability to the... | stackexchange_codegolf |
Given an integer n, output the following ASCII art to n rows:
1+1=2
1+2=3
2+3=5
3+5=8
5+8=13
Essentially, the first row is 1+1=2 and the nth row (1-indexed) is \$f_n + f_{n+1} = f_{n+2}\$ where \$f\$ is the Fibonacci sequence, padded so the numbers line up with the previous row.
You may instead out... | stackexchange_codegolf |
This task is rather simple, and makes use of three distinct "operator" characters. Your task is, given a simple sequence of letters, perform the following task to encode it using <,>,*. You may choose to use either upper or lowercase letters, you do not have to handle both.
Cipher Explanation
The cipher is simple, you... | stackexchange_codegolf |
Several Mathematica functions have system-defined short forms, e.g., /@ for Map. Many of them are listed here: https://reference.wolfram.com/language/tutorial/OperatorInputForms.html
However, there also exist some system-defined short forms for function-option combinations. E.g., Log2@ninstead of Log[2, n] and Log10@... | stackexchange_codegolf |
Your task is to create the given target string. Starting with an string that is empty, you will have to add characters to it, until your string is the same as the one we want. You can either add a character to the end of you string with cost x, or you can clone you string with cost y. What we want is the cheapest way t... | stackexchange_codegolf |
This is a cake:
_========_
| |
+________+
| |
+________+
| |
+________+
It is 8 wide, 3 tall, and 1 deep.
You must write a program that makes a cake from 3 inputs. The first input controls how many underscores there are in the middle and =s on the top. Here's the first cake with a width of 10 inst... | stackexchange_codegolf |
You are to write a program which generates random integers between \$0\$ and \$99\$ inclusive, outputting each integer in turn, until \$0\$ is generated. You may choose which single-order random distribution (uniform, binomial, Poisson etc.) you use so long as each integer has a non-zero chance of being generated and i... | stackexchange_codegolf |
Inspired by this and this question
Challenge
Your challenge is to print any 100 consecutive digits of Champernowne's Constant. You must give the index at which that subsequence appears. The 0 at the beginning is not included.
For example, you could print any of the following:
+-----+------------------------------------... | stackexchange_codegolf |
This is somewhat similar to The centers of a triangle, but with a different point. The Fermat Point is the point P in triangle ABC such that the value of AP + BP + CP is minimized. There are two cases:
If there is an angle greater than 120 degrees, that vertex is the fermat point. Otherwise, draw equilateral triangles ... | stackexchange_codegolf |
Input:
An integer n
Output:
A string A * B
Example
12
Possible 2 divisible numbers: 12 * 1, 6 * 2, 4 * 3
12-1 = 11
6-2 = 4
4-3 = 1
4 and 3 has the minimal absolute difference of 1
Therefore, Output:
4 * 3
Order of the numbers does not matter
This challenge idea was taken from a puzzle in Clash of Code in https://www... | stackexchange_codegolf |
Given 2 positive integers in any format you'd like, return their sum using only logic gates and bit shifts (see example below). Don't worry about overflow.
EDIT: Using pre-written addition is obviously not allowed. So no a + b, Add(a, b), a - (-b) etc.
This is code golf, so standard loopholes apply. Shortest program in... | stackexchange_codegolf |
There's something (well, many things ) that really annoys me. It is when dictionaries (English, not Pythonic) use the defining word itself to define the word, also called circular definitions. Example:
reticence: the quality of being reticent
-- Apple Dictionary
Circular definition: a definition that is circular
--... | stackexchange_codegolf |
This time, you are working on a regex. Your regex is meant to approximately full-match the base-10 representations of primes \$0 \le p < 1000\$, while ignoring any non-numeric string or composite in the range. You can full-match 2, 53 or 419, but not 0, 82 or example.
The approximately is important -- a minimum of 900 ... | stackexchange_codegolf |
I've been enslaved in a quine factory. The other workers and I can't communicate with the outside world, we can only slave away making quines all day. The masters will reject any work that isn't a proper quine. I'll have to put messages into the quines I make to let people know we're trapped here.
The Challenge
Help us... | stackexchange_codegolf |
Input:
Two strings (NOTE: the order of input is important).
Output:
Both words/sentences start on lines with one empty line in between them. They 'walk' horizontally 'next to each other'. But when they have the same character at the same position, they cross each other, and then continue walking 'next to each other'.
C... | stackexchange_codegolf |
(related/inspired by: Draw a bowling formation)
A fun pastime in the winter months here is to perform snowman bowling, using a large ball (like a basketball) and tiny snowman figures. Let's recreate this in ASCII.
Each snowman consists of the following:
(.,.)
( : )
Here is the alignment of the ten snowman "pins"
(.,.)... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.