instruction_seed stringlengths 34 53.1k | _source stringclasses 1
value |
|---|---|
Goal
In light of the World Series being around the corner, I need a program that can read the box scores and tell me what inning it is. This is complicated slightly because baseball uses an odd method to record the score. They don't write down the at-bat team's score for the inning until they've scored a run (and are s... | stackexchange_codegolf |
Manually summing a Cubically cube's faces is tedious and time-consuming, sorta like writing code in Cubically itself.
In Most efficient cubifier, I asked you to translate ASCII to Cubically source. One of the answers there uses a cube initialization sequence and then modifies the resulting cube based on the sums of the... | stackexchange_codegolf |
Challenge: Given an expressions made of additions and multiplications, output an expression that is a sum of products. The output must be equivalent to the input modulo the law of distribution. For example, \$1 + ((2 + 5\times 6) \times(3+4))\$ becomes \$1 + 2 \times 3 + 2 \times 4 + 5\times6\times3 + 5 \times 6 \times... | stackexchange_codegolf |
It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as \$0^2+0^2+0^2+1^2\$. Or, in general, for any non-negative integer \$n\$, there exist integers \$a,b,c,d\$ such that
$$n = a^2+b^2+c^2+d^2$$
Joseph-Louis Lagrange pro... | stackexchange_codegolf |
Suppose you have a string \$s_0\$ and someone else has a hidden string \$s_1\$. You don't know what \$s_1\$ is but they tell you that they can get from your string, \$s_0\$, to their string by making a certain number of moves \$d\$. Each move can be one of the following:
Insertion : Add a character anywhere in the ... | stackexchange_codegolf |
Your task is to write a program or function. Its output/return value must follow these rules:
The program outputs 1
The program repeated n times outputs n
The program backwards outputs -1
The program backwards and repeated n times outputs -n
A mix of forward and backward programs will output number_forward - number_ba... | stackexchange_codegolf |
Inspired by Alex's glorious Learn you an R for great good, we are going to humbly recreate Alex's "one true R program" -- but with a twist.
Alex-style Addition works like this -- it has a 90% chance of simply returning the sum of the two numbers given and a 10% chance of recursively Alex-adding the first number and the... | stackexchange_codegolf |
Consider a NxN pixel grid with up to M objects drawn on it, either squares or diamonds:
square
diamond
The objects may overlap, so recognition is hard. The task is to give the minimal possible numbers of objects per shape that can be "seen" in the picture and tell how many squares, how many diamonds, and how many ob... | stackexchange_codegolf |
Intro
Reverse and add is as simple as it sounds, take n and add it to its digits in reverse order. (e.g. 234 + 432 = 666).
If you apply this process repeatedly some numbers will eventually hit a prime number, and some will never reach a prime.
Example
I currently have
11431 rep.
11431 is not prime
11431 + 13411 = 2484... | stackexchange_codegolf |
Challenge
Given an integer n, calculate the sum of all even numbers between 0 and n
Examples
n output
-------------
100 2550
255 16256
1000 2502500
Shortest code in bytes wins
| stackexchange_codegolf |
Your input is an array of numbers: a permutation of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$.
How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 \dots n]\$ in order?
That is: find the lowest \$t \geq 1\$ so that \$[1, 2 \dots n]\$ is a subsequence of \$\text{repeat}(\text{i... | stackexchange_codegolf |
Can't see emoji? Click here.
You will simulate a vending machine. The items are 56 different emojis, which can be represented as two surrogate UTF-8 characters, from: (U+D83C U+DF45) to
(U+D83C U+DF7C). In HTML these emojis can be represented in UTF-16 form as 🍅 through 🍼. In base 10 the first UTF-8 char... | stackexchange_codegolf |
In a 9 by 9 grid some points have been marked. The task is it to
make a program that counts all distinct squares that can be made
using four marked points. Note that squares can also be placed
diagonally (any angle).
Input can be one of the following:
A character string of length 81 containing two distinct characters
... | stackexchange_codegolf |
It seems that many people would like to have this, so it's now a sequel to this challenge!
Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n is a natural number.
Task: Given a prime power pn > 1, return the power n.
Testcases:
input output
9 2
16 4
343 ... | stackexchange_codegolf |
Using the 74 characters from the 2016 time capsule string
H@~*^)$.`~+1A|Q)p~`\Z!IQ~e:O.~@``#|9@)Tf\eT`=(!``|`~!y!`) Q~$x.4|m4~~&!L{%
write N code snippets all in the same language where:
The 1st snippet outputs 1.
The 2nd snippet outputs 2.
The 3rd snippet outputs 3.
... etc. ...
The Nth snippet outputs N (the number... | stackexchange_codegolf |
Background
"Fly straight, dammit" (OEIS A133058) is a sequence of integers, which has these rules:
\$a_0 = a_1 = 1\$
\$a_n = a_{n-1}+n+1\$ if \$gcd(a_{n-1}, n) = 1\$
Otherwise, \$a_n = \frac{a_{n-1}}{gcd(a_{n-1}, n)}\$
In pseudocode:
a[0] = a[1] = 1
if gcd(a[n-1], n) == 1 then
a[n] = a[n-1] + n + 1
else
a[... | stackexchange_codegolf |
Challenge
Given a positive integer, return the product of its divisors, including itself.
This is sequence A007955 in the OEIS.
Test Cases
1: 1
2: 2
3: 3
4: 8
5: 5
6: 36
7: 7
8: 64
9: 27
10: 100
12: 1728
14: 196
24: 331776
25: 125
28: 21952
30: 810000
Scoring
This is code-golf, so the shortest answer in each language... | stackexchange_codegolf |
99 Varieties of Dosa is a popular chain of roadside dosa stalls across South India. This is inspired by a combination of this chain and the classic CodeGolf challenge "99 Bottles of Beer".
Recreate the variant of the menu of the popular '99 Varieties of Dosa' listed below.
(Note: Despite the name, the list contains 10... | stackexchange_codegolf |
Inspired by Alex's glorious Learn you an R for great good, we are going to humbly recreate Alex's "one true R program" -- but with a twist.
Alex-style Addition works like this -- it has a 90% chance of simply returning the sum of the two numbers given and a 10% chance of recursively Alex-adding the first number and the... | stackexchange_codegolf |
We define the hyper-average of an array / list (of numbers) the arithmetic mean of the sums of its prefixes.
For example, the hyper-average of the list [1, 4, -3, 10] is computed in the following manner:
We get the prefixes: [1], [1, 4], [1, 4, -3], [1, 4, -3, 10].
Sum each: [1, 5, 2, 12].
And now get the arithmetic m... | stackexchange_codegolf |
Inspired by: Find an Unrelated Number
Challenge
Given two positive integers as input, output the mathematical operations that can be used on those inputs to generate every number from 1 to n inclusive where n is the smallest prime greater than the sum of the two inputs. If the number cannot be generated using the list... | stackexchange_codegolf |
Challenge:
Given an integer \$n\$, guaranteed to be \$\geq2\$ and a power of 2, we are going to draw multiply boards either side-by-side or below one another, where the first has dimensions of \$n\$ by \$n\$; the second \$\frac{n}{2}\$ by \$\frac{n}{2}\$; the third \$\frac{n}{4}\$ by \$\frac{n}{4}\$; etc.; until the fi... | stackexchange_codegolf |
This challenge is partly an algorithms challenge, involves some math and is partly simply a fastest code challenge.
For some positive integer n, consider a uniformly random string of 1s and 0s of length n and call it A. Now also consider a second uniformly chosen random string of length n whose values are -1, 0, or 1... | stackexchange_codegolf |
Implement a function or program which raises x to the power of y. Inputs are 16-bit signed integers. That is, both are in the range [-32768, 32767]. The output should be in the same range. I chose this range because it should make it possible to do exhaustive testing to ensure all edge-cases are covered.
If the output ... | stackexchange_codegolf |
Given an input integer from 1, 2, ..., n, the task to write code to make a number as close as possible (as measured by absolute distance) to e using only the four mathematical operations +, -, *, / and parentheses (brackets). You can use any of the integers up to n once but don't have to use all the numbers and you are... | stackexchange_codegolf |
This is perhaps one of the classical coding challenges that got some resonance in 1986, when columnist Jon Bentley asked Donald Knuth to write a program that would find k most frequent words in a file. Knuth implemented a fast solution using hash tries in an 8-pages-long program to illustrate his literate programming t... | stackexchange_codegolf |
Write a program which, when every nth character is skipped, it prints n. For example, if every 2nd character is skipped, it prints 2.
Example
n=0
foobar
Output:
0
n=1
foa
Output:
1
n=2
fobr
Output:
2
Rules
If n=0 (no characters are skipped), 0 must be returned.
Must print to STDOUT.
Standard loopholes are forbid... | stackexchange_codegolf |
Merge sort is a sorting algorithm which works by splitting a given list in half, recursively sorting both smaller lists, and merging them back together to one sorted list. The base case of the recursion is arriving at a singleton list, which cannot be split further but is per definition already sorted.
The execution of... | stackexchange_codegolf |
You will be given as input a non-empty list of positive integers. For example:
[1,2,2,2,1]
You want to produce a ragged list as output which has this as its "depth map". This list should have the same elements in the same order but each element n should be at the depth equal to its value.
[1,[2,2,2],1]
This is a li... | stackexchange_codegolf |
Note: this challenge has been posted on the sandbox.
Introduction
This challenge is inspired by 2009 Putnam B1, a problem in an undergraduate mathematics competition. The problem is as follows:
Show that every positive rational number can be written as a quotient of products of factorials of (not necessarily distinct... | stackexchange_codegolf |
Given two positive numbers N >= 2 and N <= 100 create a matrix which follows the following rules:
First Number starts at position [0,0]
Second Number starts at position [0,1]
Third number goes below First Number (position [1,0])
Following numbers goes in "slash" direction
Range of numbers used is [1, N1 * N2]. So, num... | stackexchange_codegolf |
The partial sums of a list of integers [a1, a2, a3, ..., an] are
s1 = a1
s2 = a1 + a2
s3 = a1 + a2 + a3
...
sn = a1 + a2 + ... + an
We can then take the list of partial sums [s1, s2, s3, ..., sn] and compute its partial sums again to produce a new list, and so on.
Related: Iterated forward differences
Input:
A non-em... | stackexchange_codegolf |
Cops section
The robbers section can be found here.
Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.
Challenge
Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4... | stackexchange_codegolf |
Given a list of positive integers, partition the list into two sublists such that the absolute value of the difference of the sums over the two sublists is minimal.
The output of the program should be the (non-negative) difference of these sums.
Examples:
[1,2,3] -> 0 # [1,2], [3]
[2,3,5,7,11] -> 0 # [2,5,7], ... | stackexchange_codegolf |
It's Friday... so let's go golfing! Write code that determines the player's scoring on a hole in a game of golf. The code can be either a function or entire program. As the genre suggests, shortest code wins.
Input (parameters or stdin, your choice):
An integer representing the hole's par, guaranteed to be between 3... | stackexchange_codegolf |
There are \$a\$ honest man(always tell the truth), \$b\$ dishonest man(always tell lie), and \$c\$ random man(tell random Y/N). How many times at least should you ask one of them a yes/no question about who they are, to guarantee you get knowledge of who they are? You may assume that it's possible.
Test cases:
(a,b,c) ... | stackexchange_codegolf |
Strassen's algorithm was the first method of matrix multiplication in subcubic time complexity, namely O(n**log2(7)) for a pair of n*n matrices (assuming the numbers therein are large enough that their O(n*log2(n)) exact multiplication has become the constraint on your performance, and any nested structures and functio... | stackexchange_codegolf |
Homologous series, any of numerous groups of chemical compounds in each of which the difference between successive members is a simple structural unit.
As an example, Alkane is a homologous group where the chemical compounds are in \$C_nH_{2n+2}\$ format. \$CH_4\$ (Methane) is part of the Alkane group because \$CH_4 \t... | stackexchange_codegolf |
An "Egyptian fraction" is a list of distinct fractions with a numerator of \$1\$. For example:
\$
\frac 1 1+ \frac 1 2 + \frac 1 3 + \frac 1 6
\$
The "size" of an Egyptian fraction is just the number of terms involved.
Your task is to take a positive integer \$n\$ and output the smallest Egyptian fraction that sums t... | stackexchange_codegolf |
Most computers store integers in binary, but output them in decimal. However, decimal is just one representation, we just happen to find it convenient.
This challenge is to write some code to output an integer value in shortlex decimal.
What's that?
http://en.wikipedia.org/wiki/Shortlex_order
Shortlex takes the length ... | 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 |
Given a string, reverse it interleavingly. Here's how to do it for abcdefghi and abcdefghij, 0-indexed:
Separate the chars at even indices from the chars at odd indices:a c e g i
b d f h
a c e g i
b d f h j
Reverse the chars at odd indices:a c e g i
h f d b
a c e g i
j h f d b
Interleave into one string again:ahcf... | stackexchange_codegolf |
It is easy to describe a finite state machine that recognizes multiples of 9: keep track of the digit sum (mod 9) and add whatever digit is accepted next. Such a FSM has only 9 states, very simple! By the equivalence between FSM-recognizability and regular languages, there is a regular expression for multiples of 9. Ho... | stackexchange_codegolf |
The Seidel Triangle is a mathematical construction similar to Pascal's Triangle, and is known for it's connection to the Bernoulli numbers.
The first few rows are:
1
1 1
2 2 1
2 4 5 5
16 16 14 10 5
16 32 46 56 61 61
Each row is generated as follows:
If the row number is even (1-indexed):
Bring... | stackexchange_codegolf |
Your goal is to write some code that will output the shortest unique decimal sequence for the input fraction. No two fractions with the same denominator may have the same output, although it's possible for fractions with different denominators to have the same representation.
Take 2 integers as input, the first is the ... | stackexchange_codegolf |
Background
Two numbers, \$a\$ and \$b\$, are said to be connected by a Brussels choice operation* if \$b\$ can be reached from \$a\$ by doubling or halving (if even) a substring (the substring must not be empty and may not contain any leading 0s but it can be 0) in the base-10 representation of \$a\$
*This operation is... | stackexchange_codegolf |
Last time you were required to write program that output a file, such that no byte is same as original file. The request meant to let everyone carry part of information, but it ends up that everyone carry same info to reduce their storage... This challenge is similar.
Write at most 1024 programs that output at least 85... | stackexchange_codegolf |
Task
Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program.
Example with Python
Input: 1
Output:
Traceback (most recent call last):
File ".code.tio", line 1, in <module>
IfYouWantThenThr... | stackexchange_codegolf |
What is the shortest way of generating a random string with a given length and with only alphanumeric characters allowed?
example of a random string: with N = 9 output would be aZua7I0Lk
the given length N can be assumed to be always greater than 0
if necessary you can assume 256 as a maximum value for N, but solution... | stackexchange_codegolf |
This rar file, when decompressed, gives a 65024-byte exe file. Requiring you to output the contents of that file would be absolutely no fun.
But you aren't required to do that. Actually, you're to do something opposite: Output a binary of the same length (65024 bytes), such that no byte equals the byte at same position... | stackexchange_codegolf |
NOTE: Since I'm Dutch myself, all dates are in the Dutch dd-MM-yyyy format in the challenge description and test cases.
Challenge:
Inputs:
Start date \$s\$; End date \$e\$; Digit \$n\$
Outputs:
All dates within the range \$[s,e]\$ (including on both sides), which contain \$n\$ amount of unique digits in their date.
Exa... | stackexchange_codegolf |
Given two strings a and b, count how many times b occurs as a substring in a, but only when it overlaps with another instance of b.
(This means that 1 will never be a valid output, because in order for the substring to be strictly overlapping, there must be at least one other instance for it to overlap with.)
Test case... | stackexchange_codegolf |
Today is November 8th, 2016, Election Day in the United States of America.
If you are a U.S. citizen eligible to vote, then go out and vote if you haven't already before answering this challenge. Do not discuss who you voted for. It only matters that you voted.
If you are not a U.S. citizen or not eligible to vote, the... | stackexchange_codegolf |
Can you decrypt me?
Cops
Cops, post obfuscated code that hides a number \$n\$ (n must not be greater than the program length) inside its code. If \$n\$ chars are changed (no additions or deletions), the program outputs exactly one \$n\$ (any amount of whitespace before or after is allowed.) Otherwise, it outputs someth... | stackexchange_codegolf |
Background
This question is similar to this one. I have provided all of the information needed below. If you are familiar with the other challenge then note that we are ranking all defenses instead of seeing the effectiveness of a single attack. This is important because it means that the tables are inverses of each ot... | stackexchange_codegolf |
Let \$Z\$ be either the integers, the positive integers, or the non-zero integers; pick whatever's convenient. Give two functions \$f\$ and \$g\$, each \$Z \to Z\$, such that:
\$f(g(a)) = g(f(a))\$, for infinitely many integers \$a\$, and
\$f(g(b)) \ne g(f(b))\$, for infinitely many integers \$b\$.
Rules
Many of the ... | stackexchange_codegolf |
Code Golf Challenge
Given a string of 10 characters:
'abcdefghij'
I want to format it in this pattern and print it in the console in a minimum number of characters:
(abc) def-ghij
My solution:
print(f"({s[0:3]}) {s[3:6]}-{s[6::]}")
| stackexchange_codegolf |
What general tips do you have for golfing in TypeScript's type system? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to TypeScript's type system (e.g. "remove comments" is not an answer).
Please post one tip per answer.
If you're not familiar with program... | stackexchange_codegolf |
Find X
I was inspired by math questions in which one is asked to "Find X" for a given shape. Originally, I was just going to have the challenge be to print the x and y location of the character 'x' in a String. But I supposed that would be too simple. So I considered the context they were normally in, and decided findi... | stackexchange_codegolf |
A permutation of a set \$S = \{s_1, s_2, \dotsc, s_n\}\$ is a bijective function \$\pi: S \to S\$. For example, if \$S = \{1,2,3,4\}\$ then the function \$\pi: x \mapsto 1 + (x + 1 \mod 4)\$ is a permutation:
$$
\pi(1) = 3,\quad
\pi(2) = 4,\quad
\pi(3) = 1,\quad
\pi(4) = 2
$$
We can also have permutations on infinite s... | 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 |
Given the signal level L in the range 0-4. Your program should draw the following ASCII art.
When L=0:
....
....
.... ....
.... ....
.... .... ....
.... .... ....
.... .... .... ....
.... .... .... ....
.... .... .... ....
When L=1:
....
... | stackexchange_codegolf |
Tab completion is a useful feature that auto-completes partially written commands. You're going to be implementing it.
For example, if the available commands were ['apply','apple','apple pie','eat'], then a would complete to appl, as all of the commands that start with a also start with appl.
Input/Output
You need to... | stackexchange_codegolf |
This is a rock paper scissors competition. Algorithms will face each other in 100 rounds of rock paper scissors. Except that the algorithms will also be able to read the source code of each other!
Leaderboard
1. Chaos Bot (by Aiden4) - 27 Points, 168 bytes
2. Anti-99%-of-posts (by Lyxal) - 24 Points, 489 bytes
3. Psued... | stackexchange_codegolf |
Is there any javascript-like language? Something that can be interpreted by browsers?
| stackexchange_codegolf |
In the spirit of Patch the Image, here's a similar challenge but with text.
Challenge
Bit rot has afflicted your precious text! Given a paragraph composed of ASCII characters, with a rectangular hole somewhere in it, your program should try to fill in the hole with appropriate text, so that the paragraph blends as best... | stackexchange_codegolf |
In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text.
Your input will consist in a list of list with 3 parameters:
X coordinate
Y coordinate
String
How?
We know that a Cartesian plane contain 2 axes \$(X, Y)\$ and 4 quadrants where the signs of the \... | stackexchange_codegolf |
I like my job, but sometimes it can get a bit tedious and boring. As motivation, I want to know how many hours of work are left before I finally get my two days of weekend and relaxation.
I work every day from Monday to Friday, totalling 38.5 hours, starting at 9am and ending at 6pm.
Every day - except Friday - I get ... | stackexchange_codegolf |
Jimmy has had a busy last week with all these platforms and ropes, and poor Jimmy doesn't even have legs or feet to stand on!
Your job is to take a string containing multiple Jimmys and give them legs and shoes!
Get input in the form of a Jimmy String
Jimmy String => /o\ /o\ /o\
containing only /o\ and
give each ... | stackexchange_codegolf |
Adapted from Tips for restricted source in Python
Just like code-golf, restricted-source pushes one to exploit quirks and hidden features of the Powershell language. Now, We already have a place to collect all these tips for code-golf, those for restricted-source remain transmitted by word of mouth or hidden deep wit... | stackexchange_codegolf |
Challenge
You just entered a room. Here's how it looks (you are the X):
|\ /|
| \/ |
| X |
| |
|----|
You challenge yourself to see if you can reach where you started by following the walls. You go right until you find a wall. Then, you turn clockwise until you are facing parallel to the wall.
For example, if you... | stackexchange_codegolf |
A problem I sometimes encounter is that when writing comments using LaTeX, the comment is too long. Today you will solve this, by writing code which, given a LaTeX math expression, will produce the shortest equivalent expression.
To define equivalent expressions, we will need to specify a (simplified) parser for LaTeX:... | stackexchange_codegolf |
Create a function that accepts a list of dates (unsorted with possible duplicates) and returns the days of the week in one of the following formats:
A format similar to MTWTFSS or SMTWTFS (i.e. beginning with Monday or Sunday), with non-days replaced by an underscore _, illustrated below.
WEEKDAY if all the dates are ... | stackexchange_codegolf |
Background
In Python, function arguments are defined within the parentheses following the function name in the function definition. There are different ways to present function arguments, and they can be categorised into three types:
Positional-only arguments,
Positional or keyword arguments, and
Keyword-only argument... | stackexchange_codegolf |
The hamburger joint maHburger has hired you to write a program for them.
It is simple: make an ASCII hamburger, using the key. Sounds simple right? Well these customers are super picky, but one thing is for sure, they do love onions.
Write a program that accepts the customer's orders, and prints a hamburger with as man... | stackexchange_codegolf |
Another sequence, another challenge.*
Definition
A prime p is in this sequence, let's call it A, iff for every digit d in p's decimal expansion, you replace d with d copies of d and the resulting integer is still prime; zeros are not permitted.
For example, 11 is trivially in this sequence (it's the first number, incid... | stackexchange_codegolf |
A Latin square is a square that has no repeated symbols in either the X or Y columns. For example:
ABCD
DABC
CDAB
BCDA
is one such square. Notice how every column and row contains a permutation of the same 4 letters.
However, our Latin square has a problem: If I were to rotate the second row (DABC) 1 to the lef... | stackexchange_codegolf |
Given a non-negative integer N, output the smallest odd positive integer that is a strong pseudoprime to all of the first N prime bases.
This is OEIS sequence A014233.
Test Cases (one-indexed)
1 2047
2 1373653
3 25326001
4 3215031751
5 2152302898747
6 3474749660383
7 3415500717... | stackexchange_codegolf |
Story
My local pizza delivery introduced new discount. You get 50% discount from every second item on your order.
But being greedy capitalists, they forgot to mention that they will rearrange items the way they need to give you as little as possible.
Example
Imagine you ordered
- Pizza $20
- Pizza $20
- Coke $2
- Coke ... | stackexchange_codegolf |
You have a line with two endpoints a and b (0 ≤ a < b) on a 1D space. When a or b has a fractional value, you want to round it to an integer.
One way to do this is to round a and b each to its nearest integer, but this has a problem that the length of the rounded range (L) can vary while b - a stays the same. For examp... | stackexchange_codegolf |
The Cornu Spiral can be calculated using Feynman's method for path integrals of light propagation. We will approximate this integral using the following discretisation.
Consider a mirror as in this image, where S is the light source and P the point where we collect light. We assume the light bounces in a straight ray f... | stackexchange_codegolf |
Game
In this challenge you will play a made-up turn-based game.
The game is made up of the following elements:
A 8x8 grid with each spot containing nothing (space), a robot (*), a wall (#), or HP (@)
A public stack
Robots
In this challenge, you will be playing as a robot. Each robot has health (starts at 10HP and ca... | stackexchange_codegolf |
Introduction
Let's observe the string abc. The substrings that can be made from this are:
a, ab, abc, b, bc, c
We now need to align them under the initial string, like this:
abc
a
b
c
ab
bc
abc
The order of the string doesn't matter, so this is also perfectly valid:
abc
a
ab
abc
b
bc
c
So, the substring is p... | stackexchange_codegolf |
Given a positive integer \$n\$, your task is to find out the number of partitions \$a_1+a_2+\dots+a_k=n\$ where each \$a_j\$ has exactly \$j\$ bits set.
For instance, there are \$6\$ such partitions for \$n=14\$:
$$\begin{align}&14 = 1_2+110_2+111_2&(1+6+7)\\
&14 = 10_2+101_2+111_2&(2+5+7)\\
&14 = 10_2+1100_2&(2+12)\\
... | stackexchange_codegolf |
Characters in strings are sometimes represented as their ASCII hexadecimal codes. Printable characters have two hex digits in their representation. Swapping those digits leads to another character, which will be our output.
The table of relevant character codes can be found on Wikipedia.
Details
Take a string as input... | stackexchange_codegolf |
You've just been hired by a German car manufacturing company. Your first task, as an engineer, is to write a program that computes the ecological footprint of ASCII strings.
The ecological footprint of character is computed as follows:
Write the character's ASCII code in binary, and count the number of 1's.
For examp... | stackexchange_codegolf |
Let a counting tree be a rooted tree in which every node is labeled with the number of descendants it has.
We can represent such trees as ragged lists with each node being represented by a list containing its label followed by its children. For example the following is a counting tree:
[5,[2,[0],[0]],[0],[0]]
However ... | stackexchange_codegolf |
I am sorry for the very long description. But i think some information of how /proc/self/cmdline works and how it can be used to get a integer input was necessary.
You may skip the sections you don't need.
While part of this task is related to C and Linux, it can be done in any almost language that can start other prog... | stackexchange_codegolf |
You are to approximate the value of:
$$\int^I_0 \frac {e^x} {x^x} dx$$
Where your input is \$I\$.
Rules
You may not use any built-in integral functions.
You may not use any built-in infinite summation functions.
Your code must execute in a reasonable amount of time ( < 20 seconds on my machine)
You may assume that inp... | stackexchange_codegolf |
Cops thread
Robbers,
Write a program in the cop's language using the cop's P string and your own S string, and the amount of each of them specified in the cop's post. Your S string may not exceed the cop's S string in bytes.
The program
Using only strings P and S, write a program which takes a list of 5 or more non-rep... | stackexchange_codegolf |
Write a program that takes in a string where every line consists of the character 0 indented by some number of spaces. The top line is not indented and every other line will be indented by at most one more space than the line just before it.
No lines will have trailing spaces but you may optionally assume there is a si... | stackexchange_codegolf |
An activity I sometimes do when I'm bored is to write a couple of characters in matching pairs. I then draw lines (over the tops never below) to connect these characters. For example I might write \$abcbac\$ and then I would draw the lines as:
Or I might write \$abbcac\$
Once I've drawn these lines I try to draw cl... | stackexchange_codegolf |
Polystrips are a subset of polyominoes conforming to the following rules:
each piece consist of 1 or more cells
no cell can have more than two neighbours
the cells should not enclose a hole
Free polyominoes are distinct when none is a rigid transformation (translation, rotation, reflection or glide reflection) of ano... | stackexchange_codegolf |
Introduction
I defined the class of antsy permutations in an earlier challenge.
As a reminder, a permutation p of the numbers from 0 to r-1 is antsy, if for every entry p[i] except the first, there is some earlier entry p[i-k] such that p[i] == p[i-k] ± 1.
As a fun fact, I also stated that for r ≥ 1, there are exactly ... | stackexchange_codegolf |
Summer Klerance turned in her term assignment for this challenge. Her professor was miffed (but also amused) when he overheard a disgruntled classmate of Summer's saying she got her answers by simulation rather than by the probabilistic methods covered in the course. Summer received a note to see the prof during his ne... | stackexchange_codegolf |
...or is there?
Your challenge is to parse my lunch bill, which contains the base price, tips, discounts, coupons, and extras and find out if my lunch was $0 or less. If this is the input:
12.34
15 tip
25 discount
1.5 extra
2 coupon
Then the output might be false. Here's how it works:
12.34 is the base price.
15 tip m... | 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 |
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 |
You are the treasurer and you have received information that a counterfeit coin has entered the treasury. All you know is that the counterfeit coin is lighter than the original.
Knowing how many coins you have in total and using only a balance scale, you need to determine the minimum number of weighings to determine wh... | stackexchange_codegolf |
Write a program or function that takes in a positive integer N, and outputs an N×N pixel image of Google's "G" logo according to this* construction:
For example, if N is 400, a 400×400 pixel logo should be output, with correct dimensions and colors:
It should look accurate regardless of how large or small N is. e.g... | stackexchange_codegolf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.