# What is the Sandbox?

This "Sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to the main page. This is useful because writing a clear and fully specified challenge on the first try can be difficult. There is a much better chance of your challenge being well received if you post it in the Sandbox first.

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it. When you think your challenge is ready for the public, go ahead and post it, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

## Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

• How are tags added to questions? – guest271314 Jan 9 at 7:51
• @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] – DJMcMayhem Aug 29 at 15:19
• Why no featured anymore? Can't we have it auto-added or something? – JL2210 Sep 26 at 15:57
• @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary – caird coinheringaahing Sep 29 at 13:43

# Product of Shuffle Algebra

Compute the shuffle product of two elements of a Shuffle Algebra.

## Definitions

1. An Alphabet is a set of symbols. For this challenge it is $$\A = \{a,b,c,\ldots,z\}\$$. Let us use bold letters for variables that denote elements of the alphabet.
2. A Word is a tuple of of arbitrary size where each entry is an element of our alhpabet. Let $$\W\$$ be the set of words. Instead of writing a word as $$\(p,p,c,g)\$$ we just omit the unnecessary symbols and write it as $$\ppcg\$$. We write the empty word as $$\\varepsilon = ()\$$. Let us use lower case greek letters ($$\\alpha, \beta, \gamma, \ldots\$$) for variables that denote words.
3. The shuffle algebra $$\S\$$ (simplified for the purpose of this challenge) is a set of $$\\mathbb Z\$$-linear combinations of words. This means that each element consists of a few words which each have an integer associated with them (the coefficients), which are then formally summed up. Here are some examples: $$\begin{array}[l] \\ a \\ b \\ 5\varepsilon = 5\\ a + (-5)b = a-5b \\ a + 2a = 3a \\xy - 3code +5golf +5se \end{array}$$ Note that terms (that is a word with it's coefficient) where the coefficient is zero are considered as $$\0\$$ and are not listed. Let us use uppercase letters form the greek alphabet ($$\ \Gamma, \Delta, \Phi, \Psi, \ldots \$$) letters for variables denoting an element of the shuffle algebra.
4. We can add elements of the shuffle algebra just as you'd expect: The coefficients of equal words are just summed. for instance let \begin{align*} A &:= aq + 3bccd + 5cg \\B &:= -3bccd + 6cg + 5qq .\end{align*} Then \begin{align*} A+B &= aq + 0bbcd + 11cg + 5qq \\&= aq + 11cg + 5qq.\end{align*}
5. We multiply elements of the shuffle algebra using the shuffle product denoted by the symbol $$\⧢\$$. We can recursively define it as follows:

A. First we define the shuffle product for words: if one of the words is empty (=$$\\varepsilon\$$) we have $$\alpha ⧢ \varepsilon = \varepsilon ⧢ \alpha = \alpha.$$ If both are nonempty, we split them up into a one letter suffix and a leading word. So let us write the two words $$\\alpha\$$ and $$\\beta\$$ as $$\alpha = \varphi \mathbf{a} \qquad \beta = \psi \mathbf{b}$$ Then the product is defined via the recursion $$\alpha ⧢ \beta = (\varphi ⧢ \beta)\mathbf{a} +(\alpha ⧢ \psi)\mathbf{b}.$$ This is where the "shuffle" in the name is coming from: The shuffle product results in all possible riffle shuffles of the two words. Consider the following examples: \begin{align*}ab ⧢ xy = abxy + axby + xaby + axyb + xayb + xyab\end{align*}

B. Two shuffle algebra elements $$\\Phi = \sum_i f_i \varphi_i \$$ and $$\\Psi = \sum_j g_j \psi_j \$$ (where $$\f_i, g_j \in \mathbb Z, \varphi_i, \psi_j \in W\$$) are multiplied as follows: $$\Phi ⧢ \Psi = \sum_i \sum_j \underbrace{(f_i \cdot g_j)}_{\in \mathbb Z} \underbrace{(\varphi_i ⧢ \psi_j)}_{\in S}$$

### Details

• The inputs can each be taken as a string or as a list of pairs where each pair is represents one term (coefficient and word) of the element, or alternatively as two lists of the same length or other similar formats.
• The output format must match the input format.
• The output must be reduced: No two terms should share the same word.

### Examples

• Might you consider just having the challenge be to multiply two words? When thinking about how I'd do this challenge, I'm imagining implementing the shuffle product, than iterating over pairs of monomials and multiplying them and their coefficients, then reducing by combining like terms. I don't know anything about the shuffle algebra, so I don't know if there's something that lets you work with elements in some more special way. – xnor Sep 14 at 20:10
• @xnor My thought was that if we just take two words for the input, the output will still be a general element (e.g. aa ⧢ ab = 3*aaab +2*aaba +1*abaa), so you would already have to implement the simplification (collecting the the terms with the same words), so the additionl step of multiplying two general elements wouldn't be a lot more compilcated. - Would you suggest also removing the simplification step, so that the output would just be a list? (e.g. aaab,aaab,aaba,aaab,aaba,abaa for the input from above) I think this would on the one hand be a lot easier, but also less of a challenge. – flawr Sep 14 at 20:31
• Hmm, I hadn't considered that a riffle product of monomials would already produce repeats. I don't know what I'd suggest. For what it's worth, I tried searching for a duplicate of generating all possible riffles and didn't find one, though I have a memory of having done something like it on anarchy. – xnor Sep 14 at 20:37

# Walk N Spaces on a Game Board

This challenge is inspired by Touhou Cannonball, a mobile game that includes a board game element similar to Mario Party, except for the fact that movement isn't restricted to one particular direction.

### Movement

On your turn, a six-sided dice is rolled to determine how many spaces to move. For each of those spaces, you can move to any adjacent space, as long as you do not backtrack to the space you were on in a previous move.

For example, if you roll a 2 and start from space [2] in the following graph, you can move left twice to space [0] or right twice to space [4], but you cannot move once left and once right to land on space [2] again, because you traveled across the same edge in two consecutive moves.

0<->1<->2<->3<->4


You can move to a previously visited space, as long as you aren't "backtracking" to that space -- if you roll a 4 on the following graph starting from space [0], you can land on [0] by going in a circle around the graph with the move [0]->[1]->[2]->[3]->[0].

0<-->1
^    ^
|    |
v    v
3<-->2


Some graphs may have some directed edges. If your graph is [0]-->[1], you can move from [0] to [1], but not the other way around.

### The Challenge

Given any appropriate directed graph structure (incidence matrix, adjacency list, etc.), a starting position, and a number of spaces to move, output all possible positions you can move to.

### Examples

Example inputs are zero-indexed in the format starting position, number of spaces, adjacency list. I will also have the visual graph included for better visualization. (More to be added later)

Input: 2, 5, [ [1,2], [0,3], [3,4], [1,6], [2,5], [4,6], [3,5] ]
0<----->1
^       ^
|       |
|       v
2------>3
^       ^
|       |
v       v
4<->5<->6

Output: [1,2,5]


### How fair are my dice?

(Inspired by a dream I recently had regarding Mario Party. This is not fully fleshed-out yet.)

Given a pair of dice, e.g., [[1,1,2,2,3,3], [1,2,3,4,5,6]], output how "closely" they resemble a pair of standard 1-6 dice (i.e., [[1,2,3,4,5,6], [1,2,3,4,5,6]]) in terms of distribution of numbers when rolled.

• Is the input always a pair of six-sided dice or can they have a variety of face counts? Sorted? How would [[2,3,4,5,6,7],[2,3,4,5,6,7]] compare considering it'd have the same distribution curve? – Veskah Dec 2 at 16:20
• You need to flesh out details on how this should be measured. Do I go by simulation? Do I base the distribution on the total of each pair of rolls? What is "closely"? Sum of squared error? – Beefster Dec 6 at 19:56

# Next Shared Totient

• Adding bounds is not generally necessary: the usual assumption on this site is if a solution breaks for memory / data type reasons that aren't intentional abuse then the solution is still valid. – FryAmTheEggman Dec 4 at 18:48

## Round up my number code-golfnumberinteger

Given two positive nonzero integers (a and b), output the result of this operation: repeatedly increment the given number a by 1 until it becomes a multiple of b, or is already a multiple of b.

## Examples

Definitions: true = is a multiple of b, false = is not a multiple of b.

• f(1,3) = 3 because 1 is false, 1+1 is false, but 1+1+1 is true. Therefore 3 is returned.

• f(5,3) = 6 because 5 is false, but 5+1 is true. Therefore 6 is returned.

• f(9,3) = 9 because 9 is already a multiple of 3.

• f(12,5) = 15 because 12 is false, 12+1 is false, 12+2 is false, but 12+3 is true. Therefore 15 is returned.

## Rules

• Input/output can be given by any convenient method.
• You can print it to STDOUT or return it as a function result.
• Either a full program or a function are acceptable.
• Any amount of extraneous whitespace is permitted, provided the characters line up appropriately.
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• I'm not great at modular arithmetic, but $a + (b - a \bmod{b}) \bmod {b}$ doesn't seem particularly interesting to golf. – FryAmTheEggman Dec 5 at 15:20
• Really just a+-a%b assuming your language isn't weird with modulo of negatives. – xnor Dec 5 at 23:44

# What's that frequency?

This is my first code-golf challenge, so apologies if it is a little unclear/already has been done. I gave the past challenges a good look over, but I may have missed something.

Create a function or a full program which accepts a frequency value, and then outputs the closest musical note, and the octave, this frequency corresponds to.

This function/program should support eight full octaves worth of notes, starting from C0 up to and including B8.

Test cases:

440.00 -> A4
466.16 -> A#4
466.20 -> A#4
261.63 -> C4
16.35 -> C0
0.00 -> C0
7902.13 -> B8
10000.00 -> B8


A full list of frequencies and notes they correspond to can be found here: https://pages.mtu.edu/~suits/notefreqs.html

This is a code golf, so shortest code wins!

• Thanks for using the sandbox! :) I found the inverse challenge. I feel as though I've reviewed this version as well, but perhaps it never left the sandbox. In any case, you should include a method by which to classify the frequencies, and what precisely you mean by closeness in the body of your challenge. External links are nice but not enough! – FryAmTheEggman Dec 5 at 14:58

