instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Background
You awake to find yourself lost in a one dimensional labyrinth! A mystical genie (or something) appears and explains that the exit lies in front of you, but that between you and the exit is a series of challenges. As you wander forward you realize that all of the so-called challenges are merely locked doors.... | stackexchange_codegolf |
It's strange this question hasn't been asked yet, so here it is:
Calculate the length of a string given through STDIN
Rules
As said, your string will be given through STDIN, not via command line arguments
Print the length of the string to STDOUT
Only ASCII chars will be given, and all printable ASCII chars count!
This... | stackexchange_codegolf |
Task
A Rotate-Left-Double number in base \$n\$ is a number \$m\$, when its base-\$n\$ digits are rotated left once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have leading zeros.
One example in base 7 is the number 480, or \$1254_7\$. When rotated left once, the value becomes \$2541_7 = 960\$.
Given t... | stackexchange_codegolf |
One way to represent a natural number is by multiplying exponents of prime numbers. For example, 6 can be represented by 2^1*3^1, and 50 can be represented by 2^1*5^2 (where ^ indicates exponention). The number of primes in this representation can help determine whether it is shorter to use this method of representat... | stackexchange_codegolf |
Simple question!
Given a string that contains a date in ISO8601 format, print the first of the next month in ISO8601 format.
Example inputs:
2018-05-06
2019-12-20
Their respective outputs:
2018-06-01
2020-01-01
The rules:
Imports are free and don't count towards your score.
The date will be stored in a string called s... | stackexchange_codegolf |
Wordle is a daily online word game that has received considerable attention recently.
The Game
The object is to guess a secret word in the fewest attempts. Consider the following instance of the game:
The secret word is rebus, and the player's first guess was arise. The letters r, s, and e are displayed in yellow to i... | stackexchange_codegolf |
Write a function that takes two parameters: a positive integer n and a list of words.
Given a cube of n-by-n-by-n units, assign a random letter (A-Z) to each surface unit. (For a 3x3x3 cube, there would be 9 surface units on each face.)
Then determine whether it's possible for an ant walking along the surface (with th... | stackexchange_codegolf |
Euler's totient function, \$\varphi(n)\$, counts the number of integers \$1 \le k \le n\$ such that \$\gcd(k, n) = 1\$. For example, \$\varphi(9) = 6\$ as \$1,2,4,5,7,8\$ are all coprime to \$9\$. However, \$\varphi(n)\$ is not injective, meaning that there are distinct integers \$m, n\$ such that \$\varphi(m) = \varph... | stackexchange_codegolf |
Your task is to write a computer program such that when it is cut up into lines (split on the newline character) every arrangement of the lines will output a different number between 1 and n! (where n is the total number of lines). No number should be output by two different arrangements and every arrangement should o... | stackexchange_codegolf |
Background
The Schläfli Symbol is a notation of the form {p,q,r,...} that defines regular polytopes and tessellations.
The Schläfli symbol is a recursive description, starting with a p-sided regular polygon as {p}. For example, {3} is an equilateral triangle, {4} is a square and so on.
A regular polyhedron that has q r... | stackexchange_codegolf |
The Penrose triangle, also known as the Penrose tribar, or the impossible tribar, is an impossible object.
The goal in this challenge is to display a Penrose triangle in the fewest bytes possible.
Source: Wikipedia
Rules:
You must display the Penrose Triangle digitally after generating it.
They must look the same as ... | stackexchange_codegolf |
Overview
The ancient Romans devised a number system using Latin letters, which served them well, and which is still used by modern civilization, though to a much smaller degree. In the time of its use, Romans would have had to learn to use and manipulate these numbers in order to be of much use for many applications. F... | stackexchange_codegolf |
The Language: Oppification
A funny language to speak is created by applying the following process to each word:
Place op after each consonant. So Code becomes Copodope.
Yes, that's it. For the purpose of this challenge, y is always a consonant.
The Challenge: De-oppification
Given an oppified word, return the origina... | stackexchange_codegolf |
Input a decimal number and round it to an integer, randomly rounding up or down with a probability based on its fractional part, so the expected value of the output equals to the input value.
If input \$x\$ is an integer, the program should output it as is. If \$x\$ is not an integer, the program has a \$x-\left\lfloo... | stackexchange_codegolf |
I'm golfing a program to sum two numbers in C++.
Example:
10 3
13
I found out that this problem can be solved in 54 symbols (without spaces and so on) using C++.
My code (63 symbols):
#include <iostream>
main() {
int a, b;
std::cin >> a >> b;
std::cout << a + b;
}
I have no idea how to make my program sho... | stackexchange_codegolf |
We've had lots of questions about quines, programs where the source code and output are identical. For compiled languages, there are other combinations: we've already had a question about writing a program where the executable and output are identical. But there's one combination left.
The task
Using a compiled languag... | stackexchange_codegolf |
You're playing TF2, and you want to make a bot that will just put voice commands into the chat box. Typically, to "call" a voice command, one would press a key (Z, X, or C) and a number (1-8) to create an audio dialogue. Here are the text equivalents of the audios displayed when pressing these keys:
Voice Menu 1
Defaul... | stackexchange_codegolf |
Wanna be an Alchemist
I've been watching Full Metal Alchemist these past days and I've been wondering, It is really possible to trans-mutate matter? In the real world, I don't know if it is possible, but in the machine world, we think we "can".
Problem
Your task is, Given an input of N chemical elements (K, Mg, C, O, ... | stackexchange_codegolf |
(Title with thanks to @ChasBrown)
Sandbox
The Background
This challenge is inspired by a question that I recently posted on Puzzling Stack Exchange. Please feel free to follow the link if you are interested in the original question. If not then I won't bore you with the details here.
The Facts
Every printable standard... | stackexchange_codegolf |
The Levenshtein distance between two strings is the minimum number of single character insertions, deletions, or substitutions to convert one string into the other one.
The challenge is to compute the average Levenshtein distance between two independent and uniformly random chosen binary strings of length n each. Your... | stackexchange_codegolf |
Surprised that we don't have a symmetric difference challenge yet.
Given two lists only containing positive integers, return all items among these two lists that aren't contained in both of the lists.
Rules
From the set definition:
A set is a collection of definite distinct items.
So you can assume the items in the ... | stackexchange_codegolf |
Background
Flow Free is a series of puzzle games whose objective is to connect all the same-colored pairs of dots on the grid. In this challenge, we consider the original game on a rectangular grid (no variations like bridges, warps, or hexagonal grids).
A puzzle in Flow Free might look like this:
Puzzle Solution
...... | stackexchange_codegolf |
This was inspired by a function I recently added to my language Add++. Therefore I will submit an short answer in Add++ but I won't accept it if it wins (it wouldn't be fair)
Don't you hate it when you can multiply numbers but not strings? So you should correct that, right?
You are to write a function or full program... | stackexchange_codegolf |
A fixed-point combinator is a higher order function \$\mathrm{fix}\$ that returns the fixed point of its argument function. If the function \$f\$ has one or more fixed points, then $$\mathrm{fix} f=f(\mathrm{fix} f).$$
The combinator \$Y\$ has such properties. Encoded in lambda calculus: $$Y=\lambda f.(\lambda x.f(x x)... | stackexchange_codegolf |
Background
For the purposes of this challenge, we'll define a "perfect nontransitive set" to be a set \$A\$ with some irreflexive, antisymmetric relation \$<\$, such that for all \$a \in A\$ we have that \$|\{x \in A|x<a\}|=|\{x \in A|x>a\}|\$.
Okay, now in layperson's terms: \$A\$ is a set of elements with no duplicat... | stackexchange_codegolf |
In this challenge, the goal is to create a pristine truth machine in as few bytes as possible. For reference, a truth machine does the following:
Takes input, which is always 0 or 1
If the input is 0, it is printed and the program terminates
If the input is 1, it is printed forever
A pristine program is one that does... | stackexchange_codegolf |
Following the best security practices, I keep a plain text file with my passwords on my hard drive. In fact, I just copied and pasted one of them to access my PPCG account.
In a lucid moment, I decide that the password should better not remain in the clipboard after its use. Since this happens to me often, I could use ... | stackexchange_codegolf |
Fermat's Last Theorem, mod n
It is a well known fact that for all integers \$p>2\$, there exist no integers \$x, y, z>0\$ such that \$x^p+y^p=z^p\$. However, this statement is not true in general if we consider the integers modulo \$n\$.
You will be given \$n\$ and \$p\$, which are two positive integers with \$n>1\$. Y... | stackexchange_codegolf |
Originally posted (and deleted) by @Tlink, which was most likely inspired from this StackOverflow question.
Since it was a shame it got deleted, because it seemed like a good challenge in general, I figured I'd repost it with proper formatting and rules. (I've tried contacting @Tlink and get his/her permission to post ... | stackexchange_codegolf |
Whilst trying (and failing) have persuade my infant son to eat his dinner, I tried singing to him. Mid way through this song I realised the formulaic structure might lend itself well to code golfing!
The task is to write a program or function which accepts no input and produces the following text:
There's a hole in the... | stackexchange_codegolf |
In this challenge you will take two lists as input and you will zip them. The zip can be defined with this recursive expression:
\$
\mathrm{zip}(a,b) = \begin{cases}
\left[\,\,\right] & a = \left[\,\,\right] \\
[a_0]\mid\mid\mathrm{zip}(b, t) & a = [a_0] \mid\mid t
\end{cases}
\$
or this Haskell program if you would l... | stackexchange_codegolf |
This question is inspired by the cover of the book "Godel, Escher, Bach":
The challenge here is to write a function that tells if three given letters can produce a 3D sculpture that can be read from three sides.
For this exercise, the only letters you can use are 26 5px * 5px bitmaps:
Or in binary (A to Z):
01110 11... | stackexchange_codegolf |
Draw a program or function that will write to STDOUT n times (each for one step) a string that contains a dot . at the location of the walker. The program also needs to write a line every s seconds (or wait s seconds after each line).
A random walk is a mathematical formalization of a path that consists of a succession... | stackexchange_codegolf |
A cruise control has 3 different options to move the handle to set the speed you want to drive with.
Towards you: Adds 1 speed.
Upwards: Increases speed to the next multiple of 10 (e.g. 20-->30, 32-->40)
Downwards: Decreases speed to the next multiple of 10 (e.g. 20-->10, 32-->30)
Input
2 integers: the first is the ... | stackexchange_codegolf |
For those who didn't know, Sigma is a Greek letter which is heavily used in mathematics as the summation sign. Given a string representing an expression depending on \$k\$ that we will denote \$E(k)\$, compute the sum of the results for \$E(k)\$, for each \$k\in\{1,2,3,4,5\}\$. Concisely, you should find \$S\$ such th... | stackexchange_codegolf |
Challenge
Unlike the circumference of a circle (which is as simple as \$2\pi r\$), the circumference (arc length) of an ellipse is hard.
Given the semi-major axis \$a\$ and semi-minor axis \$b\$ of an ellipse (see the image below, from Wikipedia), calculate its circumference.
By definition, you can assume \$0 < b \le a... | stackexchange_codegolf |
Consider a square grid on the plane, with unit spacing. A line segment of integer length \$L\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" a square if it intersects the interior of the square (not just its border).
The challenge
What is the maximum number of squares th... | stackexchange_codegolf |
Based on THIS question.
Given a string, replace each bracket ()[]{}<> with a bracket of the appropriate type so that the brackets match, and the nested brackets cycle as follows:
Outermost ones are ()
Directly inside of () should be []
Directly inside of [] should be {}
Directly inside of {} should be <>
Directly in... | stackexchange_codegolf |
The Meeker numbers are a 7 digit number in form of \$abcdefg\$, where \$a×b=10c+d\$ and \$d×e=10f+g\$. As an example \$6742612\$ is a meeker number, here \$6×7=10×4+2\$ and \$2×6=10×1+2\$, so it is a meeker number.
Additionally, a Meeker number does not have any leading zeros (so \$a \ne 0\$)
The Challenge
Your program... | stackexchange_codegolf |
Background
An atomic bomb has exploded near the fencepost factory!
Since fenceposts are essential for the survival of our civilization, we must rescue as many as possible.
We are sending radiation-resistant robots to search the area, and it is your task to program their artificial vision.
Input
Your input is a rectangu... | stackexchange_codegolf |
Background
For the purposes of this challenge, an n-state cellular automaton is simply a binary function f that takes two numbers from the state set {0, 1, ..., n-1} as inputs, and returns another number from that set as output.
It can be applied to a list of numbers L = [x0, x1, x2, ..., xk-1] of length at least 2 by
... | stackexchange_codegolf |
The challenge
Given point and a path of points, say whether or not the point is in the polygon that is created by the path.
Also return true if the point is on an edge of the polygon.
Input
A list of pairs of integers.
The first 2 integers represent the point.
The remaining pairs (3rd and 4th, 5th and 6th etc.) represe... | stackexchange_codegolf |
Introduction
On 30 May 2020, NASA and SpaceX launched a crewed rocket to the international space station on the SpaceX Demo 2 mission. This is the first time humans have been launched into orbit from American soil since the retiring of the Space Shuttle in 2011, and the first time ever that a private company has launch... | stackexchange_codegolf |
The task is to count the number of disjoint 11 blocks in a 64-bit word, using the minimum number of straight-line instructions. That is, how many nonoverlapping neighbored pairs of 1-bits can be found.
Examples
(imagine leading zeros to fill up to 64 bits)
Input Output
111111 3
1110111 2
111100... | stackexchange_codegolf |
This question was inspired by this HNQ.
About the series
This question is now part of a series about the AGM method. This first post in the series will be about actually calculating the AGM. You may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is ... | stackexchange_codegolf |
You have your very heavy cubical box on a flat floor at position (0,0). All you can do with it is roll it in four cardinal directions (east, north, west, south). Your task is to bring it to a target position, such that the side facing up is the same as before your manipulations.
Make a program or function which receive... | stackexchange_codegolf |
Sociable numbers are a generalisation of both perfect and amicable numbers. They are numbers whose proper divisor sums form cycles beginning and ending at the same number. A number is \$n\$-sociable if the cycle it forms has \$n\$ unique elements. For example, perfect numbers are \$1\$-sociable (\$6\to6\to\cdots\$) and... | stackexchange_codegolf |
Take an array which consists of positive integers or arrays, output if it only contains 2s.
Output should be a truthy or falsey value (Sorry if this destroys answers)
Truthy Test Cases
[2]
[2,2]
[[2],[2,2],2]
[]
[[],[]]
Falsey Test Cases
[1]
[22]
[2,2,2,1]
[[1,2],2]
Standard Loopholes Are forbidden.
Default IO rules ... | stackexchange_codegolf |
Introduction
A farmer needs help calculating the least time it will take him to pick his fruit each day.
Challenge
This farmer has X orchards.
Each orchard has Y fruits in it. If the orchard has no fruits, then it will contain the string "none".
The farmer has a list, this list contains the fruit he must pick.
The f... | stackexchange_codegolf |
Almost every language has a built-in function that can split a string at a given position. However, as soon as you have html tags in the string, the built-in function will not work properly.
Your task is to write a program or function which splits a string at the nth character but does not count characters of html tags... | stackexchange_codegolf |
Don't you love those exploded-view diagrams in which a machine or object is taken apart into its smallest pieces?
Let's do that to a string!
The challenge
Write a program or function that
inputs a string containing only printable ASCII characters;
dissects the string into groups of non-space equal characters (the "p... | stackexchange_codegolf |
In the physical world, invisible ink usually becomes invisible when it dries, and is then is readable if it is exposed to heat or chemicals of some kind. The invisible ink in this challenge will be readable when exposed to highlighting.
Create a full program or function that takes in text from the console (using a prom... | stackexchange_codegolf |
Inspired by this Stack Overflow question: Sorting a list: numbers in ascending, letters in descending. Your task is to solve the following problem and, as this is code-golf, you should do so in as few as bytes as possible.
You should take a list of objects as input containing letters (any reasonable form: string, char,... | stackexchange_codegolf |
A lawn is defined as a rectangular field with of one character surrounded by two layers of visible whitespace. This means two lines above and twos lines below, and a two space padding on the left (the right has visible whitespace, so you do not need to include it).
|||||
|||||
|||||
A mowed lawn is... | stackexchange_codegolf |
Jellyfish is a two-dimensional esoteric programming language inspired by J and written in Python 3. It was inspired by a challenge on PPCG. The name was suggested in PPCG chat as a combination of Jelly, a golfing language inspired by J, and Fish, a two-dimensional esoteric language.
What general tips do you have for ... | stackexchange_codegolf |
The Challenge
Given an arbitrary amount of rectangles, output the total count of intersections of those when drawn in a 2D plane.
An intersection here is defined as a point P which is crossed by two lines which are orthogonal to each other and are both not ending in P.
Example
Each rectangle here is denoted by a 2-tupl... | stackexchange_codegolf |
Let's say I have a .env file with the following contents:
CF_WORKERS_ACCOUNT_ID=abcdef34632114
CF_WORKERS_API_TOKEN=abcdef34632114def3463def3463
FAB_DEV_ZONE_ID=434932843272439874329
I'm doing a screencast, and I want to quickly cat .env to show what's in the file, without broadcasting the exact values, since they're ... | stackexchange_codegolf |
Write a program or function that takes input: all resistors available and a resistance value and outputs a truthy value of whether or not it is possible to get the resistance by using those resistors.
Rules:
Any format for input will do.
There will be at least 1 available resistor and your program should output for at ... | stackexchange_codegolf |
Pretty simple challenge here. Who can make the fastest algorithm (lowest time complexity) to determine whether or not the circle is "boxed in" given the following setup?
Input: Your program receives a pair of numbers (a,b) that denotes the position of a circle on a grid like this with arbitrary dimensions:
Where a-1 i... | stackexchange_codegolf |
Simpler version of this
Task
You must create a program that outputs a triangle of a given size N.
A triangle is made of 3 identical triangles
A triangle of size N should be made of N lines
A triangle's line starts from 1 star, and increases by 2 stars each line
Test Cases:
1 ->
*
* *
3 ->
*
***
*****
... | 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 |
Cops challenge
The Robbers' Challenge
Find a vulnerable answer. That is, an answer which hasn't been cracked yet and which isn't safe yet either.
Crack it by figuring out its language. That is, find any language in which the given program is a valid program (subject to the rules outlined in the Cops' Challenge above)... | stackexchange_codegolf |
Laguerre polynomials are nontrivial solutions to Laguerre's equation, a second-order linear differential equation: \$xy''+(1-x)y'+ny=0\$. For a given value of \$n\$, the solution, \$y\$, is named \$L_n(x)\$. To avoid trivial solutions, the polynomials are non-constant except for \$n=0\$.
The polynomials can be found wi... | stackexchange_codegolf |
I have a pile of clean socks that I want to sort into pairs. Unfortunately, I can only take socks from either end of the pile, not the middle. Further, I can only remove socks from the pile a matching pair at a time. My strategy is to first split the pile into one or more smaller piles. I think some examples will make ... | stackexchange_codegolf |
Computers like binary. Humans like base 10. Assuming users are humans, why not find the best of both worlds?
Your task is to find the first n terms in the sequence A008559 where each term is the binary representation of the previous number interpreted as a base 10 number.
Input
An integer greater than 0. Note that the ... | stackexchange_codegolf |
Background
The language BrainF*** (or simply BF), is an extremely minimal programming language. We're going to strip it back even further by eliminating IO operations; only the sub-langage defined by the operations +-<>[], henceforth referred to as BF-subset, shall be used. The BF variant considered has a tape extendin... | stackexchange_codegolf |
If you throw an ASCII egg in a given direction, you end up with an ASCII splat of size n. It "starts" with one o (the yolk), and continues in a given direction with "lines" consisting of 2 up to n *'s. The *'s are separated by one "space", and the o and all the "lines" of *'s are separated by "lines" of "space".
The di... | stackexchange_codegolf |
Squaring the Square is a process of tiling a square using only other squares. If this tiling only uses squares of different sizes, then it is considered to be perfect. The smallest possible perfect squared square is a 112x112 square tiled using 21 different squares.
I have created the ascii art version of this squar... | stackexchange_codegolf |
In a twist on finding a needle in a haystack, you need to find the largest contiguous haystack containing exactly one needle. Note that you cannot connect cells on diagonals, only left/right/up/down.
Input
An array (or a number of user input lines, your pick) of 'N' (needles) and '#' (hay) characters. Input only contai... | stackexchange_codegolf |
Produce Graham's Number in Magic the Gathering using the fewest number of cards and without using any infinite combos.
Rules:
Producing Graham's number means do anything that requires Graham's number to represent the game state. For example, you could produce Graham's number 2/2 zombie tokens, have Graham's number li... | stackexchange_codegolf |
You will be given as input an infinite stream of positive integers.
Your task is to write a program which outputs an infinite sequence of lists with two requirements:
All lists in the output are finite sub-lists of the input stream.
Every sub-list must be output eventually by your program.
Sub-lists are not necessari... | stackexchange_codegolf |
I need this down to as few characters as possible. I would use Test-NetConnection but I need PSv2 compatability. Any help would be appreciated.
$socket = new-object Net.Sockets.TcpClient
$socket.Connect("192.168.5.5",445)
$socket.Connected
As a note I have tried this but it doesn't work
(new-object Net.Sockets.TcpCl... | stackexchange_codegolf |
Time to dig up your old trigonometry notes from high school! The challenge is to solve the unknown sides and angles of different triangles. And as is customary in code golf, the smallest working code wins.
This is not a trivial problem; my reference implementation in python is currently down to 838 837 characters, but ... | stackexchange_codegolf |
Write a Brainfuck interpreter that can interpret multiple Brainfuck programs embedded within the same source. The syntax is the same except that the instructions must be prefixxed with the number/ID of the targetted program. Example:
1st program
+++[->+<]
2nd program
+>++>+++.
Mashup
1+1+1+2+2>1[1-2+2+2>1>1+2+1<2+1... | stackexchange_codegolf |
Print the phrase And she said, 'But that's his.' using only the following characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ No punctuation or non-alphabetic characters whatsoever. You can use whatever programming language you want. Whitespace is completely allowed. Shortest program wins.
| stackexchange_codegolf |
A Flow Snake, also known as a Gosper curve, is a fractal curve, growing exponentially in size with each order/iteration of a simple process. Below are the details about the construction and a few examples for various orders:
Order 1 Flow Snake:
____
\__ \
__/
Order 2 Flow Snake:
____
____ \__ \
\__ \__/ / __
... | stackexchange_codegolf |
Given a positive integer n write some code to take its prime factorization and replace all of its factors of 2 with 3.
For example
12 = 2 * 2 * 3 -> 3 * 3 * 3 = 27
This is code-golf so the goal is to minimize the byte count of your answer.
Test cases
1 -> 1
2 -> 3
3 -> 3
4 -> 9
5 -> 5
6 -> 9
7 -> 7
8 -> 27
9 -> 9
10 -... | stackexchange_codegolf |
The purpose of this challenge is to graphically depict a walk on the plane, where the direction of each step \$k\$ is determined by the primality of \$k\$ and the parity of its binary expansion. Specifically,
Initial direction is fixed, say North.
All steps have the same length.
The direction of step \$k\$ can be Nort... | stackexchange_codegolf |
A binary convolution is described by a number M, and is applied to a number N. For each bit in the binary representation of M, if the bit is set (1), the corresponding bit in the output is given by XORing the two bits adjacent to the corresponding bit in N (wrapping around when necessary). If the bit is not set (0), th... | stackexchange_codegolf |
Task
Any one of these two:
Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position.
List all the valid positions in any order.
Make sure to describe your input (if not listing all) and output formats.
The 2368 vali... | stackexchange_codegolf |
Introduction:
Before the task, here is what every element does on the map:
Plain land (X): This does nothing.
Destroyed land (-): This is the same as plain land, but destroyed by a bomb.
The active bomb (!): On a map, this will destroy everything in a 3x3 square:
XXXXX XXXXX
XXXXX ... | stackexchange_codegolf |
Challenge
You are given two distinct bit strings of the same length. (For example, 000 and 111.) Your goal is to find a path from one to the other such that:
At each step, you change only one bit (you can go from 000 to any of 001, 010, 100).
You cannot visit the same bit string twice.
The path is as long as possible,... | stackexchange_codegolf |
Background
Lambda calculus is a model of computation using lambda terms.
A variable \$x\$ is a lambda term.
If \$E\$ is a lambda term, the lambda abstraction \$\lambda x. E\$ is a lambda term.
If \$E_1, E_2\$ are lambda terms, the lambda application \$E_1 E_2\$ is a lambda term.
The rule of computation is called \$\b... | stackexchange_codegolf |
For functions \$f, g: \{0,1\}^n \rightarrow \{0,1\} \$, we say \$f \sim g\$ if there's a permutation of \$1,2,3,...,n\$ called \$i_1,i_2,i_3,...,i_n\$ so that \$f(x_1,x_2,x_3,...,x_n) = g(x_{i_1},x_{i_2},x_{i_3},...,x_{i_n})\$. Therefore, all such functions are divided in several sets such that, for any two functions \... | stackexchange_codegolf |
Provided that the input is a monotone sequence of three or more integers:
Output -2 if the sequence strictly decreases. Example: [7,4,3,2]
Output -1 if the sequence monotone decreases but is neither strict nor constant. Example: [6,5,5]
Output 0 if the sequence is constant. Example: [0,0,0]
Output +1 if the sequenc... | stackexchange_codegolf |
Definition
a(1) = 1
a(2) = 1
a(n) = a(n-a(n-1)) + a(n-a(n-2)) for n > 2 where n is an integer
Task
Given positive integer n, generate a(n).
Testcases
n a(n)
1 1
2 1
3 2
4 3
5 3
6 4
7 5
8 5
9 6
10 6
11 6
12 8
13 8
14 8
15 10
16 9
17 10
18 11
19 11
20 12
Reference
Obligatory OEIS A005185
| stackexchange_codegolf |
Before anyone says anything, similar and similar. But this is not a dupe.
Some positive integers can be written as the sum of at least two consecutive positive integers. For example, 9=2+3+4=4+5. Write a function that takes a positive integer as its input and prints as its output the longest sequence of increasing con... | stackexchange_codegolf |
The task is simple. You are given a string with alphabetical words (say "Hello world, this are tests"). You have to return the mode of the lengths of words in the string. In this case, output is 5, as it's the most often length of words in the string.
Definition of an alphabetical word (for this challenge): a string th... | stackexchange_codegolf |
Lexicographic Ordering
For this challenge we will be talking about the lexicographic ordering of strings. If you know how to put words in alphabetical order you already understand the basic idea of lexicographic ordering.
Lexicographic ordering is a way of ordering strings of characters.
When comparing two strings lex... | stackexchange_codegolf |
Challenge:
In the language of your choice, write a program that generates a leaderboard with random scores and outputs it, then take a new score as input and check if it can be placed in the leaderboard, and output which place it is in.
Specifications:
You must generate a list of 50 "random" scores, in descending orde... | stackexchange_codegolf |
Task
Your task is to write a program that will output ASCII boxes at the locations specified by the input.
Input
You will be given a list of numbers. The format here is a bit flexible, in that you can use any deliminator you want (e.g. 1,2,3,4, 1 2 3 4, [1,2,3,4]). The list is in groups of 4 and specifies the xywh of e... | stackexchange_codegolf |
Modern hardware can perform multiplication very fast in a constant latency of 3~4 cycles. But some tiny chips for embedded environments sometimes lack hardware multiplication, which has to be emulated by a series of instructions.
Goal
You are given a primitive CPU with a set of basic operations. Your job is to implemen... | stackexchange_codegolf |
The Challenge
Given two vertexes and a point calculate the distance to the line segment defined by those points.
This can be calculated with the following psudocode
def dist(point, v1, v2):
direction := normalize(v2-v1)
distance := length(v2-v1)
difference := point - v1
pointProgress ... | stackexchange_codegolf |
Write a function that, given N >= 0, finds the Nth number in a standard Gray code.
Example input:
1
2
3
4
Example output:
1
3
2
6
Additional reference
| stackexchange_codegolf |
Imagine some cube which we can cut into smaller cubes without remaining pieces.
Find to how many cubes a cube can be cut.
For example, a cube can be cut into 8, 27 (obviously 3rd powers of integers) and 20 (19 small cubes plus one eight times the size of the others, see image).
See here some help: http://mathworld.wolf... | stackexchange_codegolf |
Background
Conway chained arrow notation is a notation to express very large numbers. It consists of zero or more positive integers separated by right arrows, e.g. \$2 \to 3 \to 4 \to 5 \to 6 \$.
Assuming \$p, q, a_1, \dots, a_n\$ are positive integers and \$X\$ is an abbreviation for a nonempty chain \$a_1 \to a_2 \to... | stackexchange_codegolf |
Cleaning the dishes
In this task, you will be given a bar of soap with a width of 1 or more units. You will also be given a plate, which you will have to clean, using the soap as few times as you can. The plate will be at least 1 character. You will have to output a plate with the 'clean' character representing the pla... | stackexchange_codegolf |
Your task is to create a good multiplication table for others to use. Given an integer \$n\$, generate a multiplication table that displays products up to \$n×n\$. You should start with \$2×2\$ as 1 times any number is itself and that is reflected in the row/column indices. Scientific notation and floating-points are N... | stackexchange_codegolf |
Ah, Tinder . . . the app that takes the code golf approach to online dating. With just a few well-chosen right swipes and a bit of luck (or a cute puppy pic), you too could have more matches than /(?!)/.
This code-golf challenge involves Tinder dates of a very different kind. Given a Tinder version number as input, hoo... | stackexchange_codegolf |
Given a word, get the indexes of each letter in the alphabet.
For example: uncopyrightable becomes: [21, 14, 3, 15, 16, 25, 18, 9, 7, 8, 20, 1, 2, 12, 5]
Convert these indexes to the given numeral system.
For example, if the radix is 36, then the array above would become:
['l', 'e', '3', 'f', 'g', 'p', 'i', '9', '7',... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.