instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Your task
Given a string, output the range of ASCII values.
Example
Let's say we have the string Hello.
We get the ASCII values:
H = 72
e = 101
l = 108
l = 108
o = 111
Now, we get the range (max - min):
111 - 72 = 39
Our answer is 39.
Test cases
Input Output
Hello, World! 82
aaaaa 0
Code Golf ... | stackexchange_codegolf |
Description
The Gameboy stores tiles as 2 bit-per-pixel 8x8 images, thus 16 bytes. Every two bytes is a complete row with all of the Low-bits of each pixel in the first byte, and all of the High-bits of each pixel in the second.
Input
Input will be exactly 16 bytes, received through Standard IO in one of the following... | stackexchange_codegolf |
In this challenge you'll be building a program that grows as it traverses through the ages… Until it's 2017.
Challenge
Whenever this challenge description says “program”, you can also read “function”.
Your submission, when executed, will output a program that is THE LENGTH OF YOUR SUBMISSION + 1 bytes long.
When that p... | stackexchange_codegolf |
You are given an array/list/vector of pairs of integers representing cartesian coordinates \$(x, y)\$ of points on a 2D Euclidean plane; all coordinates are between \$−10^4\$ and \$10^4\$, duplicates are allowed. Find the area of the convex hull of those points, rounded to the nearest integer; an exact midpoint should ... | stackexchange_codegolf |
I have a cake shop that specialises in birthday cakes. The cakes that I sell must have candles placed in a circle. You would probably think I can just divide 360° by the number of candles, but the machine for placing candles is quite unique; it uses a list of numbers representing positions of candles, placing them one-... | stackexchange_codegolf |
It's weekend and what are the cool guys doing on weekends? Drinking of course! But you know what's not so cool? Drinking and driving. So you decide to write a program that tells you how loaded you are and when you are gonna be able to drive again without getting pulled over by the cops and loosing your license.
The Cha... | stackexchange_codegolf |
Challenge
To quote Wikipedia:
An octave-repeating scale can be represented as a circular arrangement
of pitch classes, ordered by increasing (or decreasing) pitch class. For instance, the increasing C major scale is C–D–E–F–G–A–B–[C], with the bracket indicating that the last note is an octave higher than the first no... | stackexchange_codegolf |
The famous game of Qwirkle has simple but intricate rules (See part 2 of this question for a summary of the rules!)
The Challenge
You are somehow (text input, function parameter, whatever) given a board of a Qwirkle game, like a snapshot from any current timeframe within a game. This board can be anything from complet... | stackexchange_codegolf |
You just have to ouput exactly all the numbers from 1 to 10 separated by spaces.
Your programme should work all the times even if a random character is deleted before compiling/interpreting.
This is code-golf so shortest code in bytes win!
| stackexchange_codegolf |
The point of the puzzle is to learn about livelocks:
Create a multi-threaded (or a multi-process) program, whose threads (processes) indefinitely try to wait for each other and never finish. Unlike a deadlock situation, the state of threads (processes) in a livelock constantly change as they try to resolve the situatio... | stackexchange_codegolf |
In this question each answer will get a "toolbox" that can be used to construct a program/function. The toolbox will consist of two things:
a list of programming languages
a list of valid characters
You must write a valid program/function in one of the languages provided using only the characters in the toolbox. Yo... | stackexchange_codegolf |
Challenge:
Given a 2D array (8x8) of characters, is the enemy king in check?
The program should return true if and only if the king is currently in check.
Standard chess rules apply.
Specifications:
The game is provided using a 2D array,
where blank space means there is not a piece on that square.
You may assume that t... | stackexchange_codegolf |
Inspired by this.
Background
The evil farmer has decided to burn your wheat field down in order to drive up the prices. To ensure total destruction, he has also soaked your field in gasoline. Even more unfortunately, you happened to be walking on the field when it was lit on fire, and you must get out quickly to surviv... | stackexchange_codegolf |
You're sick of other players smugly announcing "BINGO" and walking triumphantly past you to claim their prize. This time it will be different. You bribed the caller to give you the BINGO calls ahead of time, in the order they will be called. Now you just need to create a BINGO board that will win as early as possible f... | stackexchange_codegolf |
Your Programs:
You'll write two programs (both in the same language). The storage program takes a string from STDIN and stores it somewhere persistent (see below) and then exits without error. The retrieval program takes no input, retrieves the string that was stored, and prints it to STDOUT.
Objective test of Persiste... | stackexchange_codegolf |
We've all seen the signs on motels telling us if there's a vacancy or not:
Typically, these will permanently have the letters of VACANCY lit up, and have the letters of NO lit up if there isn't any room in the motel.
The challenge
The average motel in the U.S. has 200 rooms.
You will write a program/function that take... | stackexchange_codegolf |
When writing a message with fridge magnets, you'll often find yourself substituting a 1 for an I. In this challenge, your goal is to find out if a message can be written using the letters of another message. The allowed substitutions are:
A = 4
B = 8
C = U
E = M = W = 3
G = 6 = 9
I = 1
L = 7
N = Z
O = 0
R = 2
S = 5
Fo... | stackexchange_codegolf |
The Task
You are given a mutable string that matches [a-z]+( [a-z]+)*.
You must mutate it into the string which contains the same words, but in reverse order, so that "hello there everyone" becomes "everyone there hello".
You are not permitted to use more than a constant amount of additional memory (so no copying the ... | stackexchange_codegolf |
Introduction
Putting all positive numbers in its regular order (1, 2, 3, ...) is a bit boring, isn't it? So here is a series of challenges around permutations (reshuffelings) of all positive numbers.
The first challenge in this series is to output a(n) for a given n as input, where a(n) is A064413, also known as the EK... | stackexchange_codegolf |
Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, cat would become catatt, and hello would become helloellolloloo.
Input
Any of the 26 letters of the English alphabet. There may be multiple words separat... | stackexchange_codegolf |
Consider a finite, one-dimensional grid where each cell is marked with one of two symbols (I will use the symbols < and >, but you can use other symbols).
When a pinball is placed on one of the cells, it moves according to the following rules:
If the pinball is on a cell that is marked with <, the pinball moves one ce... | stackexchange_codegolf |
It seems that any Simple Modification of deltas using a consistent function can almost always be done some other shorter way, Dennis.
Thus, the only solution I can imagine to make this harder, is to introduce some sort of inconsistent function.
Sorting.
Your task is to take an array of integers, sort their deltas, and ... | stackexchange_codegolf |
Problem
Given no input write a program or a function that outputs or returns the following string:
(<(<>(<>.(<>.<(<>.<>(<>.<>)<>.<>)>.<>).<>)<>)>)
Rules
Shortest program wins.
Trailing whitespace allowed.
Trailing newlines allowed.
Unused parameters for functions allowed.
| stackexchange_codegolf |
This challenge is about finding the smallest disk that contains some given points. This is made somewhat trickier, however, by the fact that in this challenge, the disk's coordinates and radius must both be integers.
Your input will be a list of points with integer coordinates x and y. You can take this as a list of tu... | stackexchange_codegolf |
In Imperial China, ranks in society were not decided by birth or wealth, but by a person's ability to excel in the Imperial Examinations. The Jade Emperor, divine ruler of the Heavens, has called for all his subjects to be examined to determine their worth, and whom to next give the Divine Mandate to rule China.
Rules ... | stackexchange_codegolf |
(yes, "generating generating" in the title is correct :) )
Context
In middle (?) school we are taught about sequences and, in particular, we are taught about linear sequences where the nth term is generated with an expression of the form an + b, where a and b are some coefficients. In this challenge, we will deal with ... | stackexchange_codegolf |
Alphys, the Underground's Royal Scientist, has finished a prototype for a new puzzle. However, she can't seem to find anyone willing to test it.
The rules of her puzzle are as follows:
The goal is to get to the right side, starting from the centermost tile on the left side. For puzzles with even-numbered heights, star... | stackexchange_codegolf |
Background
Sudoku is a number puzzle where, given an \$ n \times n \$ grid divided into boxes of size \$ n \$, each number of \$ 1 \$ to \$ n \$ should appear exactly once in each row, column and box.
In the game of Chess, the King can move to any of (at most) 8 adjacent cells in a turn. "Adjacent" here means horizonta... | stackexchange_codegolf |
Introduction
Just on Hacker news, John Resig contemplates
transforming a query “foo=1&foo=2&foo=3&blah=a&blah=b” into one that looks like this: “foo=1,2,3&blah=a,b", https://johnresig.com/blog/search-and-dont-replace/.
He claims "being 10 lines shorter than Mark’s solution".
Query strings consist of sequences of name-v... | stackexchange_codegolf |
Objective
You're on a nonempty list of integers that wraps around. You start at the leftmost entry of the list, and keep jumping to the right to the amount of the integer entry you're at.
Eventually, you'll end up in a cycle. The objective is to output the length of this cycle.
I/O format
Provided that the inputted lis... | stackexchange_codegolf |
Very few, if any, programs or applications have utilised the proposed spec for WOM which was initially thought up in the early 1970s as a polar opposite to ROM, so your task is to take a dataset of n Integers and simulate storing it to a WOM schema as a proof of concept.
Your array must contain 1 or more integers. Smal... | stackexchange_codegolf |
In Python it is often necessary to use str.replace(a,b), however .replace is rather long and feels unnecessary. So is there a shorter alternative to str.replace.
Alternatively is there a similar trick to how you can use r=range for golfing for str.replace?
Example code for golfing
m=input()
f="hello"
print m.replace('t... | stackexchange_codegolf |
Input
A non-empty encoded string consisting of printable ASCII characters (in the range 32-126), where some missing letters have been replaced with _.
Output
A decoded string of the same length with all letters in lowercase, including the missing ones.
How?
Edit: As mentioned by @Deusovi in the comments, this is a vari... | stackexchange_codegolf |
Introduction
Some days ago I needed a metronome for something. I had none available so I downloaded an app from the App Store. The app had a size of 71 MB!!!
71 MB for making tic-toc...?!
So code-golf came into my mind and I was wondering if some of you guys could improve this.
Challenge
Golf some code that outputs s... | stackexchange_codegolf |
Your task: given an integer n, generate an embedded hexagon pattern following the below rules, to the nth depth.
An embedded hexagon has the basic shape of this: (n=0)
__
/ \
\__/
Embedded Hexagons n=1 and n=2:
____
/ \ \
/\__/ \
\ /
\____/
________
/ \ \ \
/\__/ \ \
/\ ... | stackexchange_codegolf |
Implement the shortest Sudoku solver using guessing. Since I have received a few request I have added this as an alternative question for those wishing to implement a brute force sudoku solver.
Sudoku Puzzle:
| 1 2 3 | 4 5 6 | 7 8 9
-+-----------------------
A| 3 | 1 |
B| 6 | | 5
C| 5 | |... | stackexchange_codegolf |
Definition
Given some string return an integer whose digits are the number ocurrences of a-z (case insensitive, in alphabetical order) in that string. Any character with 0 instances is skipped. Characters with 10 or more instances will define 2 or more digits of the returned integer. For example, aaaaaaaaaaaaaaaaaaaaaa... | stackexchange_codegolf |
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
I've got an infinite supply of \$n\$-dimensional chocolate for some positive integer \$n\$. The shape of the chocolate is not important. You may assume that they are just \$n\$-dimensional hypercubes with side length \$1\$.
To celebrat... | stackexchange_codegolf |
In a fictional 2D world, a set of 2D printing instructions for an object can be represented by a list of integers as follows:
1 4 2 1 1 2 5 3 4
Each number represents the height of the object at that particular point. The above list translates to the following object when printed:
#
# # #
# ###
## ####... | stackexchange_codegolf |
CHALLENGE
This is a fastest-code challenge.
Count how many n-dimensional hypercubes with n=1,2,3,4 exist, with vertices labeled with either 1 or 0, such that there does not exist any rectangle formed by 4 vertices such that one diagonal is 1-1 and the other diagonal is 0-0. To be more clear, the forbidden rectangles ha... | stackexchange_codegolf |
I have an issue with my keyboard (more likely an issue with my browser). Some times when I click on a new text field and begin typing all my text comes out backwards. After a very short amount of time (for the purpose of the challenge we will say it is 10 milliseconds) it resumes typing forwards again. It seems that ... | stackexchange_codegolf |
You task for today: draw a dragon curve!
In case you don't know what a Dragon Curve is, here is an introductory ViHart video (Really cool, please watch!)
Your task: draw a dragon curve, iterated at least 9 times. You don't have to show iterations 1 through 9, you just have to show the final curve produced after complet... | stackexchange_codegolf |
Every now and again, I'll encounter a large string of alphabetical text encoded as numbers from 1-26. Before I knew that I could just google a translator online, I had to personally, painstakingly copy and paste the entirety of the encoded text into a text document and translate it myself.
Thankfully, I did know about ... | stackexchange_codegolf |
The unnecessary and convoluted story
I am walking around manhattan, block by block and my feet have gotten tired and want to go back home.
The traffic is pretty bad, but fortunately I'm very rich and I have a helicopter on standby at the hotel. But I need them to know how much fuel to pack for the flight and for that t... | stackexchange_codegolf |
Background
The nuclear industry has term, SCRAM, used to describe a quick shutdown of the reactor. There's a fun myth that it stands for "Safety Control Rod Ax Man," the role which served to shut down the Chicago Pile if it got too hot by literally cutting a rope with an ax (although this was debunked).
The US Nuclear... | stackexchange_codegolf |
Write a function which takes a date and returns the day of the week of the next February 29th after that date.
The input is a string in the ISO Extended format: YYYY-MM-DD (e.g. May 27th, 2010 would be "2010-05-27").
The output is a string which is the name of the day of the week (e.g. "Monday"). Capitalization doesn'... | stackexchange_codegolf |
Do you ever look at 3D shapes and think that we have 2 many dimensions. So let's make 3D into 1D! (See what I did there?)
Task
Given a 2D representation of a cube (layout below), flatten it into a single string, based on pointers.
The CUBE
This is the layout of the cube filled with no-ops (,) and pointers at the corner... | stackexchange_codegolf |
Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each one occurring.
Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an e... | stackexchange_codegolf |
Intro/Background
I was looking at "You Had One Job" pictures lately, and noticed an old favourite of mine:
And I said to myself: "I need a program that can generate text like that".
So I devised a set of rules for character swapping and wrote a CGCC challenge!
The Challenge
Given a single string as input, output a str... | stackexchange_codegolf |
Given N decanters (0 < N < 10) with that can hold C0 ... CN-1 liters (0 < C < 50) and a goal G liters, please determine if it is possible to reach that goal using only the following actions:
Fill a decanter
Empty a decanter
Pour from one decanter to another until the one being poured to is full or the one being poured... | stackexchange_codegolf |
An alphadrome is a word in which each letter in the first half of the word "reflects" its alphabetical "opposite" in the second half of the word. Write a program or function that returns truthy if the given word is an alphadrome and falsey otherwise.
For example, BEEB is a palindrome. Its first letter B "reflects" its ... | stackexchange_codegolf |
Introduction
Our goal is to efficiently find the maximum of a large amount of (redundant) data.
We define the outer product of vectors \$A\$ and \$B\$ as a matrix containing the products of all entries of \$A\$ with each entry of \$B\$. (see outer Product)
$$
A\otimes B := A\cdot B^T = \left(\begin{array}{rrr}
A(1)\cdo... | stackexchange_codegolf |
The flag of Bangladesh is very simple. It looks like below:
The flag will be in bottle green (#006a4e) and rectangular in size in the proportion of length to width of 10:6, with a red circle in near middle. The red circle (#f42a41) will have a radius of one-fifth of the length of the flag. This image will help you to ... | stackexchange_codegolf |
The game is played on a 1x8 board with the following setup:
KNR..rnk
White's pieces are on the left, while black's pieces are on the right.
The king (K) can move 1 space in any direction.
The knight (N) can jump 2 spaces in any direction, regardless of bordering pieces.
The rook (R) can move any number of spaces in an... | stackexchange_codegolf |
In my last challenge, you were asked to find all rectangles given a m x n grid of them. However, it turned out to be very trivial as there actually was a mathematical formula I did not even know about to solve the problem! So now, for a little bit more of a challenge, how about calculating the number of unique rectangl... | stackexchange_codegolf |
inputs / outputs
your program/function/routine/... will be a predicate on two tuple sequences; call it relation ≡. for the purpose of simplicity we use natural numbers:
the input will be two list of pairs of numbers from ℕ (including 0); call them Xs and Ys
the output will be a "truthy" value
specification
≡ checks t... | stackexchange_codegolf |
Background
Jelly's arithmetic atoms vectorize automatically. In fact, x + y is well-defined whenever x and y are numbers or ragged arrays of numbers. Jelly's source code implements this behavior using a generic vectorizer, but for this challenge, we'll only consider addition of integers and nested integer arrays.
Defin... | stackexchange_codegolf |
Inspired from Is this site down or is it just me?
Challenge
You have to print if a website server is online or not, for you.
Input
The domain name, like codegolf.stackexchange.com
Output
1/True if online
0/False if offline
Rules
Any kind of web access is allowed
URL shorteners allowed
Except 2 no. Rule, all standa... | stackexchange_codegolf |
Your job is to simulate a couple of keystrokes that a user types in.
Input
A string array or string with a delimiter of your choice (outside the range 32-126) containing at least one 'keystroke'.
This array will only contain two types of string: passive keystrokes (single chars) and commands (chars within brackets [ ... | stackexchange_codegolf |
Story
Martians have been observing Aussie rules football matches from space with great curiosity. Having totally fallen in love with the game, they have been inspired to start their very own football league. However, being dim-witted creatures, they are unable to comprehend the scoring system.*
We know that in Aussie r... | stackexchange_codegolf |
In this code-challenge you will write a hash function in 140 bytes1 or less of source code. The hash function must take an ASCII string as input, and return a 24-bit unsigned integer ([0, 224-1]) as output.
Your hash function will be evaluated for every word in this large British English dictionary2. Your score is the ... | stackexchange_codegolf |
The challenge here is to find the longest uninterruped arc around a unit circle with a random amount of points distributed in random positions around it.
Here is a diagram to assist my explanation:
The red line indicates the largest arc between any two points that is not interrupted by any other points. The challenge ... | stackexchange_codegolf |
Remember the kids game, 'Duck, Duck, Goose'? No? Me neither.
The challenge
Print the word 'duck' on individual lines an indeterminate amount of times.
Print the word 'goose'.
Your program ends.
The rules
Attempt to play the game in the fewest bytes.
There must be at least one duck.
There must be exactly one goose, a... | stackexchange_codegolf |
I came across this picture, which I initially questioned and thought about posting to Skeptics. Then I thought they'll only tell me if this one case is true, but wouldn't it be great to know how true any "rule" really is? Today you're going program a skeptic-bot
Challenge
Write a program or function which when given a ... | stackexchange_codegolf |
Example
Input -> 5
Output -> 55555
Input -> 12
Output -> 121212121212121212121212
Criteria
Least number of bytes wins!
| stackexchange_codegolf |
Your task is to write some code that outputs an OEIS sequence, and contains the name of the sequence in the code (A______). Easy enough right? Well here's the catch, your code must also output a second separate sequence when the name of the sequence in the code is changed to the name of the second sequence.
Input Out... | stackexchange_codegolf |
The challenge
Write a program or function which takes a string input as a function parameter or from stdin and determines if it is a valid FEN string.
Input
You can assume the input will only ever include the following characters (case sensitive)
pkqrbnPKQRBN12345678/
The length of the input will always be a minimum of... | stackexchange_codegolf |
Inspired by Make a Rectangle from a Triangle.
Task
There is a famous formula on the sum of first \$n\$ squares:
$$
1^2 + 2^2 + \dots + n^2 = \frac{n(n+1)(2n+1)}{6}
$$
It is known that this number is composite for any \$n \ge 3\$.
Now, imagine a collection of row tiles (a tile of shape \$1 \times k\$ with the number \$k... | stackexchange_codegolf |
Oh no! I have a theory test soon and I don't remember the scales yet! Help me remember my major scales by printing the following:
7♯ - C♯ D♯ E♯ F♯ G♯ A♯ B♯ C♯
6♯ - F♯ G♯ A♯ B C♯ D♯ E♯ F♯
5♯ - B C♯ D♯ E F♯ G♯ A♯ B
4♯ - E F♯ G♯ A B C♯ D♯ E
3♯ - A B C♯ D E F♯ G♯ A
2♯ - D E F♯ G A B C♯ D
1♯ - G A B C D ... | stackexchange_codegolf |
Background
In X11 (a windowing system used by a lot of Unix-like OS), what you would call the clipboard behave a bit differently than on other OSes like MacOS or Windows. While the "traditional" clipboard using ctrl+v/ctrl+c works, there is also another clipboard, called PRIMARY selection, that behave as following:
wh... | stackexchange_codegolf |
Given (in any structure; flat list, two lists of lists, a tuple of matrices, a 3D array, complex numbers,…) the coordinates for two non-degenerate triangles ABC=[[Ax,Ay],[Bx,By],[Cx,Cy]] and PQR=[[Px,Py],[Qx,Qy],[Rx,Ry]], determine if they are similar, that is,
they both have the same shape, or one has the same shape ... | 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 |
This challenge is inspired by Fortran's idiosyncratic implicit typing rules. Your task will be to determine the data type of the object GOD according to the implicit typing rules explained below.
Background
Fortran 77 has six data types: CHARACTER, COMPLEX, DOUBLE PRECISION, INTEGER, LOGICAL, and REAL. Any object not e... | stackexchange_codegolf |
Write a program that outputs all 64 layers of this representation of Graham's number from Wikipedia:
Your output must exactly match this ASCII version (in which ^ represents Knuth's up-arrows and combinations of slashes and underscores represent the large horizontal curly brackets):
3^^................................. | stackexchange_codegolf |
This challenge is inspired by the same task I read some time ago in CACM.
There are many ways to sort stuff. Most attempt to sort in as few operations as possible (= as fast as possible). However, it is also possible to consider how few resources you might require to sort stuff, which seems more fitting for a codegolf ... | stackexchange_codegolf |
Inspired by this building (United States Air Force Academy Cadet Chapel, Colorado)
Your task is simple, given a positive integer n, output the spiked building to size n
Testcases
1
->
^
/|\
/.|.\
/..|..\
_______
2
->
^ ^
/|\/|\
/.|..|.\
/..|..|..\
__________
7
->
^ ^ ^ ^ ^ ^ ^
/|\/|\/|\/|\/... | stackexchange_codegolf |
Bitshift Variations in C Minor by Robert Miles is a Code Golf music piece written in C (with some additional bash commands). It was originally presented in a 2016 Computerphile video Code Golf & the Bitshift Variations. You can listen to clean renderings of it here (by Lucia Ceionia).
The original 2016 source code pres... | stackexchange_codegolf |
Your task is to create a program that performs a bubble sort on a given array until it is sorted.
Algorithm
In order to qualify as a bubble sort, the program must operate as follows:
Each pass goes through the array, looks at every two adjacent elements in turn, and potentially swaps them.
Each pass goes through the ... | stackexchange_codegolf |
Let's have a tank war!
Partially inspired by Destroy Them With Lazers
Objective
Your task is to control a tank. Move around and shoot other tanks and obstacles in the 2D battlefield. The last tank standing will be the winner!
Map format
Your tank will be on a 2D field based on an n by n grid of unit squares. I will dec... | stackexchange_codegolf |
Consider an arbitrary set of letters \$L\$. It may either be \$\{A, B, C\}\$, \$\{M, N, O, P\}\$, \$\{N, F, K, D\}\$, or even contain all the 26 letters. Given an instance of \$L\$ and a positive integer \$n\$, how many \$n\$-letter words can we build from \$L\$ such that no adjacent letters are the same (so for exampl... | stackexchange_codegolf |
Given a matrix, the goal is to ensure all the values in each column occur at least once, while at the same time doing so requiring the least possible amount of rows. Fastest solution wins.
Note: a value in one column (e.g. 1) is considered different from the same value in another column.
Expected output: an array/list... | stackexchange_codegolf |
Let's say I'm ten steps away from my destination. I walk there following the old saying, "Two steps forward and one step back". I take two steps forward, one back, until I'm standing exactly on my destination. (This might involve stepping past my destination, and returning to it). How many steps did I walk?
Of course, ... | 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 |
Introduction
The Babylonians had a clever method for finding square roots. To find the square root of a number N, you start with a guess, then refine it by repeatedly evaluating a line of computer code (or papyrus scroll equivalent):
guess = (guess + N/guess) / 2
If the guess is smaller than sqrt(N), N/guess must be ... | stackexchange_codegolf |
Write 2 programs in the same language which count the number of shared subsequences of consecutive elements from 2 given sequences.
For example, given "test" and "enter", there are 5 shared subsequences of consecutive elements:
t
t
e
e
te
One possible algorithm consists in counting, for each subsequence of consecutive... | stackexchange_codegolf |
Background
We define the prime-counting function, \$\pi(x)\$, as the number of prime numbers less than or equal to \$x\$. You can read about it here.
For example, \$\pi(2) = 1\$ and \$\pi(6) = 3\$.
It can be shown, using dark magic, that
\$ \lim_{x \to \infty} \frac{\pi(x)}{x/\log x} = 1 \$
which means we can approxima... | stackexchange_codegolf |
Your function must accept one string and return the opposite
The opposite string is a string where all characters go in reverse order, all letters are replaced with the opposite mirror letter from the English alphabet and are changed in case, and all digits are replaced with opposite mirror digits
opposite mirror for l... | stackexchange_codegolf |
This is a cops-and-robbers puzzle, the cops' thread can be found here.
Your task will be to find an anagram of the provided programs in the cops' thread that performs its left inverse.
Once you crack an answer post the solution as an answer below and notify the original answerer.
You will be scored on the number of pro... | stackexchange_codegolf |
Description
Given an object (json), write code to extract all the keys from it. This is a question that I really wanted to ask everybody for a long time ago but I did not have time to write it up. It can be helpful in some cases in your daily work.
Rule:
You can use any parse function to get the JSON object, it does n... | stackexchange_codegolf |
Task
Given an array of non-negative integers a, determine the minimum number of rightward jumps required to jump "outside" the array, starting at position 0, or return zero/null if it is not possible to do so.
A jump from index i is defined to be an increase in array index by at most a[i].
A jump outside is a jump wher... | stackexchange_codegolf |
Given is any integer x > 0 and any base y > 3.
Sum all digits of x (if written in the set base).
Multiply this by the highest possible digit (is always base -1).
Repeat until this value is (y - 1) ^ 2
Searched is the count of iterations and the steps.
Example 1:
x= 739
y= 7
searched: (7 - 1) ^ 2 = 36
based: (b7)2104... | stackexchange_codegolf |
Gringotts isn't just a vault, but a reputable financial institution and wizards need loans too. Since you don't want to be screwed over by the Gringotts goblins, you decided it would be a good idea to write a program to calculate interest. Interest is compounded only yearly.
Your task is to calculate total owed amount ... | stackexchange_codegolf |
Your task is to print a number. Simple, right? It is simple, but not as simple as this. The first answer is to print the number 1, the second answer is to print the number 2, etc.
Rules
The first answer must print 1, and the nth answer must print n.
The first answer may be of any length.
Whitespace, comments, etc. are... | stackexchange_codegolf |
Your regex will receive a string of the form
!XX!
#<extra>
where X is any hexadecimal digit (0-9 and A-F capital letters only), and <extra> is a character sequence to your choosing. (perhaps something like 0123456789ABCDEF0 could be useful?)
You may use any regex flavour.
Scoring will be calculated as: find regex len... | stackexchange_codegolf |
Introduction
In the strange world of integer numbers, divisors are like assets and
they use to call "rich" the numbers having more divisors than their reversal, while they call "poor" the ones having less divisors than their reversal.
For example, the number \$2401\$ has five divisors : \$1,7,49,343,2401\$, while its r... | stackexchange_codegolf |
Introduction
Finding the closest power to a number is a common enough problem. But what if you need both the next-highest and next-lowest power? In this challenge you must find the closest powers to a given number - the 'power sandwich' if you will, where the given number is the filling and the powers are the bread. Mm... | stackexchange_codegolf |
Given integer n, output the smallest exponent e greater than 1 such that n^e contains n as a substring.
For example, for 25, the answer should be 2, as 25 ^ 2 = 625, which contains 25 as a substring, but the answer for 13 should be 10, as 13 ^ 10 = 137858491849, so 10 is the lowest exponent for which the result contain... | stackexchange_codegolf |
A polyomino with \$n\$ cells is a shape consisting of \$n\$ equal squares connected edge to edge.
No free polyomino is the rotation, translation or reflection (or a combination of these transformations, i.e. an isometry) of another (they're equal).
The sequence of free polyominoes with \$n\$ cells is as follows:
1, 1, ... | stackexchange_codegolf |
Shuffling a deck of cards is hard for kids, so they must figure out ways to get a reasonable well shuffled deck as simply as possible.
One way to do this that gives reasonably good results is:
Take the top card out and insert it a random place in the deck
Take the bottom card out and insert it in a random place in the... | stackexchange_codegolf |
At a party, I was introduced to the game LCR. Now it's not a great game as there's no skill but only random chance. But it got me thinking, I could code this, and I made a quick program in R to model the game.
Rules of the game modified from Wikipedia to match how we played:
Each player receives at least 3 chips. Pla... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.