# A game of putting lines through dots.

## Get to my destination code-golfpath-finding

Given the speed of the car, the length of the road, and the position of my destination, output the fewest possible steps I need to get to my destination.

## How does the car move?

This car that I rode in the morning has a weird feature: after the driver presses break, the car's speed gets halved and rounded down. So if the car's initial speed is 3, it produces 1.5 rounded down, which becomes 1. The symbol for this is B.

An alternate decision for what the driver should do in a second is to not press brake. The symbol for this decision is ..

If the car gets out of the road it bounces back in the opposite direction (similar to Backhand).

## An example

The length of the road is 10. Let's draw it:

C000000000


The C character is the car. Now we know that the car goes right 2 blocks per second:

000C000000


But my destination is the second position. I need to press brake.

After pressing brake the car's speed is 1 block backwards per second.

00C0000000
0C00000000


And now I've got to my destination. But I couldn't stop without pressing brake, so I need another brake.

The produces the output code B.B.

## Test cases

3 10 2 -> B.B


# Union of Two Polygons

Given two intersecting polygons as input, output a third polygon that is the union of the two input polygons, that is to say, the perimeter that encloses all points present in at least one of the two input polygons.

# Example inputs/outputs

### 2 Squares

  [(0, 0), (0, 2), (2, 2), (2, 0)]
| [(1, 1), (1, 3), (3, 3), (3, 1)]
==> [(0, 0), (0, 2), (1, 2), (1, 3), (3, 3), (3, 1), (2, 1), (2, 0)]


... more to come

# Notes and Rules

• Input will be two lists of at least 3 2d points each, taken in any convenient format.
• Output should be a list of 2d points, in any convenient format.
• It does not matter which point you list first.
• It does not matter whether you output in clockwise or counterclockwise order.
• Polygons may be concave
• You may assume that both polygons are not self-intersecting
• You may assume that the polygons overlap in at least two places exclusively via edge-edge crossings rather than vertex-edge intersections, vertex-vertex intersections, or flush edge-edge overlaps.
• You may assume that the polygons do not overlap in such a way that the union would have at least one hole in it.
• You must be accurate to at least 0.01 for all polygons between -100 and 100 units along each axis.
• Standard rules apply. Shortest code wins.
• Can you add some examples? – Carson Graham yesterday

# Define the finite field GF(9)

$$\GF(9)\$$ or $$\GF(3^2)\$$ is the smallest finite field whose order isn't a prime or a power of two. Finite fields of prime order aren't particurlarly interesting and there are already challenges for $$\GF(2^8)\$$ and $$\GF(2^{64})\$$.

### Challenge

First define nine elements of the field. These must be distinct integers from 0 to 255, or the one-byte characters their code points represent. State in your answer which representation you choose.

Then define two binary operations, addition and multiplication, satisfying the field axioms:

• Both operations must be commutative and associative.
• Addition has the identity element $$\0\$$ and an additive inverse for each element.
• Multiplication has the identity element $$\1\$$ and a multiplicative inverse for each element except $$\0\$$.
• Multiplication distributes over addition: $$\a·(b+c) = (a·b)+(a·c)\$$

Since the field is really small, you can test the axioms exhaustively to check your implementation or print the addition and multiplication tables.

### Mathematical construction

Elements of $$\GF(3^2)\$$ can be interpreted as polynomials of the form $$\P(x)=a x+b\$$ over $$\GF(3)\$$. (Addition and multiplication in $$\GF(3)=\{0,1,2\}\$$ are the standard integer operations modulo 3.)

Then addition in $$\GF(3^2)\$$ is simply the addition of two polynomials. Multiplication is defined by the product of two polynomials, reduced modulo a polynomial of degree 2 which is irreducible over $$\GF(3)\$$.

### Example

