instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
I wrote this function in 48 bytes and I wonder, is there any way to write this code 2 characters shorter?
p=lambda n,c:(n*c)[:n//2]+(n*c)[:n//2+n%2][::-1]
The point of the function is to create a palindrome of length n by using all the characters from the string c. Example: n = 3, c = 'ab'. Result is 'aba'.
Is there s... | stackexchange_codegolf |
Input
A single integer in your language's preferred format, e.g int or an array of digits are all acceptable.
Output
A truthy or falsely value, depending on whether the given number is palindromic (same forwards and backwards)
Rules
Numbers will always be positive, at least two digits long.
This is fastest-algorithm, ... | stackexchange_codegolf |
The sequence discussed in this challenge is a variant of the Descending Dungeons sequence family. Specifically, the sequence generation rules:
(A_b = A's base 10 representation read as a base b number, A = A_10)
A(0) = 10
A(n) = 10_(11_(12_(...(n+9)_(n+10))))
Your goal is to make a program which accepts a nonnegative ... | stackexchange_codegolf |
Given a list of non-negative integers the function \$f\$ replaces every integer with the number of identical integers preceding it (not necessarily contiguously). So
f [1,1,2,2,1,3,3] = [1,2,1,2,3,1,2]
We will say that a list, \$X\$, is in a loop if there is some positive integer \$n\$ such that \$f^n X = X\$. That i... | stackexchange_codegolf |
Definition
A dollar word is a word where when each of its letters is given a cent value, from a = 1 to z = 26, and the letters are summed, the result is 100. Here is an example on CodeReview, and here is a list of dollar words I found online.
Input
Input will be alphabetical from a-z, in your one language's text dataty... | stackexchange_codegolf |
Cops' thread
In this thread, your task is to make a recursion-based program/function to generate any integer series. Robbers will try and find a shorter non-recursive solution over in the Robbers' thread.
Challenge synopsis
In many languages, recursive functions can significantly simplify a programming task. However, ... | stackexchange_codegolf |
To shuffle a string \$s\$, Alice applies the following algorithm:
She takes the ASCII code of each character, e.g. "GOLF" → \$[ 71, 79, 76, 70 ]\$
She sorts this list from lowest to highest: \$[ 70, 71, 76, 79 ]\$
She reduces each value modulo the length of the string (4 in this case), leading to the list \$A = [ 2, 3... | stackexchange_codegolf |
The aim of this challenge is to find an impossibly short
implementation of the following function p, in the langage of your
choosing. Here is C code implementing it (see
this TIO link that also prints its outputs) and a wikipedia page containing it.
unsigned char pi[] = {
252,238,221,17,207,110,49,22,251,196,250,2... | stackexchange_codegolf |
Note: This challenge was inspired by Joe Z's many excellent questions surrounding NAND golfing.
Description
Your goal in this challenge, should you choose to accept it, is to implement a very simple ALU using just NAND gates. The ALU can only perform the the following four operations:
00, meaning increment (wrapping a... | stackexchange_codegolf |
Recently, when doing some code-golf challenge, I came up with with two solutions, in 69 and 105 bytes. It's a remarkable coincidence, because:
69 (decimal) = 105 (octal)
69 (hexadecimal) = 105 (decimal)
What other numbers have this property (using different bases)? You should help me answer this question!
Write a pro... | stackexchange_codegolf |
The Challenge
Given a CSV input, output a proper unicode table using box characters.
Formatting
The table will be formatted using the following rules:
Column width will be equal to the longest value of that column
All table data will be left justified
Each table will assume the first csv row to be the header
The table... | stackexchange_codegolf |
In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will be required to determine if (λ, v) is an eigenpair corresponding to A; that is, whether or not Av = λv.
Dot Product
The dot product of two vectors is the sum of element-wise multiplication. For example, the dot product of the f... | stackexchange_codegolf |
I recently solved a coding challenge in one of the challenge papers that my IT teacher gave to us. It was a seemingly simple, but fun challenge, so I thought it will make fun golfing.
The task
Given an input of a 2x2 matrix that contains 4 strictly positive integers (i.e. non-negative and non-zero), like this:
$$\begin... | stackexchange_codegolf |
Your task
Given a integer input, \$ n \$ (such that \$ n > 1 \$), decide whether it can be written as the sum of (at least 2) consecutive square numbers.
Test cases
Truthy:
Input Explanation
5 1 + 4
13 4 + 9
14 1 + 4 + 9
25 9 + 16
29 4 + 9 + 16
30 1 + 4 + 9 + 16
41 16 + 25
50 9 + 16 + ... | stackexchange_codegolf |
Given string S representing a dollar amount, make change for that amount of money use the least number of coins to make the change and record the amount of each coin in a list. Here are the coins available to use and their value.
Coin : Value
Dollar Coins : $1.00
Quarters: $0.25
Dimes: $0.10
Nickels: $0.05
Pennies: $0.... | stackexchange_codegolf |
Your task is to write a program that:
Runs indefinitely
Produces no output
Consumes an unbounded amount of memory
Specifications
You must list the implementation used for your program. This is relevant because some implementations might preform optimizations while others do not. For example, the LISP code (defun f (... | stackexchange_codegolf |
Inspired by This answer to a Puzzling question
Background - exponentiation by squaring
If you don't want to read the background, or don't understand it, there's a worked example in Java, linked at the bottom of the post.
\$a^{2^{x+1}} = a^{2^{x}} * a^{2^{x}}\$
Therefore to find \$a^b\$ (where \$a\$ and \$b\$ are base-1... | stackexchange_codegolf |
Given 2 brainfuck code snippets A and B, output some brainfuck code C which has the same behavior as running B with the input of As result. Note that C must work for any input that match the following assumptions, as if it were given to A.
You can assume:
Finite input.
both A and B halt.
EOF is consistently 0 or consi... | stackexchange_codegolf |
Your function must accept three numbers in any order:
A signed real number (or ±Infinity) - The number (N) for which you have to generate a number from the range
A signed integer - Minimum of the range
A signed integer - Maximum of the range
Input:
The minimum of the range will always be less than the maximum of the... | stackexchange_codegolf |
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
On the flight to Hawaii for vacation, I'm playing with a deck of cards numbered from 1 to \$n\$. Out of curiosity, I come up with a definition of "magic number" for a shuffled deck:
The magic number of a shuffle is the minimum number ... | stackexchange_codegolf |
Background
In Haskell and many other functional languages, function application f(x) is simply written as f x. Also, this form of function application is left-associative, which means f x y z is ((f x) y) z, or ((f(x))(y))(z).
Haskell also has a binary operator called $. f $ x does function application just like f x, b... | stackexchange_codegolf |
Columnar Transposition Cipher
While I have plenty of programs I have written for more advanced ciphers, I just realised I don't actually have one for one of the simplest: Columnar Transposition. The cipher, in case you don't know, works as follows:
First, you take the key, and write it as numbers. The numbers are made... | stackexchange_codegolf |
Seems like we do not have this one yet, so here we go:
The Challenge
Write a program or function that takes a date as input and outputs the day number of the year. You may not use any builtins for that!
Rules
As usual you may write a full program or a function.
The format of the input is up to you, but it has to conta... | stackexchange_codegolf |
The code:
function L(){N=null;E=[N,N];t=this;h=E;t.u=i=>h=[i,h];
t.o=_=>h==E?N:h[+!(h=h[1])];t.e=(i,l)=>h=(l||h)==E?[i,
E]:[(l||h)[0],t.e(i,(l||h)[1])];t.s=_=>{o="";while(i=t.o())
{o+=i+","}return o}}
For my response to this (old) question: https://codegolf.stackexchange.com/a/196783/72421 (my linked answer has a com... | stackexchange_codegolf |
Your task is to print the titles of the questions with the five highest scores (upvotes minus downvotes) here on CodeGolf.SE, while skipping over any closed, locked and on-hold questions.
Currently these are:
Produce the number 2014 without any numbers in your source code
Showcase your language one vote at a time
Ameri... | stackexchange_codegolf |
Inspired by How do you write dates in Latin?
Challenge
Given a month-and-day date, output that date in abbreviated Latin, as explained below.
Input
Input is flexible, following conventions from other date and sequence challenges. You may choose to:
Take a date in mm/dd or dd/mm format or two separate month,day argumen... | stackexchange_codegolf |
MD5 checksums are relatively easy to crack. For this challenge you will create two separate programs, the first one writing Hello, World! and the second one writing Goodbye Cruel World! but with the source code having identical MD5 hashes.
The source code of both programs must not be identical.
The programs can use th... | stackexchange_codegolf |
I was browsing Stack Overflow when I saw this post in Puzzling in the hot network questions and decided to make a challenge out of it (all credit goes to the creator of the challenge).
Overview
A Chess Number is a number that, when converted to base 18, results in a valid chess coordinate pair, where the first characte... | stackexchange_codegolf |
Everybody has heard of the phrase "be there or be square". So I thought it was time for a challenge about it.
Input
You will take a full absolute directory address as text as input via STDIN or equivalent.
Output
If the directory address exists and is valid, your program will move itself to that folder on your computer... | stackexchange_codegolf |
What happens when the CapsLock key on your keyboard doesn't have a notch in it?
"This hPPENS."
The goal of this program is to consistently emulate keyboard misses where each A press is replaced with CapsLock. Uppercase 'A's from the source should yield the same effect. When CapsLock is enabled, capitalization is revers... | stackexchange_codegolf |
https://en.wikipedia.org/wiki/Losing_chess
This is basically Chess Tournament, but for antichess ;)
Antichess is one of the many chess variants that have been invented. The goal is to lose all your pieces (this may seem a little odd, but it's called antichess for a reason).
The rules
The rules of antichess are very si... | stackexchange_codegolf |
Introduction and Credit
We all know and love our awesome rules to test whether a number is divisble by 11 or 3, which is just some clever sum over the digits of the number. Now this challenge takes this to a new level, by requiring you to compute the sum of the digits and then checking whether the result is a perfect i... | stackexchange_codegolf |
Here is your task, should you choose to accept it: Output (through STDOUT, or whatever is most convenient) some n by m ASCII art that has at least one line of symmetry and is non-empty. Example:
HiiH
iooi
iooi
H!!H
This is a 4x4 example output.
(Note: I define an ASCII character to be in the ASCII range 32-126 plus ne... | stackexchange_codegolf |
Write the smallest program that maps strings injectively to outputs and maps itself to 2020.
To be clear, your program \$p\$ must have the following properties:
every possible input string \$s\$ has a well-defined output \$p(s)\$,
for every pair of strings \$s\$ and \$t\$ with \$s\neq t\$, it holds that \$p(s)\neq p(t... | stackexchange_codegolf |
This challenge will have you count pseudo-polyforms on the snub square tiling.
I think that this sequence does not yet exist on the OEIS, so this challenge exists to compute as many terms as possible for this sequence.
Update: this is now on the OEIS as A309159: Number of generalized polyforms on the snub square tiling... | stackexchange_codegolf |
This is the follow up question to standard Sudoku solver.
You are given a Sudoku grid where . represents an empty cell and the other cells are filled with numbers 0-8 (inclusive).
Rules:
All the numbers in Sudoku must appear exactly once in all left-top to right-bottom diagonals.
All the numbers in Sudoku must appear ... | stackexchange_codegolf |
Write a program that accesses Project Gutenberg's KJV Bible, either from a file called pg10.txt in the working directory or in any other way that is typical for the language, takes a Bible verse reference as input, and prints the corresponding verse, with no newlines except optionally one at the end, as output.
The sta... | stackexchange_codegolf |
Introduction:
Let's take a look at a standard Calculator in Windows:
For this challenge, we'll only look at the following buttons, and ignore everything else:
7 8 9 /
4 5 6 *
1 2 3 -
0 0 . +
Challenge:
Input:
You will receive two inputs:
One is something to indicate the rotation in increments of 90 degrees
The other... | stackexchange_codegolf |
In this optimization challenge you will write a program that sorts a single array by only comparing elements through asking the user on stdout to input comparison results on stdin.
The below protocol is line-based, so everytime you print to stdout or read from stdin it is assumed a newline follows. Throughout the quest... | stackexchange_codegolf |
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
challenge idea by emanresu A
Santa has a bunch of presents wrapped in cuboid boxes of various sizes. As his sled flies above a chimney, a stack of presents will be automatically dropped through it. Santa wants to carefully choose the p... | stackexchange_codegolf |
A repost of this challenge. Meta discussion. Sandbox post. Body of the question similar to the original
Robber's challenge
This cops and robbers is now (08/03/2018) closed to further competing cop entries, as robbers may no longer be competing to crack answers, but feel free to post new answers.
The Cops challenge was... | stackexchange_codegolf |
Challenge:
Inputs:
A string containing printable ASCII (excluding spaces, tabs and new-lines)
A boolean †
Output:
The parts of the String are divided into four groups:
Lowercase letters
Uppercase letters
Digits
Other
Based on the boolean, we either output the highest occurrence of one (or multiple) of these four gr... | stackexchange_codegolf |
Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$. This means that \$(*, S)\$ is a magma
Let's define some basic terms describing the properties of \$*\$. We can say that \$*\$ can have... | stackexchange_codegolf |
The goal of this challenge is to make a program that outputs the nth letter of its source code where n is given as input to the program. Like most quine challenges, you are not allowed to read your source code as a file or use any builtin quine functions.
Input
An integer 0 <= n < len(program).
Output
The nth character... | stackexchange_codegolf |
Challenge
Given a number width, number height, hours and minutes print the time using the following format style:
------ - ------ ------ - - ------ ------ ------ ------ ------
| | | | | | | | | | | | | |
| | | ------ ------ ------ ------ ------ | ... | stackexchange_codegolf |
Objective
Given a nonnegative integer, calculate its NDos-size as defined below, and output it.
NDos' numeral system
The concept of NDos-size comes from the numeral system I made. It represents every nonnegative integer by a nested list, as follows:
With the binary expansion of given nonnegative integer, each entry of... | stackexchange_codegolf |
This is the robber's thread. The cop's thread is here.
A snake matrix is a square matrix that follows this pattern:
3-by-3:
1 2 3
6 5 4
7 8 9
and 4-by-4:
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
Your task is to write a code that takes an input n and creates such a matrix, in the same language as a cop pos... | stackexchange_codegolf |
You host the Olympic Games, and need to build a fantastic pool for the sake of the occasion, but the supervisors often change their mind regarding the dimensions, and need a quick way to rebuild it with the requested size!
Given two integers, L and x, your task is to build a swimming pool of length L and x lanes.
How ... | stackexchange_codegolf |
Your challenge is very simple: output the previous answer, in reverse.
However, as with this similarly-titled question, there's a catch: in this case, you can only use characters from the answer before the last. For example:
Let's say the first answer looks like this:
1 - Python
print('hi!')
And the second answer loo... | stackexchange_codegolf |
This is a code golf puzzle: shortest byte count wins. The program should do the following (standard loopholes obviously forbidden):
Input a hexadecimal number
Convert to octal
Then interpret the digits as if in decimal (765 octal -> 765 decimal)
Divide the number by two
Convert to hexadecimal
Example:
Input: 4a3d
Out... | stackexchange_codegolf |
You wake up and find out that your computer has been stolen! You have a few sensors and scanners, but unfortunately, the footage is incomplete, so you want to find and rank your suspects for further investigation.
Your computer is a rectangle, and your camera caught a bunch of people walking around with packages; howev... | 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 |
Since 2009, Android's version code names have been confectionery-themed. Android 1.5 is Cupcake, Android 1.6 is Donut, Android 2.0 is Eclair, etc.. In fact, the version names are alphabetical!
C -> Cupcake
D -> Donut
E -> Eclair
F -> Froyo
G -> Gingerbread
H -> Honeycomb
I -> Ice Cream Sandwich
J -> Jellybean
K -> Kitk... | stackexchange_codegolf |
A fairly simple challenge: You will receive two inputs, a string and a number (the number may be taken as a string, ie "123" instead of 123)
If the string does not end in a number (ie, it does not match the regex \d$), just append the number to the end of the string.
If the string does end in a number (ie, it matches t... | stackexchange_codegolf |
Inspired by Digits in their lanes and 1, 2, Fizz, 4, Buzz
Introduction
Your task is to generate exactly the following output:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
... | stackexchange_codegolf |
Challenge
Write a program that applies an injective function which takes an ordered pair of strings as input and one string as output. In other words, each input must map to a unique output.
Specifics
The input may be any two strings of arbitrary length, but will consist only of printable ASCII characters (codes \$[32... | stackexchange_codegolf |
In this challenge, all bots are wizards. At the beginning of each round, they create a wand which has a certain chance of successfully stunning another wizard. They then fight, by choosing one bot to attack in each turn. The last bot remaining wins.
Results
500 games, 1000 rounds each
Revenge!: 132101.68886125216
JustE... | stackexchange_codegolf |
Given an \$n \times n\$ matrix of integers, The task is to find the optimal dividing line that maximizes the sum of the integers on the same side as the top left corner. The dividing line should be connected and made up of only vertical and horizontal lines. For an example with a non-optimal dividing line:
[[ 3, 0,... | stackexchange_codegolf |
The reverse-then-add (RTA) sequence is a sequence obtained by adding a number to its reverse, and repeating the process on the result. For eg.,
$$ 5 + 5 = 10 \Rightarrow 10 + 01 = 11 \Rightarrow 11 + 11 = 22 \Rightarrow 22 + 22 = 44 \Rightarrow\text{ }... $$
Thus, 5's RTA sequence contains 10, 11, 22, 44, 88, 176, et... | stackexchange_codegolf |
Given two strings containing only 0 and 1, decide the probability that first appears earlier as a consecutive substring in an infinite random 0/1 stream.
You can assume that neither string is suffix of the other string, so 01, 1, 00, 0 are invalid. (*)
IO format flexible. Your answer should be precise given ideal float... | stackexchange_codegolf |
We define a tree-like list, or trist for short, as the empty list or a list containing only previously constructed trists.
The natural numbers can either include 0 or not, according to your preference.
The task is to create a pair of functions or complete programs f and g (they don't have to be named like this or even ... | stackexchange_codegolf |
COMPLETE
Wumpus season has ended, and with, the lives of many a vicious Wumpus and brave Hunter. As well as some cowardly, immoral and downright stupid Hunters. But at the end of the day, NascarHunter by Dr Heckle came away with the most loot and glory. We salute you, oh brave... driver?
It's open season on Wumpuses, a... | stackexchange_codegolf |
Today your goal is to decrypt a secret message using AES. Given a ciphertext and key you will decrypt and print the message.
Your program may be in any language. It will be run with input on stdin, and its output on stdout will be checked for correctness.
The first line of input on stdin will be the 16 byte key, enco... | stackexchange_codegolf |
Find the max number of Xs you can fit onto a rectangular tic-tac-toe board of length l and height h without ever having 3 consecutive Xs in a row diagonally, horizontally, or vertically.
This is a code-golf challenge so shortest code wins!
Input
A single line containing values l and h, representing the length and heigh... | stackexchange_codegolf |
Background
Famously, the acronym GNU stands for GNU's Not Unix. 1
It's recursive because, after expanding it once, it still contains the acronym GNU, and so must be exanded again:
(GNU's Not Unix)'s Not Unix
And so on, ad infinitum. Visualizing this, we get a kind of Droste effect:
┌─────────────────────────────────... | stackexchange_codegolf |
Note that this challenge requires no handling or understanding of complex numbers.
Given a non-empty square matrix where every element is a two-element (Re,Im) integer list, determine (giving any truthy/falsy values or any two consistent values) whether this represents a Hermitian matrix.
Note that the input is a 3D ar... | stackexchange_codegolf |
Background
Recognizing primality seems like a poor fit for (artificial) neural networks. However, the universal approximation theorem states that neural networks can approximate any continuous function, so in particular it should be possible to represent any finitely-supported function one desires. So let's try to re... | stackexchange_codegolf |
Input
Two non-negative floating point numbers \$x < y\$. You can assume they are close enough to each other that there is no integer between \$x\$ and \$y\$.
Output
A fraction with the smallest possible denomination that lies strictly between \$x\$ and \$y\$.
Examples
Input: 1 and 2
Output: 3/2
Input: 0 and 0.33
Output... | stackexchange_codegolf |
I was playing with the Fibonacci sequence in binary like so (note that the binary representations are written here from smallest bit to largest bit):
1 1
1 1
01 2
11 3
101 5
0001 ... | stackexchange_codegolf |
Background
Supplementary reading 1, Supplementary reading 2
Linear lambda calculus is a limited form of lambda calculus, where every bound variable must be used exactly once. For example, \a b c d e -> a b (d c) e is a valid term in linear lambda calculus. When embedded as a logic system, this enforces each input to be... | stackexchange_codegolf |
I came across an interesting tiling of the plane using squashed hexagons in a popular math book. All the six edges of the squashed hexagon are the same length. Two opposite corners are right angles and the rest four corners are 135 degrees each. This shape allows four squashed hexagons be arranged so that they meet at ... | stackexchange_codegolf |
Given no input, output the following:
_
| ~-_
| o ~-_
| ~ ~-_
| \~~~~~~
| * \
| \
|~~~~~~~~~~\
Note the backslashes are actually \, which is U+FF3C
Trailing whitespace is allowed, however leading whitespace is not.
This is code-golf so fewest bytes in each language wins!
| stackexchange_codegolf |
A tower is made out of layers, each one being one unit shorter than the one below it. Every layer is completely on top of the previous layer. For example, here is a tower along with it's height map:
#
##
###
####
#####
14532
Because the lengths of the layers are the integers from 1 to n, and because the layers ar... | stackexchange_codegolf |
If we have a list of integers we can "squish" one of them by:
decrementing it
replacing adjacent values with its new value
For example in this list:
[1,2,8,3,6]
If we squish the 8 we get:
[1,7,7,7,6]
The question is:
Given a starting array, what is the largest we can make its sum by repeatedly squishing values?
For... | stackexchange_codegolf |
Given a number \$n\$, we have its sum of divisors, \$\sigma(n)\ = \sum_{d | n} {d}\$, that is, the sum of all numbers which divide \$n\$ (including \$1\$ and \$n\$). For example, \$\sigma(28) = 1 + 2 + 4 + 7 + 14 + 28 = 56\$. This is OEIS A000203.
We can now define the sum of sum of divisors as \$S(n) = \sum_{i=1}^{n}{... | stackexchange_codegolf |
Given a positive input \$n\$, output a random pair of primes whose difference is \$n\$. It's fine if there's another prime between them.
Every pair should possibly appear and the program should have zero possibility to fall into infinite loop.
It's promised that such pair exist, but not always infinite, so beware. You ... | stackexchange_codegolf |
Introduction
It is somewhat like DVORAK Keyboard layout , but MUCH harder.
Let's talk about the Korean keyboard first. As you can see in Wikipedia, there is a Kor/Eng key to change between Korean and English key sets.
Koreans sometime type wrong : they attempt to write in Korean on a qwerty keyboard or in English on a ... | stackexchange_codegolf |
emanresu A posted a challenge to reconstruct an ordered list of integers from its unordered set of unordered prefixes. Many users (beginning with xnor's answer) noticed that summing each unordered prefix led to a very short solution. Well, let's cruelly take that possibility away by using data that isn't integers!
A fe... | stackexchange_codegolf |
Introduction
This question is inspired by this great question.
Challenge
Given a number \$N>0\$, output the largest integer \$a^b\$ that is smaller or equal to \$N\$, and the smallest integer \$c^d\$ that is greater or equal to \$N\$, where \$b>1\$ and \$d>1\$.
Output should be a list of two integers, the first being s... | stackexchange_codegolf |
Scientists have made contact with a parallel universe. Just one problem: They write math differently. Help the scientists make a program that can convert normal math expressions to their equivalent in alternate universe math. The connection through the portal is bad so your code needs to be as short as possible
Given a... | stackexchange_codegolf |
Introduction
I have decided that this Christmas, as a "present" to a friend, I wish to purchase the things described in the classic song "The 12 Days of Christmas". The only problem is, I don't know how to calculate the total price!
Your Task
Given a list of prices (in order from first to last), calculate the total pri... | stackexchange_codegolf |
The 52 week challenge is a way to save money. For example, Week 1, you save $1.00. Week 2 you save $2.00, and it continues through the year, adding one more dollar to each week’s savings goal. By Week 52, you’ll set aside $52.00, which will bring the year’s total savings to $1,378! Of course, you can decide how much mo... | stackexchange_codegolf |
For this problem you are given an \$n \times n\$ matrix of integers. The task is to find a pentagon in the matrix with maximum sum. The pentagon must include part (or all) of the x and y axes as two of its sides starting from the top left cell.
All the sides except one must be horizontal or vertical. The remaining si... | stackexchange_codegolf |
Your task is to decipher a non-empty string consisting of printable ASCII characters in the range [32..126].
Reading the string character per character:
each time you encounter a letter in lowercase, associate it with the next letter in uppercase, starting with 'A'
each time you encounter a letter in uppercase, replac... | stackexchange_codegolf |
This is the cops' thread, the robbers' thread is here
A polyglot is a program, that without modification, can run in multiple languages.
Allowed languages
Any language that was made before the challenge and isn't made for the purpose of the challenge, it is allowed, though discouraged, to use languages that are easy t... | stackexchange_codegolf |
In the location-based AR mobile game way of life Ingress the player can hack things called portals in order to get items. (If you are interested in Ingress, you can ping me in chat for more info. Trust me, it's better than Pokémon. If you end up downloading it, remember to choose the Resistance.)
A way to increase hack... | stackexchange_codegolf |
Task
Your task is to take an array of numbers as input, and produce a new one where each number has been shifted both right and left, leaving 0s if no number fills a spot. This process can be represented graphically like this:
[x]
/ | \
[x, 0, x]
This is done with every number in the list, with overlapping number... | stackexchange_codegolf |
This is a rather simple challenge, but I couldn't find any question that was really similar to it. The challenge is to take a frequency in using STDIN or an equivalent, and then output a tone that matches that frequency, in Hz, for 5 seconds. For example
Input: 400
Output: (a tone of 400 Hz with a duration of 5 seconds... | stackexchange_codegolf |
The Challenge
Given a CSV input, output a proper unicode table using box characters.
Formatting
The table will be formatted using the following rules:
Column width will be equal to the longest value of that column
All table data will be left justified
Each table will assume the first csv row to be the header
The table... | stackexchange_codegolf |
An integer \$x\in[0,2^{32}-1]\$ divided by an integer \$d\in{[1,2^{31}]}\$ will produce an integral quotient \$q\$ and a remainder \$r\$, so that \$x=d\times q+r\$.
Any \$q\$, in fact, can be calculated by the following formula.
$$y=\left\lfloor\frac{mx}{2^{32}}\right\rfloor\\q=\left\lfloor\frac{y+f\lfloor(x-y)/2\rfloo... | stackexchange_codegolf |
Write a program that will output its own source code when run, and nothing else. Seems easy, right?
The catch is that when the source code is reversed, your program must output "Hello, World!" exactly, without the quotes.
This is code-golf, so lowest byte count wins.
Edit: Your quine must be a proper quine.
| stackexchange_codegolf |
We're getting markdown tables! I assume this is what they look like:
data
data data data
---------------------
| |
| |
| |
| |
Your task is to make a program or function to generate one of these tables. You'll be given input (string, list of ... | stackexchange_codegolf |
Find a bijective function which maps integers to arbitrarily large tuples of integers. Given the input \$n\$, output the tuple it matches to.
Edit: The empty tuple is included in the mapping.
| stackexchange_codegolf |
Background
Here you have another work-inspired challenge, but from my wife's work in this case. Imagine you have a service that returns the list of nodes in a tree structure (much like the files and folders in a file system), but in no particular order. For every node you get a tuple with its name and the name of its p... | stackexchange_codegolf |
Take as input two strings \$A\$ and \$B\$. Output a string \$C\$ that is \$A\$ but with two characters swapped such that the Levenshtein distance \$d(C,B)\$ is as small as possible. You must swap two characters and you cannot swap a character with itself, although you may swap two identical characters in different po... | stackexchange_codegolf |
Because ARM is the July 2021 LoTM, I figured I'd create the tips thread.
ARM is probably the most successful architecture for the digital world. From mobile phones to supercomputers, ARM is everywhere! Consequently, let's have a thread where we can help each other shorten our ARM code.
One tip per answer, and no stupid... | stackexchange_codegolf |
Yet another Brainfuck parsing problem, but this time... different.
You are working in the Infinite Monkeys Incorporated, the company making Brainfuck programs, to solve various interesting problems (by accident, no less - after all, the company makes random programs). However, it appears that your fast Turing machines... | stackexchange_codegolf |
Given a PPCG User ID, output that user's current username.
Examples
Input -> Output
61563 -> MD XF
2 -> Geoff Dalgas
12012 -> Dennis
foo ->
-3 ->
Rules
Input/output can be taken via any allowed means.
The output must be the full username with proper capitalization and spacing, nothing more and nothing less... | stackexchange_codegolf |
Input:
A positive integer n=p^q where p and q are prime.
Output:
Output the result of q^p
Test cases (in, out):
4, 4
8, 9
25, 32
27, 27
49, 128
121, 2048
125, 243
343, 2187
1331, 177147
3125, 3125,
16807, 78125,
823543, 823543
161051, 48828125
19487171, 1977326743
Scoring:
This is code-golf, so may the shortest code... | stackexchange_codegolf |
Here's a pretty common pattern for sorting algorithms:
def sort(l):
while not is_sorted(l):
choose indices i, j
assert i < j
if l[i] > l[j]:
l[i], l[j] = l[j], l[i]
These algorithms work well because the indices i and j are chosen carefully, based on the state of the list l.... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.