Mapping polynomials to integers with $$\n=3a+b\$$ and using the irreducible polynomial $$\x^2+1\$$ yields the following addition and multiplication tables. Note that there are other possible isomorphisms of these tables.

+   0 1 2 3 4 5 6 7 8   *   0 1 2 3 4 5 6 7 8
------------------      ------------------
0 | 0 1 2 3 4 5 6 7 8   0 | 0 0 0 0 0 0 0 0 0
1 | 1 2 0 4 5 3 7 8 6   1 | 0 1 2 3 4 5 6 7 8
2 | 2 0 1 5 3 4 8 6 7   2 | 0 2 1 6 8 7 3 5 4
3 | 3 4 5 6 7 8 0 1 2   3 | 0 3 6 2 5 8 1 4 7
4 | 4 5 3 7 8 6 1 2 0   4 | 0 4 8 5 6 1 7 2 3
5 | 5 3 4 8 6 7 2 0 1   5 | 0 5 7 8 1 3 4 6 2
6 | 6 7 8 0 1 2 3 4 5   6 | 0 6 3 1 7 4 2 8 5
7 | 7 8 6 1 2 0 4 5 3   7 | 0 7 5 4 2 6 8 3 1
8 | 8 6 7 2 0 1 5 3 4   8 | 0 8 4 7 3 2 5 1 6


Test of distributivity using the tables above:

$$5 · (2 + 7) = 5 · 6 = 4$$ $$(5 · 2) + (5 · 7) = 7 + 6 = 4$$

Note that simply using addition and multiplication modulo 9 won't work.

### Scoring

This is code golf. Your score is the sum of bytes of the functions (or programs) for addition and multiplication. Lowest number of bytes wins.

### Sandbox notes

• Each finite field has a unique structure, so I wouldn't consider this question a duplicate.
• I think it's a good idea to post an example of addition and multiplication tables to help people who aren't mathematically inclined.
• Looks like a solid challenge. I like that the field size here is not a power of two so that bit encoding won't be useful, and 3^2 looks like a good small choice. About "You can use any nine distinct objects of your language", I'd suggest restricting this to prevent something cheesy like having the objects be ones pre-made to implement the operation or be strings that can be executed as code. In a similar style challenge, I allowed any one-byte numbers or characters. – xnor Dec 7 at 10:35
• It might also be good to warn people that it won't work to do usual addition and multiplication modulo 9, since I think that's a common misconception. – xnor Dec 7 at 10:37
• @xnor You're right, allowing arbitrary objects as field elements would allow to cheat. I changed that according yo your suggestion. – nwellnhof 23 hours ago

This challenge is to produce a script that will accept a string as input, and generate a score for it using the rules defined below. Your score is the return value of your program given its own source as input.

The first scoring system

The first unique character is worth -1
The second unique character is worth -2
The third unique character is worth -3
etc...

The second scoring system

Each repetition of a given character incurs a further escalating penalty to your score.

The first usage of a given character incurs no additional penalty
The second usage of a given character incurs an additional penalty of -1
The third usage of a given character incurs an additional penalty of -2
The fourth usage of a given character incurs an additional penalty of -3
etc...

e.g.

• The code abc would have a score of -6
• The code aabc would have a score of -7
• The code aaaabc would have a score of -12

Rules

• Your score starts at 0
• The highest score for a given language wins.

Test

The below Stack snippet will parse a string according to the rules defined above and generate the score.

function testScore() {
var score = 0,
counter = 0,
input = document.getElementById('code').value,
x,
y,
instances = {},
keys;

input = input.split('');

for(x = 0; x < input.length; x++) {
if(typeof instances[input[x]] == 'undefined') {
instances[input[x]] = 0;
score -= ++counter;
}

instances[input[x]]++;
}

keys = Object.keys(instances);
for(x = 0; x < keys.length; x++) {
for(y = 0; y < instances[keys[x]]; y++) {
score -= y;
}
}

return false;
}
<form onsubmit="return testScore(this);">
<div>
<textarea id="code" style="width: 100%; height: 150px;"></textarea>
</div>
<div>
<button type="submit">Generate score</button>
</div>
</form>

• I'd appreciate some pointers on what tags to use for this one - it's similar to code golf but isn't quite code golf. – Scoots Dec 11 at 11:48
• Similar but a slightly different scoring system – Veskah Dec 11 at 13:02
• This is two challenges: First, reading your own source code. Second, creating the score for an input string. In addition, the condition of "Parse yourself" is a non-observable requirement. In this case, it's definetly bad because it forces the two separate challenges approach onto people. I understand why you want to exclude print -45, but right now, the whole quine-except-not-really thing doesn't seem helpful. – AlienAtSystem yesterday
• @AlienAtSystem Respectfully I disagree with your assertion that reading the source code is a challenge; I'm very explicit that any means of getting your source code in is acceptable, even copy/pasting it as a command line argument. The parsing of your own code - I thought it might encourage people to golf in a way they may not be used to due to the escalating penalties involved in the scoring system. – Scoots yesterday
• If you don't want the source code reading to be part of the challenge, then don't write things like it is. Really just say Takes a string as input and outputs the uniqueness score and Your score is the return value of your program when given its own source as input. – AlienAtSystem yesterday
• @AlienAtSystem I take your point, your phrasing is definitley better than what I originally had. – Scoots 21 hours ago

Play snake on a 50*50 grid. The snake will start at length 3, heading (2,0) with body (1,0) and (0,0). It shouldn't bump into wall or itself. There is always one food, which increases the length of snake by 1 when eaten.

Smallest amount of steps till there's no space to place food win. Flexible I/O, anyway it doesn't matter.

Vote on whether the food placer is transparent and allow food manipulation(Up for yes, down for no)

• I think there are already quite a few snake challenges. You need to flesh out some more details here. How do you determine where the food will spawn? Will you be given some sampling of the game state (vision?) on each step? – Beefster Dec 28 '18 at 19:22
• @Beefster If "food placer is transparent and allow food manipulation", you just know how it spawns; If not, you get access to the location of current food – l4m2 Dec 29 '18 at 3:44
• If food manip. is allowed, is the optimal score achievable by finding an Hamiltonian path starts with the snake? – user202729 Dec 29 '18 at 8:55
• @user202729 It depends on how strong the manipulation is – l4m2 Dec 29 '18 at 10:54
• -1 for winning entries must be written in one of the 25 top languages. – Jo King Jan 19 at 9:28
• I'm trying to exclude golfing languages with that - this only seems like an interesting challenge to me if you don't allow languages where it's excessively trivial. Any suggestions for how to do that in a more permissive way or other thoughts about that goal? – lahwran Jan 19 at 22:13
• actually, I think this will be quite difficult in many code golf languages as well, as they usually try to get brevity by cramming things into single letters and numbers. there are of course languages where it'll be excessively trivial, but that's fine, those solutions most likely just won't be upvoted. – lahwran Jan 19 at 22:21
• Most golfing languages won't be able to pull sth. from the interconnected-webs afaik, so there's no real need to invent arbitrary restrictions to ban them. – ბიმო Jan 21 at 16:25
• Also "but that's fine, those solutions most likely just won't be upvoted" is too optimistic, usually it's the other way around :( – ბიმო Jan 21 at 16:26
• dang, good to know. – lahwran Jan 21 at 22:55

# A Quine that Grows!

Challenge

Create a quine that, when run, outputs itself but copied larger in the next one. The output should be able to be run, and get larger each time the output is run. The output must consist only of characters from the original quine!

EX:

abc //original
abcabc //output


or

abc //original
aabcc //output


What not to do

abc //original
abcgef //output

abc //original
abcoooooooooooo //output


An example I created

Try it Online! It replicates pretty fast if I do say so myself!

Points

This challenge is meant to be a codegolf, but also emphasize on how fast it replicates. So perhaps something like the speed at which it gets bigger divided by the number of bytes.

I really don't want loopholes like just repetitively adding characters to a section of the code, making infinite loops, and things of the like.

Any input on how to make this a good challenge? I'm open to suggestions!!!

• Related, related (probably a dupe) – Jo King Feb 10 at 10:25
• @JoKing What about a polyglot that gets bigger? It runs, making another program that runs and outputs a bigger version of the original, and vice versa. – KrystosTheOverlord Feb 10 at 16:02
• where's the polyglot part come from? otherwise that sounds like the second one – Jo King Feb 10 at 22:04
• @JoKing The output has to be in a different programming language, and then create a larger version of the original, then this larger original makes a larger of second program etc... Also to prevent easy loopholes, no using program languages that are derivatives of eachother – KrystosTheOverlord Feb 10 at 22:32

Just idea. Not sure what to do exactly.

# Evolutionary Golf

Make simple (not golfed at all at first) code for (some program) with language (something).

Now, change a little bit (maximum 3 byte) of code to make it shorter.

Altered code must work properly (this is how evolution work).

(Maybe here will be starting code).

### Sandbox

First. What program would be best? For example, 'Hello World' program is not proper, because it is too short, and can't golf that much.

Second. What language would be best? Esolang like BF? Or something like C?

• If I understand the challenge idea correctly you will post an ungolfed answer that does something in some (probably verbose) language (i.e. FizzBuzz in C#). And then answers after that should have a Levensteihn distance change $c$ where $1\leq c\leq3$ (at least 1 delete) that does the same thing (in any language). And the shortest answer that's at the end of the answer chain wins if no other answers are posted within 2-3 weeks (which is usually the case with answer-chaining challenges)? Or do you mean that anyone can post an ungolfed program, and others using the same language chain it? – Kevin Cruijssen Jun 26 at 9:04
• @KevinCruijssen I'm thinking of both. This is just brief outline, so everything can be changed. – LegenDUST Jun 26 at 12:10
• this is just game of nim with extra steps – Kenneth Taylor Aug 2 at 17:51

# Print all the commands

META Just a rought idea, needs to be worked out.

Write a program that prints all the keywords and commands that are available in your langauge when you do not import/add anything

### Details

• require full program or standard code-golf?
• Understanding that this is a rough idea, what happens in languages without commands corresponding to single tokens e.g. ///? – lirtosiast Jul 18 at 15:49
• It is my opinion that this sort of challenge will likely never be clear. – Wheat Wizard Jul 18 at 16:08
• I'd imagine for /// you'd output all valid non-text characters, so \ /. – bigyihsuan Jul 18 at 17:08
• Another thing is that language version would be specified. For example, Python 2 has print as a keyword, while Python 3 has print() instead. – bigyihsuan Jul 18 at 17:10
• Pretty sure this (or something similar enough to be a dupe) has been done before. Lemme see if I can find it .... – Shaggy Jul 21 at 21:11
• – Shaggy Jul 21 at 21:13
• One way to do this might be to make it language specific? While that isn't usually popular, outputting all of, say, Python's commands in most languages besides python is a dupe of the Rickroll challenge. However, in python itself that isn't the best approach. I can't say how well reveived it'd be, but you could try "output these MATLAB commands in MATLAB" and see what people think. – FryAmTheEggman Jul 23 at 19:45

Here's a challenge I'd like post because I'm curious to see what people will come up with. It's a bit of an anti-code-golf question because the code should look normal.

Is it clear what the constraints? Did I miss anything?

# Introduction

Write a piece of unsuspicious code that does the following:

Let's say you've written a parser that parses it's input line by line and somewhere in your code is

find_string(line, "[start]", "[end]") // returns string between [start] and [end]


This program, when given it's own source code plain text as input, will match that line (twice actually); but we don't want that. It should still parse what it was designed for but not match any line of it's own source code.

# Rules

• It's preferred that your code makes it obvious that one of it's intended uses is to parse (and not match) itself. This is so anyone 'refactoring' the code will not accidentally undo the trick that made it work.
• Your source code as input will be reduced to a single line.
• Your program should be able to handle large input (~10mb) and perform reasonably (for your chosen language).
• Your program does not need to parse the input line by line but that just seems like something reasonable code would do.
• Points are awarded for code that looks like a normal parser and contains as little assumptions about the input as possible. Bonus points for solutions that contain the start and end delimiters in that order.

Easy solutions are to swap the start and end token arguments or to pre-treat the tokens in some way but that would look suspicious. Someone will come along and refactor your code and break the 'trick'.

I'm interested in reasonable solutions because this is a reduction of a real life problem.

# Example Input and Output

• Input lines may or may not contain [start] or [end], only return it in the output when it occurs in a pair.
• Input lines will never contain more than one pair of [start] and [end] tokens.
• Input lines may contain additional content before [start] or after [end]
• Your source code plain text will be inserted at a random line in the input.

Input #1:

[start]hello[end]
dont output this[start]world[end]


Output #1:

hello world


Input #2:

lorem[start]i solemnly[end]
[start]false start
[start]swear[end]
ope, sorry just passing through
this is not the[end]
[start]that i'm up to[end]ipsum
[start]no[end]dolor
[start]good[end]


Output #2:

i solemnly swear that i'm up to no good

• What is the objective winning criterion? – Unrelated String Aug 9 at 5:16
• This could be a good challenge if it was just 'Write a program that takes a line of input and returns the concatenation of anything between [start] and [end] on each line, otherwise an empty string', with the restriction that if it was fed itself, it wouldn't return anything – Jo King Aug 9 at 6:05
• I'm a little confused about what Bonus points for solutions that contain the start and end delimiters in that order. means, since I thought the point was that we're not allowed to have that? – Jo King Aug 9 at 6:07
• "unsuspicious code" will raise red flags in the minds of a number of old-timers, for historical reasons which I won't explain in detail. What I will say is that unsuspicious is subjective, and we insist on objective criteria. In terms of actual reasonable solutions to the real world problem: don't use magic strings. If "[start]" and "[end]" are both constants and defined on separate lines, the problem is averted, and anyone who refactors to inline them deserves all the bugs that causes. – Peter Taylor Aug 9 at 10:45

# Make it improbable... BUT NOT IMPOSSIBLE

You must make a program that outputs truly once in a while. However, making it have output falsy all the time is not acceptable.

## Rules

• Standard loopholes are forbidden.
• You may use any of accepted I/O formats.
• Your program must be possible to output a truly value.
• When not outputting a truly value, you may either output a falsy value or not output anything at all.
• You may output two or more values, however if it contains a truly value, then the output is considered truly.
• The probability of outputting a truly value must be at most 1/2.
• Your program must not take/use an input.
• Using non-deterministic but non-random(Such as getting the time) is prohibited. However, if date etc. is used in the builtin random function, it is allowed.
• The program must theoretically always terminate or stop outputting anything.
• You may assume that you have a fast enough computer and large enough memory.
• Your program should not be affected by raising the maximum value of a data type. You may still use unaffected constants.
• Data types must be following its spec: ie. for an unbounded arbituary precision integer type, you may assume that it can go as high as you want(but you are not allowed to increment until an error as in the rule above), but a double-precision floating-point format still has 22-bit fraction and 8-bit exponent.
• Score is calculated as: Pl-1.5l, where P is the probability and l is the byte length.

## Example(s)

JavaScript
P=0.1, l=24 => Score=23.534


The lowest score wins!

• So is it acceptable for just a program that always outputs truly? You need to define improbable. (I assume this probability must be at least lest than 1/2.) Providing a few examples will be helpful. So is there only output and no input? In addition, you need an objective winning criterion, which is a criterion that posts for this challenge will need to comply in order for it to be a valid answer. (Usually this criterion is making the source code shortest.) – A̲̲ Sep 24 at 13:37
• Sorry, I posted this incomplete. – Naruyoko Sep 24 at 16:14
• I don't think your scoring method works particularly well, unless I'm making an error. For any $l > 1$ your score cannot be less than 1. Achieving a score arbitrarily close to 1 is relatively easy. So the only way to beat that is to have a one or zero byte solution. It is easy to make the probability increase exponentially with linear code additions. It might be necessary to penalise length massively, like $P \times e^{l!}$, to avoid similar problems. – FryAmTheEggman Sep 24 at 18:39
• I see. I guess P^l^k is too penalizing but Pk or Pe^k is too forgiving. Pe^l! looks simple enough but is is the middle so it may work. – Naruyoko Sep 24 at 20:11
• The problem with any of scoring methods for this challenge is that it is possible for any increasing computable function f, a program with length l can have P around 1/f(l). The only non-broken formula could be uncomputable, i.e. P/BB(l), where BB is the busy beaver function. – Naruyoko Sep 24 at 20:15

Title: Transposition

** The challenge **

Given a set of notes (as a string, or a list, or any other reasonable input - but as letters and accidentals, not a numerical equivalent), the key those notes are in, and a target key; output the notes transposed into the new key. Some of the notes may not exist in the scale for the given key (e.g Eb in the key of C).

** Inputs **

The complete set of input notes for this challenge will use the English naming convention, and so are as follows:

Ab,G##,A,A#,Bb,B,C,C#,Db,C##,D,D#,Eb,E,F,F#,Gb,F##,G,G#

where "b" represents a flattened note (down one semitone per b), and # represents a sharpened note (up one semitone per #). Theoretically all notes can be extended further with more #s and bs; but for the purposes of this program that won't happen beyond what is already given.

** What is transposing? **

Transposing a song involves "moving" the song into a different key, by finding the equivalent note of the scale in that key.

We will assume Major scales for the purposes of this challenge.

** Scales **

The scales for this challenge are officially as follows:

• C: C, D, E, F, G, A, B, C
• C#: C#, D#, E#, F#, G#, A#, B#, C#
• Db: Db, Eb, F, Gb, Ab, Bb, C, Db
• D: D, E, F#, G, A, B, C#, D
• D#: D#, E#, F##, G#, A#, B#, C##, D#
• Eb:Eb, F, G, Ab, Bb, C, D, Eb
• E: E, F#, G#, A, B, C#, D#, E
• F: F, G, A, Bb, C, D, E, F
• F#: F#, G#, A#, B, C#, D#, E#, F#
• Gb: Gb, Ab, Bb, Cb, Db, Eb, F, Gb
• G: G, A, B, C, D, E, F#, G
• G#: G#, A#, B#, C#, D#, E#, F##, G#
• Ab: Ab, Bb, C, Db, Eb, F, G, Ab
• A: A, B, C#, D, E, F#, G#, A
• A#: A#, B#, C##, D#, E#, F##, G##, A#
• Bb: Bb, C, D, Eb, F, G, A, Bb
• B: B, C#, D#, E, F#, G#, A#, B

For simplicity, we can assume that both notes in the pairs A#/Bb, C#/Db, D#/Eb, F#/Gb, G#/Ab, C##/D, F##/G, G##/A are enharmonically equivalent (i.e. interchangeable - although they're not, always).

For scales with double-sharps, I will accept the enharmonic equivalents as an alternative implementation:

• D#: D#, E#, G, G#, A#, B#, D, D#
• G#: G#, A#, B#, C#, D#, E#, G, G#
• A#: A#, B#, D, D#, E#, G, A, A#

but for all other notes in the scale, they must match. If the note isn't in the scale, either can be used.

e.g.

• F in the key of C should transpose to F# in the key of C#, and not to Gb, because that option in the pair is explicitly in the scale
• but D in the key of C# could transpose to either C# or Db in the key of C, because it's an incidental anyway and so there's no easy rule to determine which it should be.

BONUS feel-good points *: normally it's # if you're going up, and a b if you're going down - feel free to implement this if you want!

For double-sharps (e.g F##) in all cases, It's OK if the program "resolves" these (e.g.to G in that case) even if they are in the scale; but again, some BONUS feel-good points * if you keep the double-sharps in.

Examples

• CDEFGABC in C to A -> ABC#DEF#G#A
• C# in C to A -> A# OR Bb
• ABCDEFGBAF#Bb in Bb to Gb -> FGAbBbCDbEbGFDGb
• CCGGAAAAGFFEEDDCGGGFFEEEDCGGGFFFFEEED in C to G# -> G#G#D#D#E#E#E#E#D#C#C#B#B#A#A#G#D#D#D#C#C#B#B#B#A#G#D#D#D#C#C#C#C#B#B#B#A#

Websites like http://www.logue.net/xp/ can be used to test your answers to other inputs

* Bonus feel-good points don't get you anything extra, unless someone can come up with a quantifiable difference that it should make to the score?

• This is kind of similar but doesn't use scales and has a different set of chords, so I think this is effectively different? – FryAmTheEggman Sep 24 at 18:47
• Yes, I agree it's similar but doing a different thing to me (they're using chords, and so have the extra text to worry about; but I'm doing notes, like sheet music; and so you have accidentals to worry about) – simonalexander2005 Sep 25 at 8:48

# Interpret Unneccesary (Not quite)

Unneccesary is a joke language created by Keymaker. The source is unneccesary, and if given, it will error out.

Your task here is similar. If there is input, your program should error out. If the input is empty, your program should do nothing and terminate.

• What does it mean to error out? – Beefster Oct 24 at 19:14
• @Beefster throw a runtime error... Or? – HighlyRadioactive Dec 1 at 10:15
• What if I'm using a language that does not have terminal errors such as Bash? – Beefster Dec 2 at 19:34

# Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?

# Challenge:

Given an arbitrary number (>= 2) of possibly duplicated hexadecimal color values (ranging from #000000 to #FFFFFF) and paired strings, calculate the following:

• If #FF0800 (Candy apple red) appears in the input, return "Return to Sleeping Death"
• If #000000 appears in the input, return "Saved by Grumpy"
• If #A98AC7 or #111111 appears in the input, return "Saved by Happy"
• If #21E88E or #222222 appears in the input, return "Saved by Sleepy"
• If #32DCD5 or #333333 appears in the input, return "Saved by Bashful"
• If #43D11C or #444444 appears in the input, return "Saved by Sneezy"
• If #54C563 or #555555 appears in the input, return "Saved by Dopey"
• If #65B9AA or #666666 appears in the input, return "Saved by Doc"
• If #76ADF1 or #777777 appears in the input, return "Saved by the Seven Dwarfs"
• If #FFFAFA (Snow) appears in the input, return "Saved by Love's first kiss"
• If an F variant appears in the input, return "Press F to pay respects to Snow White"
• An F variant is any number that contains at least one F in its hexadecimal form, and is otherwise all 0s (e.g. #0FF0F0, #FFFFFF, #00000F, #F00F00)
• If multiple of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
• For all N occurrences of special color values, choose the (N-1)/2-th (truncating division) occurrence. The associated special output is the "fairest" answer.

"Appears in the input" here refers to only the hexadecimal color values, and not to the paired strings.

• If none of the preceding occur, return the "fairest" answer. The "fairest" answer is calculated as follows:
• Take the hexadecimal color value at the end of input values, write it down, and exclude that single color-string pair from consideration as the "fairest" answer
• Show its binary form to the mirror, computing a reflection of only the last 24 (#FFFFFF is the mask) bits.
• Choose the hexadecimal color with least Hamming distance from the reflection. If there are multiple (N) such colors, choose the middle ((N-1)/2-th, truncating division) instance of the color. The "fairest" answer is the associated string for the color.

# Inputs:

A sequence of hexadecimal color values and String values separated by a space. The input may also be read as two separate sequences of hexadecimal color values and String values, or a single sequence of 2-tuples (either (hexValue, stringValue) or (stringValue, hexValue) is permissible, as long as the ordering is consistent across all 2-tuples). Input order matters - for each index, the corresponding element in the supply of color values is "associated" with the corresponding element in the supply of String values, and duplicates can affect the "fairest" answer. The effect is something like Function(List(HexColorValue),List(AssociatedStrings)) -> "fairest" answer. Hexadecimal color values may be represented as either (your choice of) a String "#"+6 digits, or 6 digits alone, as long as the representation is consistent across all color values.

Here's an example input:

76ADF1 Return to Sleeping Death
2FE84E Return whence ye came!


Here's another example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
2FE84E Return of the Jedi


Here's the third example input:

2FE84E Return to Sender
4FFAFC Return of the Obra Dinn
7217F8 Return of the King


Here's the final sample input:

F4A52F Eating hearts and livers
F4A52F Eating apples
F4A52F Eating porridge
F4A52F Eating candy houses
F4A52F A Modest Proposal


# Outputs:

The "fairest" answer as computed by the specified logic. For example, on the first sample input, the "fairest" answer would be Saved by the Seven Dwarfs, due to the special hex color 76ADF1 appearing within the input.

In the second sample, there are no special inputs. First, we take "2FE84E Return of the Jedi", which has value #2FE84E. In binary, this is:

001011111110100001001110


We take the reflection from the mirror, getting:

011100100001011111110100


We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 18 and 12 from the reflection, respectively. Since #4FFAFC has the uniquely lowest Hamming distance from the reflection, the "fairest" answer is Return of the Obra Dinn.

In the third sample input, there are no special inputs. First, we take "7217F8 Return of the King", which has value #7217F8. In binary, this is:

011100100001011111111000


We take the reflection from the mirror, getting:

000111111110100001001110


We compare it against 2FE84E (001011111110100001001110) and 4FFAFC (010011111111101011111100), which have Hamming distances of 2 and 8 from the reflection, respectively. All 3 instances of hexadecimal color value #2FE84E have minimum Hamming distance from the reflection, so we take the (3-1)/2=1th instance (0-indexed) of #2FE84E. Therefore, the "fairest" answer is Return to the house immediately, young lady!.

In the last sample input, there are no special inputs. First, we take "F4A52F A Modest Proposal", which has value #F4A52F. In binary, this is:

1111010011001100101111


We take the reflection from the mirror, getting:

1111010011001100101111


We compare it against F4A52F (1111010011001100101111), which has Hamming distance 0 from the reflection. All instances of hexadecimal color value #F4A52F have minimum Hamming distance from the reflection. There are FOUR instances of #F4A52F, because we always exclude the last hexadecimal color instance from evaluation. Therefore, we take the (4-1)/2=1th instance (0-indexed) of #F4A52F, and the "fairest" answer is Eating apples. If you don't exclude the last value from consideration, you actually get the (5-1)/2=2th instance of #F4A52F (Eating porridge), which is wrong.

# Rules:

• No standard loopholes
• Input/output taken via standard input/output methods.
• The output must be exactly equal to the "fairest" answer

# Scoring:

This is code golf, so shortest program wins.

Posted~ you can see it here

• Going to need tag suggestions :) – Avi Sep 30 at 20:57
• Can each entry be taken as a tuple, i.e. ("#FFFFFF","Return the Slab")? Can the label part also have a hex number in it or are we guaranteed it wont? Rules has the # but the examples do not, is either form fine? Can we get a worked example of a list containing multiple matching entries? – Veskah Oct 1 at 12:33
• @Veskah You can take tuples as input. You can choose whether to keep # in your input hex colors or not, as long as you keep it the same for every single input (no sneaky stuff like putting a # before the correct answer every time). I've added more sample inputs/outputs with explanation. – Avi Oct 1 at 14:28
• -1: This has way too many hardcoded input/output mappings. This challenge is more about encoding those than solving a problem. – Beefster Oct 24 at 19:10

# CMC: Cross-Multiplication Calculator code-golfmatharithmetic

In this task you should create a Cross-Multiplication Calculator.

Cross-multiplication is a way of factoring an algebraic expression. This is the expression form that this way can solve:

$$x^2 + ax + b$$

$$\a\$$ and $$\b\$$ are constants here, and $$\x\$$ is a variable.

Anyway, as far as I can tell, this expression form is only solvable in this method.

# Anyway, how do I do Cross-Multiplication? (TODO)

You first take the number $$\b\$$ and factor this number into integral factors.

Okay. We are using the expression $$\x^2 + 8x + 16\$$ as an example.

(Although 16 is not a prime) let us assume that 16 only has 2 possible factors:

• $$\-1 \times -16\$$ (because $$\-x \times -x = x^2\$$)
• $$\1 \times 16\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

Now you sum these possible two factors and check this against the number $$\a\$$.

• Check 1. So $$\-1 + (-16) = -17\$$. And unfortunately -17 is not 8, we proceed to the next check.
• Check 2. So $$\1 + 16 = 17\$$. And unfortunately 17 is not 8, we proceed to the next check. There are no checks left.

Did I make a mistake? Of course, I need to change the factors.

• $$\-2 \times -8\$$ (because $$\-x \times -x = x^2\$$)
• $$\2 \times 8\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

We sum those values, and they are -10 and 10 respectively. So I should change the factors to another value:

• $$\-4 \times -4\$$ (because $$\-x \times -x = x\$$)
• $$\4 \times 4\$$ (Obviously this is 16)
• And the above 2 with the factors reversed.

Finally! $$\4+4 = 8\$$, and here is the factorization:

$$(x+4)(x+4)$$

Now you will probably realize why I desperately need a program to automate this.

# Test cases

You can assume that the input is always valid. You do not have to specify the variables, only the numbers. Therefore the expression

$$x^2 + ax + b$$

is converted into:

$$+a \, +b$$

The expected output is not:

$$(x+\alpha)(x+\beta)$$

but:

$$+\alpha \, +\beta$$

a, b => α, β
8, 16 => 4, 4
-5, -24 => 3, -8


# Scoring

This is , so shortest answer in bytes wins.

## Meta

• Is this clear enough?
• I haven't found a duplicate, but anything? (Although unlikely, I found nothing by searching "Cross Multiplication".)
• Tags are code-golf, string and interpreter. Anything else?
• Any further feedback?
• I've edited your post to use MathJax for the mathematical formula/workings. In addition, I've edited out the rather strict input/output format (leading + etc.) as it's generally recommended to allow the most natural output format. Feel free to revert these changes if you dislike them. Also, your tags bullet point in the Meta section appears to be different to the tags in the title? – caird coinheringaahing Oct 21 at 17:48
• Finally, I'd vote to close this as a duplicate of this or this challenge (as it is a subset of both) – caird coinheringaahing Oct 21 at 17:51

# Parse a regex

Grep is a wonderful tool. It can find stuff in files, it can help you spell stuff correctly (grep 'whatever' /usr/share/dict/words or wherever that file is), and it can even test if something is a prime number!

However, the first version was implemented back in the golden age, when FORTRAN was respected, Pascal was the language for beginners, and object orientation was just starting out in on its great adventure.

One could argue that modern developers have nowhere near that much talent or skill, what with their flashy "IDEs" and "frameworks". If they would be asked to implement something similar, they would just jump at the nearest library or cloud thingimabob and say "Done!".

At least, that is what some would say.

## Prove them wrong! Golf grep!

Parse a regular expression without calling any built-in functions or operators explicitly meant for this.

## input:

Basically the same as a simple grep: a regular expression as a command line parameter, followed by an optional filename or a dash. If the filename is not present, or it is a dash, read for stdin.

This is the recommended way to do it, but if you can write an adapter (eg: post stuff to a php form for your program via a shell script), then that is OK as well. The adapter does not contribute to your score.

## output

Lines that match the regular expression.

## Notes:

The regex dialect is PCRE (perl compatible). Files use unix line terminators if it is relevant.

• Closely related, but not quite a duplicate. – AdmBorkBork Nov 18 at 20:42
• Why the downvote? – Mark Gardner Nov 20 at 8:16
• You've likely been downvoted because you "ban built-in functions or operations explicitly meant for this." Consider this post for a lengthy discussion of why this has fallen out of favour. Beyond this being trivial besides parsing regular expressions, it also doesn't actually describe what a regex is or what it means to be PCRE. Challenges need to be self contained! I think your bet is to make a different matching language yourself and ask us to implement grep but with that language instead of regex. – FryAmTheEggman Nov 20 at 19:09

# Predict the state of a Minecraft inventory after click events

Minecraft does inventory management over the network by sending packets describing the clicks that a player does. If you're caching these events, it can be non-trivial to predict what state the inventory is in after the clicks

## Challenge

Take an inventory of 9 slots, each with an item and a type. Assume all items can stack up to 64 and that if a slot would be "overfilled" that the cursor will continue holding onto the items. Then, take a list of the slot index, button, and mode variables for the clicks to be done (mode and button are defined at https://wiki.vg/Protocol#Click_Window). Output the inventory afterwards.

## Restrictions/Rules

You may input and output the inventory in any reasonable format. You may take click input in any reasonable format. You may ignore Mode==2, as the player inventory is not implemented correctly enough for this. You may ignore Mode==3 because this is a survival player You may ignore Mode==5 where Button==8, 9, or 10 for the same reason as Mode 3. Dropping the item is a delete. Your player won't pick it back up or anything silly like that. You may assume that input will have valid counts Don't use standard loopholes

## Examples

Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
[0, 0, 0]
[0, 0, 1]
]


Output

[[],["diamond",64],[],[],[],[],[],[],[]]


Input:

[["diamond",64],["dirt", 64],[],[],[],[],[],[],[]]

[
[0, 0, 0]
[0, 0, 1]
[0, 0, 2]
]


Output

[[],["diamond",64],["dirt",64],[],[],[],[],[],[]]


Input:

[["diamond",64],[],[],[],[],[],[],[],[]]

[
[0, 0, 0],
[-999, 4, 4],
[0, 4, 5],
[1, 4, 5],
[2, 4, 5],
[3, 4, 5],
[4, 4, 5],
[5, 4, 5],
[6, 4, 5],
[7, 4, 5],
[8, 4, 5],
[-999, 4, 6],
[8, 0, 0]
]


Output

[["diamond",56],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1],["diamond",1]]


# Meta

I have no clue what I'm doing writing a question.

Tagged code golf

Critique goals:

• Improve testcases
• Improve description of problem
• Determine if the problem is too complex
• Challenges are meant to be self-contained. While information where the idea/process comes from can be nice, everything needed to solve the challenge should be in the description. This means you should write down what click does what, for all the people who don't remember what Minecraft clicks do by heart. – AlienAtSystem Nov 22 at 6:43

A very-very old (maybe early 2000s) problem:

Print out a decimal number $$\n\$$ such as $$\n^2\$$ ends with $$\n\$$ with maximal length your program can compute in 60 seconds

In other words it's needed to find some long enough $$\n\$$ such as $$\10^{\lfloor\log_{10}n\rfloor+1}|(n^2-n)\$$.
A hint may be that an $$\n\$$ ending with $$\5\$$ is more easy to compute than an $$\n\$$ ending with $$\6\$$.

• How can this be king-of-the-hill? Do you mean code-challenge? And what stops us from hardcoding some extremely large number? – Jo King Nov 21 at 23:36
• king-of-the-hill needs interaction between submissions. I don't see any here – Jo King Nov 22 at 1:43
• @JoKing the problem becomes very simple with modular arithmetic: got 205k digits for free with ~len(n) time for each step imgur.com/ExPdwMb , so there's no need for hardcoding and it's not much interesting. ) – Alexey Burdin Nov 22 at 14:11

# JavaScript: Free for All

This is a very experimental idea of mine: given a function which is provided a single function as an argument, try to run that function the most times possible in a browser environment while competing against other bots.

## Bot submissions

Each bot consists of a function. This function takes a scoring function as input. Each bot has a state consisting of three values:

• score: Number indicating score, winning criterion
• locked: Boolean which, when true, prevents further score increases
• calls: Number of times scoring function called in last 100ms (?), will set locked to true for the remainder of the round if it exceeds a certain value

The scoring function increments score and calls, as long as locked is not true.

## Restrictions

If any of these restrictions are violated, a bot will have locked set to true.

No bot or bot-defined function may:

• Run longer than 5ms
• Attempt to modify the window location (location.href, location.assign, etc.)
• Attempt to connect to the internet (AJAX, WebSockets, etc.)
• Create web workers
• Affect hardware (sound, microphone, camera, USB, gamepads, etc.)
• Leave an impact which cannot be fixed by reloading the page

## Notes

This is almost certainly a very bad idea on an assortment of levels. If you have any suggestions of restrictions or ways to make the challenge more interesting, be sure to comment.

I'm considering some sort of system to determine which bot runs first that adds to the strategy, and interesting attack angles for other bots.

To prevent this from becoming a "read the last answer and exactly cancel out its strategy" type thing, I'm open to any suggestions.

# Digits of the sum of the reciprocal exponential factorials

The exponential factorial, $$\n^!\$$, is the extension of the factorial using exponentiation instead multiplication:

$$n^! = \begin{cases} 1, & \text{if }n = 0 \\ n^{(n-1)^!}, & \text{if }n \ge 1 \end{cases}$$

The first few exponential factorials are $$\1, 1, 2, 9, 262144, \dots\$$

The infinite sum of the reciprocals of the exponential factorials tends towards a constant:

\begin{align} \sum_{n=1}^\infty\frac{1}{n^!} & = 1+\frac{1}{2^!}+\frac{1}{3^!}+\frac{1}{4^!} + \cdots \\ & = 1+\frac{1}{2}+\frac{1}{9}+\frac{1}{262144} + \cdots \\ & = 1.611114925808376736\underbrace{111\dots111}_{183213\text{ times}}27224\dots \end{align}

The digits after the decimal point are OEIS A080219

You are to take a positive integer $$\n\$$ as input and output the $$\n\$$th digit after the decimal point of the above constant. Your program must work for an arbitrarily large $$\n\$$, but can fail due to language constraints for reasonably large $$\n\$$. You may choose 0 or 1 indexing. This is so the shortest code in bytes wins

# Meta

• Is this clear?
• Is this a duplicate?
• Tags are , and . Any suggestions?
• Any further feedback?
• The \$ symbol makes it look like you made a latex-typo :P Maybe you can mention that this is oeis.org/A080219 – flawr Dec 5 at 20:10
• @flawr Given that it's the symbol used in the Wikipedia article, I think it's best to keep using it. And yes, I will include that OEIS sequence, thanks! – caird coinheringaahing Dec 5 at 20:11

# Introduction

As programming languages reproduce are created, documentation is even more important for programmers. Your task is simple: output the esolangs.org documentation for your programming language.

With wikis being wikis, languages are heavily penalized in this challenge for being used often and for being interesting to write about, the goal here is to draw attention to languages that may not get utilized otherwise.

# Challenge

For this task, you will need to output the source for the article on esolangs.org for your language, with greater than or equal to 95% accuracy. Your score is your program length in bytes, as in other challenges.

Languages not on this multi-page list of languages as of the time of this posting are ineligible.

Standard loopholes are forbidden.

None

## Output

The source (as of this challenge being posted), for the esolangs wiki page for your language, with at least 95% accuracy.

# Example

Language: ///

Output:

{{featured language}}
'''///''' (pronounced "slashes") is a minimalist [[Turing-complete]] esoteric programming language, invented by Tanner Swett ([[User:Ihope127]]) in 2006 based on [[wikipedia:sed|the "s/foo/bar/" notation that everybody seemed to be using in IRC]]. The only operation is repeated string substitution, using the syntax <code>/''pattern''/''replacement''/</code>. Despite its extreme simplicity – there isn't even an obvious way to create a loop – it was proved [[Turing-complete]] by [[Ørjan Johansen]] in 2009, who created [[#Bitwise Cyclic Tag interpreter|an interpreter]] for the Turing-complete language [[Bitwise Cyclic Tag]].
...

New contributor
iPhoenix is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• -1: Interesting idea, but I don't think it can work as a challenge. I'm not convinced that kolmogorov-complexity-ing a volatile data source is a good idea. What happens if the page is edited two weeks from now? – Beefster yesterday

# Every number is interesting

We know that every number is interesting but how?

You should write a program or function which:

• takes a list of N positive integers (>0 and <2^31)
• outputs N lines each of them showing how the corresponding input number is interesting
• is not longer than 1024 bytes
• uses no more than 1 second per number
• doesn't use external sources

## Examples

172: 444 in base6
5776: 76*76
9801: 9 * 1089 (reverse)
68101: no 11 in base2 (10000101000000101)
491033: 317 * 1549 (product of 2 big primes)
467808816: no digit 5 from base6 to base10


## Inputs

You should include the output for the following input in your post:

58 92 120 224 358 490 912 1578 7812 222008 1645060 19796411 550453633


If you care to run your program on a bigger sample and share the result with us use this input data (2500 numbers). (You can upload your output to e.g. pastebin.)

This is a popularity-contest so highest voted answer wins.

Tags: popularity-contest, number

• What sort of criteria are necessary for defining a number as 'interesting'? I see things like square numbers, other bases, etc. But are there any specifics? I'm interested in this challenge (but worried it might be closed as too broad). – ASCIIThenANSI Apr 7 '15 at 13:18
• @ASCIIThenANSI There wasn't a clear definition. That's part of the reason why I abandoned the challenge. – randomra Apr 8 '15 at 1:55
• Would you mind if I tried taking it up? I would have to post as a new answer, because I can't directly edit. – ASCIIThenANSI Apr 8 '15 at 2:00
• @ASCIIThenANSI Not at all. – randomra Apr 8 '15 at 2:01
• @ASCIIThenANSI Where did you post it? – wizzwizz4 Jul 24 at 13:33
• @ASCIIThenANSI I am also curious – MilkyWay90 Aug 27 at 23:41

# Something Else - ASCII Art maker:

A text to ASCII art generator maker, the program must input a string and return ASCII art from it. Something like patorjk.com/software/taag/. It has to use the Graffiti font. The winning criteria is the whoever gets the most likes.

• Hello! Just a few things to point out: 1) The current spec is very broad. For example, what fonts, how does spacing look, what characters need to be supported... there's a lot more details that need to be included than just "return ASCII art of this text" – Sp3000 Feb 24 '15 at 4:07
• 2) What's the winning criterion? Popularity contest? Code golf? – Sp3000 Feb 24 '15 at 4:08