# 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 your first try can be difficult, and 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 and click "Answer This Question", or click on the "Add Proposal" link below. 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, and replace the post here with a link to the challenge and delete the Sandbox post.

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

# Heads I win, tails you booze: coin tossing, pub trivia style code-golfprobability-theorygame

At my old pub trivia night, a free jug of beer or bottle of wine was awarded to the team that won Heads or Tails. This game requires players to correctly guess the outcome of successive coin tosses. The game proceeds as follows:

1. Before each toss the remaining players, who are standing, place both hands on their head (for heads) or their bottom (for tails). If all remaining players choose the same outcome (which would lead to a draw) the host refuses to toss the coin until at least one player changes his/her guess.
2. The host then tosses a coin (assumed fair) and announces the outcome. All players who guessed incorrectly are eliminated and have to sit down.
3. Play continues until there is only one person left standing to claim the prize for their team.

In perfect play, the remaining players on each team always divide as evenly as possible between heads and tails:

• If the number of remaining players on a team is $$\2k\$$ for some positive integer $$\k\$$, then exactly $$\k\$$ of them guess heads and $$\k\$$ of them guess tails.
• If the number of remaining players on a team is $$\2k+1\$$, then with equal probability
• exactly $$\k\$$ of them guess heads and $$\k+1\$$ of them guess tails, or
• exactly $$\k+1\$$ of them guess heads and $$\k\$$ of them guess tails.

An interesting consequence of players not acting independently is that a team's probability of winning is not, in general, equal to $$\\dfrac{\text{number of players on the team}}{\text{number of players on all teams}}\$$, as the examples below illustrate.

### Challenge

Assume that there are $$\n_0\$$ players on our team and $$\n_1, n_2,\ldots, n_N\$$ players on the opposing $$\N\$$ teams ($$\N\$$ and the $$\n_i\$$ are all positive integers). Given the $$\n_i\$$ as input, write the shortest program or function that calculates the probability that our team wins the booze, assuming perfect play by all teams.

Input format is flexible: you may (for example) take

• an integer $$\n_0\$$ and a list $$\[n_1, n_2, \ldots, n_N]\$$ (this format is used in the test cases),
• a flat list $$\[n_0, n_1, \ldots, n_N]\$$,
• a nested list $$\\left[n_0, [n_1, n_2, \ldots, n_N]\right]\$$.

The $$\n_i\$$ may be taken in any order. Output should be in a suitable numeric format. Floating-point approximations are acceptable provided that the underlying algorithm is theoretically exact. You may not return a list of winning probabilities for all teams (I don't care how likely it is that another team wins).

### Examples

Example 1: $$\n_0=1\$$, $$\n_1=2\$$

Suppose there are only two teams: our team has one player and the opposing team has two players. After the first toss, exactly one player from the opposing team remains in the game (because one player guesses heads and the other guesses tails). For our team:

• Half of the time, our player has guessed incorrectly and is eliminated. The other team wins.
• Half of the time, our player has guessed correctly. A second toss occurs—a head-to-head battle with the remaining player on the other team—which our player wins half of the time.

The probability that our team wins is therefore $$\\dfrac{1}{2}\cdot0 + \dfrac{1}{2}\cdot\dfrac{1}{2} = \dfrac{1}{4}\$$.

Example 2: $$\n_0=2, n_1=3\$$

In this case, both teams survive the first toss. Exactly one player remains on our team. For the other team:

• Half of the time, one player remains. A second toss decides the winner.
• Half of the time, two players remain. From this point, the remaining tosses play out exactly as in Example 1.

The probability that our team wins is therefore $$\\dfrac{1}{2}\cdot\dfrac{1}{2} + \dfrac{1}{2}\cdot\dfrac{1}{4} = \dfrac{3}{8}\$$.

### Test cases

$$\n_0\$$, $$\[n_1, n_2, \ldots, n_N]\$$ -> Output

1,  -> 1/4
2,  -> 3/8
5, [5, 5, 5] -> 1/4
5, [3, 5, 7] -> 5929/24576
8, [1, 2, 4] -> 485/768
6, [4, 5, 5, 6, 8] -> 45/256

• Even then, that "perfect strategy" strategy is ambiguous -- what if there's an odd number of players? Why isn't there a (us=H, them=H) case in the "round 2" of example 1? [please review other sandbox posts] – user202729 Feb 13 at 5:41
• @user202729 Yes to your first question. For your second question, there's no (H, H) because one of the players on the other team was eliminated in Round 1. Do the edits help? – Dingus Feb 13 at 5:46
• @user202729 Just saw your edit. (us=H, them=H) is a draw (by which I mean the round would just be repeated until they guess differently from each other). It's supposed to be covered by 'the pathological scenario in which all players repeatedly guess the same outcome never occurs in practice'. – Dingus Feb 13 at 5:47
• So if there are two ways to divide evenly (odd number), assume that each team choose one of them independently with the same probability? – user202729 Feb 13 at 5:49
• By the way, unless there's some clever formula to calculate the result, I expect that all the submissions will be too inefficient to calculate the last test case. – user202729 Feb 13 at 5:52
• @user202729 I'll add some text to clarify what happens with odd-sized teams and a small test case with all odd-sized teams of different sizes. Fair point about the inefficiency. – Dingus Feb 13 at 5:57
• Okay that part is good now, but you might want to add "if all players guessed wrong, then no players is eliminated" – user202729 Feb 13 at 11:24
• @user202729 I think that's covered by 'If all remaining players choose the same outcome (which would lead to a draw) the host will refuse to toss the coin until at least one player changes his/her guess', but it should be clearer now that I've moved that sentence earlier in the description. – Dingus Feb 13 at 11:36
• By the way, do you have a proof that the mentioned algorithm is optimal? – user202729 Feb 13 at 12:47
• "until at least one player changes..." can be ambiguous (what is their strategy to change the choice?) I think "skips the round and all player choose [...] again" is better. – user202729 Feb 13 at 12:52
• By the way, do you have a polynomial time solution? – user202729 Feb 15 at 2:07
• (this is a (probably polynomial time, or at least can be made polynomial time) implementation . tio.run/… ) – user202729 Feb 16 at 6:43
• @user202729 I appreciate all the comments, thank you. Clearly there's a bit to think about but I won't have time to look at this again in detail for a few days, probably. (It may be that this challenge has more potential in a category other than code golf, but I'm not sure yet.) – Dingus Feb 16 at 7:02

# Score an approximation code challenge code-golf

Given a list of inputs (strings) and their expected outputs (integers or floats), and a black-box program, calculate the score using the following scoring system:

Let $$\R_n\$$ be the expected output of the $$\n^{th}\$$ input, let $$\A_n\$$ be the actual output given by the black-box program, and let $$\ j \$$ be the total number of input/output pairs. (All values are positive and non-zero)

Then the score is defined as: $$S=\left\lceil L\times\max_{1\le i \le j}\left({\max\left(\frac{A_i}{R_i},\frac{R_i}{A_i}\right)^2}\right)\right\rceil$$ where $$\L\$$ is the length of the black-box program in bytes.

Example:

If the size of the program is $$\100\$$ bytes and the worst approximation is on the input "moon", where the program outputs $$\1000\$$ instead of the expected $$\1737\$$, then the score would be:

$$S=\left\lceil 100\times{\left(\frac{1737}{1000}\right)^2}\right\rceil=302$$

This system is taken shamelessly from this challenge by @Arnauld. Here is his reference implementation.

: You may take the inputs and outputs either zipped ([(in1, out1), (in2, out2), ...]), or not zipped (([in1, in2, ...], [out1, out2, ...]), with both lists of the same length), at your option.

: You may take the black-box program as either:

• a black-box function, and its length in bytes, as two separate inputs
• a string of code to be evaluated, as one input (the length will not be given separately unless necessary)

# Rules

• (1) is it a problem if the program only support integers? (2) is it guaranteed that both values (actual and submission output) are strictly positive? The formula is not well defined when either value is zero. – user202729 Feb 15 at 13:17
• @user202729 all values will be positive; the idea was that you can support integers or floats, whichever is easier – pxeger Feb 15 at 13:23
• The "whichever is easier" part is currently not mentioned in the challenge. – user202729 Feb 17 at 10:36

# Stack half full or half empty? (worldview of a programming language)

Is the glass half full or half empty? It's a common rethoric question to determine a person worldview, which can be optimistic or pessimistic based on the answer given. If i were dealing with a machine i would probably ask "Is the stack half full or half empty?" Let's try and see if programming languages have a worldview too.

Write a full program or a function which prints or returns one of "The stack is half full." or "The stack is half empty." when given as input the question "Is the stack half full or half empty?" but wait.. you have to provide a stack to be observed.. which stack you provide is up to you: input one or check an already existing stack. Your solution will then output one of the two sentences mentioned above for a non empty / non full stack, your choice which one to print, just make sure your answer is as short as possible because this is . For an empty stack it must produce the "empty" output while for a full stack "full".

# Survey

I will make a chart of the pessimistic Vs optimistic languages based on the half outputs. If you find the same byte count for both choices you can provide both, in which case they will count on both sides of the chart, but you just can select one if you like.

## input

• A sentence in any reasonable method.
• The behavior is defined only for the question "Is the stack half full or half empty?" and exactly this.
• Indeed your solution can also completely ignore the input as long as it works with the specified input.
• Question mark is mandatory.

## output

• One of "The stack is half full." or "The stack is half empty.", for a non full / non empty stack.
• "full" or "empty" for a full stack or an empty stack respectively
• upper / lower case or a mix are fine.
• ending dot not mandatory.

# Rules

• Only the mentioned input allowed.
• Loopholes allowed.
• This is and the answer with the fewer bytes of source code wins.
• This would be a really cool challenge, but the tasks are too similar. I doubt anything other than print "The glass is half full" will be competitive. Maybe add an additional thing they have to do, in addition to printing the text? As an example, for half empty, take a number of inputs and discard every second one. For half full, print every other fibonacci number. – Redwolf Programs Feb 18 at 20:41
• So undefined behaviour is fine for all inputs that are not one of the two specific questions? – Adám Feb 18 at 20:41
• Your initial description only mentions one possible input, while your "input" section mentions both. – Adám Feb 18 at 20:42
• Thanks @Redwolf Programs ! To be honest I had this crazy idea but don't really knew how to make it interesting.. I ended developing it in the simplest and most obvious way.. Maybe I 'll change many things during the sandbox – AZTECCO Feb 18 at 20:48
• @Adám yes for UB, for the input I'm sorry, my fault.. Initially I was using only one question but then decided it was reasonable to handle both combinations.. Gonna edit thanks! – AZTECCO Feb 18 at 20:51
• @Redwolf Programs I changed a bit, I hope this stack thing will add some flavor without exiting the context, please let me know if you want to share some opinions – AZTECCO Feb 21 at 18:43
• @Adám some changes.. If you have any opinions please let me know – AZTECCO Feb 21 at 18:45
• @AZTECCO I still think half empty and half full should require doing different things. Currently I doubt anyone will pick half empty, because half full is shorter and there's no other difference. – Redwolf Programs Feb 22 at 0:24
• @Redwolf Programs yeah that's true. I was wondering if languages with built in string compression, string methods or regex would compete the plain print"..answer.." method which should be around 25~30 of score but.. I don't know.. I just feel like a do this or that based on input is a different challenge but it seems to be the only way – AZTECCO Feb 22 at 9:21
• @AZTECCO The concept of the answers choosing between two options is really cool and unique; the current options are just too similar. Maybe one thing that tests control flow, like a truth machine sort of thing, and one that tests input/output, like discarding every other output? The stack validating thing (where you have to print empty or full) feels kind of irrelevant to the cool part of the challenge. Having the input be the question isn't really necessary IMO; you could replace the input with something like a list of numbers (cont.) – Redwolf Programs Feb 22 at 16:19
• (cont.) and have the answers do one of two things with that list (totally up to you, although I'd recommend tasks that use different capabilities of the language, like one control flow and one math), then print The glass is half (empty|full). – Redwolf Programs Feb 22 at 16:20
• @Redwolf Programs thanks for explaining your opinion, your insight are really important and I totally agree, I was losing the scope and your words got me back on track! – AZTECCO Feb 22 at 19:27

# Bytewise look-and-say sequence code-golf

The look-and-say sequence is a sequence which begins with 1, 11, 21, 1211, 111221, 312211. To get a term of the sequence from the previous, read the previous out literally:

312211 => one three, one one, two twos,two ones => 13112221

So the next term is 13112221.

Given this javascript code (Node.js), which outputs the look-and-say sequence indefinitely, delimited by newlines:

function nextTerm(x){
return x.replace(/(.)\1*/g,z=>z.length+z)
}
function printUpTo(x){
var str = '1';
for(var i = 0; i < x; i++){
console.log(str);str = nextTerm(str);
}
}
printUpTo(Infinity)


It will output a string that begins 1\n11\n21\n1211\n111221 etcetera. Your job is to write a function that takes a number as input and outputs that byte of the output string.

## Rules

You may output a different character for newline instead of \n, e.g. # or something.

## Scoring

Your program should be able to handle 100 million.

The first answer to handle 1e+18 correctly will receive a 100-rep bounty. This cannot be hard-coded.

Standard loopholes apply.

Test cases:

1 => \n
5 => 2
10 => 1
20 => 3
50 => 3
100 => 1
1000 => 1
100000 => 3
10000000 => 1


This is , so shortest bytes wins.

• Note that restricted-complexity means "solutions' time complexity must be polynomial in the input size" or something similar. "In a minute" means restricted-time, but then you have to specify the specification of your machine and test all solutions (although in most cases it will be obvious and you don't need to) – user202729 Feb 20 at 9:39
• And an implementation of the naive algorithm in a low-overhead language (C++) would be able to do that as well. – user202729 Feb 20 at 9:40
• @user202729 I'm not actually sure how to write this myself - notice that there isn't a testcase for 1 billion - that's because I couldn't figure out how to do an actually efficient version. Also, by 'In a minute', I mean on TIO. I'll add that. – A username Feb 20 at 9:44
• And TIO isn't suitable for timing submissions (personally I think it's really suitable, but people don't agree.) – user202729 Feb 20 at 9:45
• @user202729 What do you mean? Is it something to do with how busy the server is or similar? – A username Feb 20 at 9:46
• codegolf.meta.stackexchange.com/questions/12707/… – user202729 Feb 20 at 9:48
• @user202729 Ok, redoing the whole thing, since I don't want to install loads of different compilers/interpreters. – A username Feb 20 at 9:50
• Ok, publishing. – A username Feb 22 at 4:30
• Wait, I did warn you that a naive implementation in C++ would be able to do it. – user202729 Feb 22 at 4:30
• Do you want to allow that? – user202729 Feb 22 at 4:31
• Ok, 1e+12 should be fine. – A username Feb 22 at 4:31
• Wait are you sure that there actually is a polynomial time solution? – user202729 Feb 22 at 4:32
• I feel like there should be one, but I don't know. Never mind. – A username Feb 22 at 4:33
• Actually there probably isn't since there's no way to calculate the nth term or length of nth term without calculating the previous. So never mind. – A username Feb 22 at 4:36
• There probably is. (I didn't come up with one.)Although people could let their programs run for a month. 1e+18 is definitely safe, but might be a little too large for some polynomial approaches. – user202729 Feb 22 at 4:36

# Self improving program

In this challenge you will write a program or function which when run will output a faster solution to this challenge.

Formally speaking: you will write a program or function, $$\T_0\$$, which takes an integer $$\x\$$ as input and outputs a program or function (in the same language), $$\T_1\$$, which is itself a valid solution to this challenge, such that there exists a function $$\f\$$ where $$\T_1\$$ is in the time complexity class $$\O\left(f\right)\$$, but $$\T_0\$$ is not. That is to say the output program must have a strictly faster asymptotic time complexity.

Note that since $$\T_1\$$ must be a valid solution to the challenge it must output a program or function $$\T_2\$$ which is even faster, and so on and so forth, creating an infinite chain each faster than the last.

Answers will be scored by their length in bytes with fewer being better.

# Precision

In keeping with the tradition of this site, and to remain inclusive: The order notation of a function will be assumed to be measured by the algorithm implemented by your answer. Thus we will pretend not to notice the behavior of your actual program for inputs out of the range of your language's numeric type.

However that being said, in order to ensure that you are actually changing the algorithm at every step, for constants initialized in your program this leniency is not given. e.g. If you use a double precision floating point 1.0000000000000001 is equal to 1.0. So if your method relies on an increasing or decreasing constant embedded in the program you should be careful that the algorithm actually changes.

Simply put for $$\T_n(x)\$$ you are forgiven for errors arising from very large $$\x\$$, but not from very large $$\n\$$.

• (which is the same thing is $T_0\in o(T_1)$.) – user202729 Feb 20 at 9:54
• How is this possible? You'd need to get faster and faster, and even if you do it exponentially, you can't change the speed by tiny fractions of a second each time. Please explain, very confused. – A username Feb 20 at 9:54
• And what prevents programs from doing for i in range(int(n**1.00001)): pass? – user202729 Feb 20 at 9:55
• Thinking about it again, since programs can simply run a loop to have any asymptotic complexity (>= complexity to parse input), it's not that hard. And you could just ask programs to print out an always-decreasing floating point value plus the new program. – user202729 Feb 20 at 9:57
• @user202729 But the always-decreasing float is the problem here, because eventually it will get too small to be distinguished by the language from 0. – A username Feb 20 at 10:01
• @Ausername An easier way to have it constantly decreasing is to have O(n^2) -> O(n log(n)) -> O(n log(log(n))) -> O(n log(log(log(n)))) etc. This approaches O(n) from above and remains distinguishable for really large inputs, without requiring anything finicky about precision. – Wheat Wizard Feb 20 at 10:02
• @user202729 Do the precision rules address your comments? – Wheat Wizard Feb 20 at 10:17
• It means that programs doing things like (Python) n=1000000000000000000000000000000; for i in range(int(input())**(1+1/n): pass and (1+1/n) evaluates to 1 (because of IEEE754, even though the value of n is stored exactly) will fail? – user202729 Feb 20 at 11:45
• @user202729 Yes. Precision rules are always pretty non-concrete and non-objective. I think it is best to not try to push at the boundaries. – Wheat Wizard Feb 20 at 12:49

Posted at Convert Gemtext to HTML but moved here to discuss

Gemtext is a very simple markup format used by the alternative web protocol Gemini. Write a Gemtext to HTML converter.

From the Wiki:

A line of text is a paragraph, to be wrapped by the client. It is is independent from the lines coming before or after it.

A list item starts with an asterisk and a space. Again, the rest of the line is the line item, to be wrapped by the client.

A heading starts with one, two, or three number signs and a space. The rest of the line is the heading.

A link is never an inline link like it is for HTML: it’s simply a line starting with an equal-sign and a greater-than sign: “⇒”, a space, an URI, and some text. It could be formatted like a list item, or like a paragraph. Relative URIs are explicitly allowed.

Example:

# This is a heading
This is the first paragraph.
* a list item
* another list item
This is the second paragraph.
=> http://example.org/ Absolute URI
=> //example.org/ No scheme URI
=> /robots.txt Just a path URI
=> GemText a page link


This should produce this HTML tree (just the equivalent tree, not the exact formatting):

<h1>This is a heading</h1>
<p>This is the first paragraph.</p>
<ul>
<li>a list item</li>
<li>another list item</li>
</ul>
<p>This is the second paragraph.</p>
<a href="http://example.org/">Absolute URI</a>
<a href="//example.org/">No scheme URI</a>
<a href="/robots.txt">Just a path URI</a>
<a href="GemText">a page link</a>


HTML in the text must be escaped, e.g paragraph <p> is cool becomes <p>paragraph &ltp&gt is cool</p>.

This is so the shortest code in bytes wins

• Can you clarify "whitespace ... doesn't matter"? – Wezl Mar 1 at 19:30
• @Wezl edited question – R Harrington Mar 1 at 19:36
• What parts of HTML do we need to handle? Can we convert every character (even unreserved ones like A) to its entity number? Is the input guaranteed to be ASCII only or do we need to handle other characters? I don't know Gemtext well enough to ask about it, but are there escape characters or something that would allow mapping, say, to HTML: <p># A paragraph</p>? – FryAmTheEggman Mar 1 at 19:53

# Dedekind, cut!

## Objective

Given a Dedekind cut and a nonnegative integer $$\n\$$, print the real number represented by the Dedekind cut up to $$\n\$$ precisions, rounded.

## Dedekind cut

A Dedekind cut representing a real number $$\x\$$ is a boolean-valued function on $$\\mathbb{Q}\$$ that gives a falsy value for rational numbers under $$\x\$$, and a truthy value otherwise.

Note that Dedekind cuts can represent arbitrary real numbers. Irrational, nonconstructible, transcendental, or even uncomputable numbers.

## Rules

• Direction of rounding is implementation-defined.

• For the inputted Dedekind cut, it shall accept arbitrary rational numbers. That is, the numerator and the denominator must be arbitrary-length integers. (Though the denominator is nonzero, of course) Accepting the rational number as a pair of integers is acceptable. In this case, the denominator is expected to be positive, and the fraction is expected to be irreducible.

• Invalid inputs fall in don't care situation. This also applies to the rational numbers the Dedekind cut accepts.

• Note that negative numbers also must be handled. For nonnegative numbers, however, it is implementation-defined whether to output a leading plus sign.

• Outputting leading or trailing whitespaces is permitted.

• All digits after the decimal point shall be considered significant in this regard. The amount of significant digits after the decimal point must be exactly $$\n\$$. Trailing zeros cannot be discarded.

• If $$\n = 0\$$, the decimal point may be omitted.

• If the decimal representation has no significant digits before the decimal point, the leading zero may be omitted.

• The omission from the previous two rules cannot be present simultaneously.

## Examples

• For $$\x = 0\$$ and $$\n = 0\$$, output one of 0, 0., +0, and +0..

• For $$\x = 0\$$ and $$\n = 2\$$, output one of .00, 0.00, +.00, and +0.00.

• For $$\x = ½\$$ and $$\n = 0\$$, output one of 0, +0, 1, +1, 0., +0., 1., and +1..

• For $$\x = ½\$$ and $$\n = 3\$$, output one of .050, 0.050, +.050, or +0.050.

• For $$\x = \sqrt{2}\$$ and $$\n = 3\$$, output either 1.414 or +1.414.

• For $$\x = -\pi\$$ and $$\n = 3\$$, output -3.142. Note the rounding.

## Ungolfed solution

### Haskell

An implementation with exponential time complexity.

import Text.Printf

showDedekind :: (Rational -> Bool) -> Int -> String
showDedekind x n = go (0.5 * 10 ^^ negate n)
where
go p = let
epsilon = 10 ^^ negate n
in if x p
then if x (p - epsilon)
then go (p - 2 * epsilon)
else let
str = printf "%0*d" n (floor (p / epsilon) :: Integer)
(str1, str2) = splitAt (length str - n) str
in str1 ++ '.' : str2
else go (p + epsilon)

• So to be precise, the input value x is actually given as a black-box function, right? For output format, I recommend to keep it simple. You can even omit it entirely so that we can assume a convenient format for each language in use (under default I/O rules). Should the solutions theoretically support arbitrarily large x (with both signs)? – Bubbler Mar 2 at 9:08

# Let's rise higher!

(I am posting this challenge in sandbox because this kind of exceptional challenges are often closed, and then downvoted to oblivion, so I want to get your feedback and with kind help you fix the specifications in this challenge, and make it interesting, Thanks!)

# Challenge

The main objective of the challenge is pretty simple, this is an answer chaining contest, where you have to serially print numbers from 1. That means User 1's answer will print 1, then User 2's answer will print 2 and so on. But there are some rules to make the contest tougher.

# Rules

• You can't use the characters of the source code used in the previous answer.

• Each answer cannot use more than 12 distinct bytes.

• Use of comments in your code is disallowed.

• You cannot post 2 answers in a row, let me explain, suppose you have written answer no. 5, now you cannot write answer no. 6, you have to wait someone to post a valid answer no. 6 (That prints 6 without using characters in answer no. 5), and after that you can write a valid answer no. 7 following the rules.

• Program cannot take input or access internet.

• Standard loopholes apply.

# Scoring criterion

This is not challenge, so there is a custom objective scoring criteria. Try to make your score higher.

• Each answer's initial score is 1. (Only chain beginning answer has score 0).

• For each distinct byte you use, your score is increased by the number of distinct bytes. That means if your number of distinct bytes is 6, then your score increases by 1+2+3+4+5+6, and if your number of distinct bytes is 7, then your score increases by 1+2+3+4+5+6+7 and so on.

• You have to calculate distinct byte difference with the previous answer, and add/subtract score using the 2nd rule. So if byte difference is 3 then you will get a +1+2+3 score, or if -3 (Previous answer has 3 more distinct bytes than yours), then -1-2-3.

• For first 40 bytes you will get a 0.15 score, but from then you have to minus 0.5 score. An example if your score has total 45 bytes then your score bonus will be (40*0.15)-(5*0.5)=6-2.5=3.5, so you have to add +3.5 to your score. (The score criteria is to encourage medium length smart answers.)

A total example:

Suppose,

• Your previous answer has 4 distinct bytes, and a total of 20 bytes
• Your answer has 7 distinct bytes, and a total of 56 bytes

So your score will be:

Distinct byte difference: (7-4)=3
Total score: 1+(1+2+3+4+5+6+7)+(1+2+3)+(40*0.15)-(16*0.5)=33


So you get a score of 33 for this condition.

# Answer format

# Answer Number. Language Name, x Bytes, y Distinct bytes, Score: Z

source code

(TIO/Any other interpreter link) -> Not required, but preferred


example

1. Powershell, x Bytes, y Distinct Bytes, Score: Z

......


# Winning criterion

Winner will be determined after 30 days, winner is determined by total score. But users are welcome to continue the chain after that!

Suppose you have three answers with score 33,16,78 then your total score will be 33+16+78=127.

And there is two special prizes from me after 30 days:

• +150 bounty for the winner.
• +50 bounty for the single answer with highest score! (Such as man of the match in Cricket)

# 1. PowerShell, 1 byte, 1 distinct byte, Score: 0

1


Try it online!

---

# Meta

• Are all rules clear?

• Please improve the scoring criterion and rules. (Especially please improve the second rule, I am not very sure about that.)

• Please make me a javascript snippet for leaderboard, to sort users by their total score.

• Any other feedback please.

• There are a bunch of small things that could be clarified (particularly the scoring), but I think there is a larger problem you should try to fix first. Answer-chaining challenges rely on the task becoming more difficult as more answers are posted, but since you are only restricted by the previous response getting an optimal score will probably not be difficult until the number of answers is very large (much larger than 100). If you fix this, then the problem becomes that if finding a good answer is difficult, posting for more score becomes a race, which usually isn't fun. – FryAmTheEggman Mar 3 at 18:32
• @FryAmTheEggman if the number of answers are large, then you would sort the question by active. What are the other problems please say. – Wasif Mar 4 at 6:58
• The number of answers being large isn't the problem. Please re-read my comment - it is talking about how the challenge isn't a good answer-chaining challenge because the approach for each link in the chain is too similar. Try writing what you think the next solution would be, and the one after that, and I think you will start to see the problem. – FryAmTheEggman Mar 4 at 14:42

# Finish what John McCarthy started (WIP) code-golfinterpreterlisp

This does not have anything to do with Joseph McCarthy or communism. Some background from Wikipedia (you can skip ahead if you like):

John McCarthy published the first paper on Lisp in 1960 while a research fellow at the Massachusetts Institute of Technology. In it he described a language of symbolic expressions (S-expressions) that could represent complex structures as lists. Then he defined a set of primitive operations on the S-expressions, and a language of meta-expressions (M-expressions) that could be used to define more complex operations. Finally, he showed how the meta-language itself could be represented with S-expressions, resulting in a system that was potentially self-hosting. The draft version of this paper is known as "AI Memo 8".

Example M-expressions McCarthy had planned to develop an automatic Lisp compiler (LISP 2) using M-expressions as the language syntax and S-expressions to describe the compiler's internal processes. Stephen B. Russell read the paper and suggested to him that S-expressions were a more convenient syntax. Although McCarthy disapproved of the idea, Russell and colleague Daniel J. Edwards hand-coded an interpreter program that could execute S-expressions.2 This program was adopted by McCarthy's research group, establishing S-expressions as the dominant form of Lisp.

# Task

Interpret a subset of M-expressions, where 9 primitive functions have already been defined.

## Syntax

Atoms: An atom is a series of any characters excluding [, ], ;. While an atom name can include whitespace, leading and trailing whitespace is ignored. Some examples include foo, lambda (also a function name), and nil (also a list). Atoms act as both variables and data (they're like strings).

Booleans: The atom t is truthy, whereas the atom nil is falsy.

quote: A series of expressions between square brackets, delimited by semicolons. [a; [b; c]; de] is equivalent to the S-expression (QUOTE (A (B C) DE)). It is somewhat like this JS list: ["a", ["b", "c"], "de"].

cond: A series of if-then pairs between square brackets, delimited by semicolons, with an arrow -> (you can use any other character(s)) separating the if-then pairs. e.g. [atom[x] -> x; t -> car[x]] yields x if it's an atom, or the first element of x if it's a list. It is guaranteed that at least one of the cases will be true.

Function application: Functions can be called using functionname[arg1; arg2; ...; argN].

• car - Return the first element of its argument.
• cdr - Return its argument without the first element.
• cons - Prepend its first argument to its second argument.
• eq - Check if its two arguments are equal.
• atom - Check if its argument is an atom.
• lambda - Define an anonymous function using the syntax lambda[[param1; param2; ...; paramN]; bodythatusesparams].
• label - Store a function using a name. For example, label[drop2; lambda[[xs]; cdr[cdr[xs]]]] defines a function drop2 that drops the first two elements of its first argument.

# Rules

• Functions may use lexical or dynamic scope, or some crazy mixture of both.

Much of this question is copied from this challenge and the Wikipedia article on M-expressions.

# Questions for Meta

• For cond, should I use the [condition -> res; condition2 -> res2; ...] syntax, or should I keep it like the linked challenge?
• Should answers support higher-order functions?
• Does anyone have any good examples using Mexprs?
• I did a double-take at the title, which sounds like the challenge is to root out communists still hiding in the US state department to finish what Joseph McCarthy started... – xnor Jan 20 at 10:23
• @xnor Uh...that certainly was not what I intended. I could probably say "Finish what John McCarthy started" or just "Interpret M-expressions", although the latter sounds more boring. There's also a Eugene McCarthy, apparently, so I guess just McCarthy is too ambiguous. – user Jan 20 at 13:59
• – pxeger Mar 10 at 16:41
• If you want do disallow trivial answers that use quit or comments or something, you could require all 3 programs to be irreducible. However, I think it might not be as interesting like that, because it would then just be the same as all the existing irreducible restricted-source challenges. It's still an interesting challenge to optimise the length of three similar programs with the same charset. Extra feedback: I'd recommend changing Hello, World! to another string because many languages have Hello World built-ins. – pxeger Mar 10 at 16:47
• Also, maybe specify that functions are allowed as well as programs, according to our I/O defaults. And can you clarify whether the Hello World has to include the quotes? – pxeger Mar 10 at 16:51
• @pxeger Thanks, I have updated my post and I agree that the irreducible rule is not needed. Even a "trivial" answer seems challenging to arrive at. About the string, maybe I can change it to "Hello, Permutations!" which also goes with the challenge title, but I am unsure if I should. – Manish Kundu Mar 10 at 17:18
• Hello, Permutations! sounds fine - I think it would be a good idea. Again, can you clarify whether you want the double quotes around "Hello, Permutations!" to be outputted literally or not? – pxeger Mar 10 at 17:25
• @pxeger Changed it, and its clarified now. – Manish Kundu Mar 10 at 17:29

# Uppercase JSON member names

Given a single valid JSON value, uppercase all member names. That is, you must also return valid JSON that encodes an equivalent value, except that all names of members in all objects, have been converted to uppercase according to one of the Unicode methods (simple or full).

Details:

• The given value can be null, a number, a string, an array, or an object. There may therefore not be any names to convert, but such names can also "hide" as elements/members of arrays/objects in arrays/objects, …

• Dictionaries are considered unordered.

• Names and strings will only encode ASCII.

• Keys will be unique, even after case conversion.

• Floating point imprecision is tolerated.

## Example input A

["a\":",{"b":"c"}]


### Example outputs

["a\":",{"B":"c"}]

[
"a\":",
{
"B" : "c"
}
]


## Example input B

{"h\u0065re":
"are'=",    "be"
:{"dra\u0000gons":true,"b\\e\"ar\ns":"two"},"\t":[1e-0,null,3e+2
,  {"":""} ,{
},
"name\":\"value",[false,[],[[]]]]}


### Example outputs

{
"BE": {
"B\\E\"AR\nS": "two",
"DRA\u0000GONS": true
},
"HERE": "are'=",
"\t": [1,
null,
300,
{
"": ""
},
{
},
"name\":\"value",
[false,
[],
[[]]]]
}

{"BE":{"B\\E\"AR\nS":"two","DRA\u0000GONS":true},"HERE":"are'=","\t":[1,null,300,{"":""},{},"name\":\"value",[false,[],[[]]]]}

• Is order of keys in a dictionary matters? For example, input {"b":0,"a":0}, may I output {"A":0,"B":0}? Will there be any duplicate object keys? For example, is {"a":1,"a":2} a valid input? ECMA-404 allow duplicate keys, but RFC 8259 disallow it. For above input, may I output {"A":2} only? What about duplicate keys after conversion? For example, is input {"a":1,"A":2}valid? And what should I output? – tsh Mar 15 at 6:28
• @tsh How is this? – Adám Mar 15 at 6:33
• May I assume keys only contains characters in range U+0020~U+00FE? For example, are keys like {"großes":1,"æða":2,"ｈｅｌｌｏ":3,"βῆτα":4} invalid? – tsh Mar 15 at 6:33
• @tsh non-ASCII keys are literally mentioned in the bullet points and included in the example case. – Adám Mar 15 at 6:33
• May I output DRA\u0000GᎤNSS for dra\u0000gꭴnßinstead of DRA\u0000GᎤNß? – tsh Mar 15 at 6:37
• @tsh Silly me for not thinking of the various methods. Addressed. – Adám Mar 15 at 6:42
• @tsh All answered: 1: "Dictionaries are unordered." 2: "Keys will be unique" 3: "Keys will be unique, even after case conversion." – Adám Mar 15 at 6:44
• May I use different unicode normalization from inputs? For example, Input {"e\u0301":1}, may I output {"\u00c9":1}? And for input {"\u00e9":1}, may I output {"E\u0301":1}? – tsh Mar 15 at 6:47
• @tsh Good point. Addressed now. Do you think it would be an improvement to restrict input to ASCII only? – Adám Mar 15 at 6:52
• Try to support uppercase for non-ASCII would simply require submission in some languages with such a built-in support. And as code-golf context, no one would likely to handle it manually. So restrict it to ASCII only would be helpful to let more languages involved. – tsh Mar 15 at 7:14
• @tsh Done. How is this? – Adám Mar 15 at 7:16
• You are still using "ꭴ" in it. Also suggest testcases with object in array: {"extra":[0, {"key":[[[{"inner":{}}]]]}]} – tsh Mar 15 at 7:24
• @tsh Did you refresh? I don't see any "ꭴ". There are objects in the "\t" array. – Adám Mar 15 at 7:27
• Will input always be a json object (dictionary)? For example, another testcase ["a",{"b":"c"}], null, And maybe it need more testcases. And if I try to parse the JSON string first, may floating point errors allowed? For example, input {"a":[17706675576718736274, 300223795848957673199326286566205161047]}, may I output {"A":[17706675576718735000,3.0022379584895768e+38]} – tsh Mar 15 at 7:31
• @tsh Good questions. Should all be addressed now. – Adám Mar 15 at 7:36

## Minimally Making Change

• What is expected output for 10? To my understanding, it should be 0010, but you give 5100. Am I misunderstand something? – tsh Mar 16 at 11:33
• @tsh They have to be able to make all cents 1-10 with the coins. So they need 5 pennies for making 1-4 and the nickel to make 9. Hopefully clarified a bit – Medix2 Mar 16 at 12:35

# Find the Best Set of Adapters

Moved here: Find the Best Set of Adapters

• This reminds me of one of the 2020 AoC challenges, don't remember exactly what the task was but it had a similar premise. (Also there's no need to disallow standard loopholes explicitly, they're disallowed by default :p) – Redwolf Programs Mar 12 at 1:44
• It was "Day 10: Adapter Array" but that was about finding the number of ways to reach the result and the adapters were a bit different. – user197974 Mar 12 at 3:42
• This looks like it'll be a fun challenge, although I'd be careful to look around because there might be a duplicate with an entirely different name/background that involves doing the exact same thing. – Redwolf Programs Mar 12 at 4:14
• May it contains adapter from A -> A? Although it would be not useful. It could be included in testcases. (make sure implementation will not fall into infinity loop in such case.) Will it possible 0 adapter is required (Same type for both computer and phone already)? If so, add another testcase for it. – tsh Mar 15 at 9:00
• Also, is it possible that part of given graph is not connected to computer / phone types. For example, A, C; A->B; B->C; X->Y; Y->Z. – tsh Mar 15 at 9:02
• Current testcases does not contains cycle. It would be helpful to include one: A, C; A->B; B->C; C->A for example. – tsh Mar 15 at 9:04
• Your description says "Unfortunately, none of them can go straight from my phone to my computer". but your last testcase output 1. One of them should be incorrect. – tsh Mar 15 at 9:04
• Thanks, @tsh for the great feedback. I have edited the question with your suggestions in mind. – user197974 Mar 15 at 18:37
• 2nd test case seems incorrect. – tsh Mar 16 at 11:28
• @tsh thanks, fixed – user197974 Mar 16 at 15:45

# Fortuitous Numbers

Four is Magic is a very interesting math game.

1. We start out with a number: 1
2. We spell it into English: “one”
3. We find the sum of the letters: 3
4. Go back to step 2, until the game ends at “4”

The reason “4” is Magic, is that “Four” has 4 letters, and no other number has this property.

### Fortuitous Numbers

In this game, I’m making one change.

1. Take for example the number: 24.
2. Write it out in English: “twenty four”
3. Note that there are 2 words
4. Take the product of the word lengths
5. 24 - “twenty four” - 6 * 4 = 24

4 and 24 are Fortuitous Numbers. Are there any more?

### The challenge

Your challenge is to create a piece of code that will generate all Fortuitous Numbers.

Specifically:

1. Solutions should be found by the program, not chached by you.
2. We never say, “one hundred and one”. Exclude the “and”
3. The only output should contain a comma separated list of only the solutions:
4,
24,
n,
m,

1. The code should have no limit as to how large the number can go. If you have trouble finding names, used the ones mentions in this Wikipedia article. This will take you smoothly to 103003 and beyond.
2. Hint: Look at the sequence, A058230.

### Bonus!

1. Program generates the first 9 solutions relatively quickly (under 5 minutes time.)
2. Program also finds Fortuitous Numbers if type a -> b -> ... -> a instead of just a -> a

## ROT47(code) code-golfciphersource-layout

ROT13 is a Caesar cipher where every letter is replaced by the 13th letter that follows it in the alphabet.

Every letter and its counterpart:

a b c d e f g h i j k l m n o p q r s t u v w x y z
n o p q r s t u v w x y z a b c d e f g h i j k l m

ROT47 is a deritave of ROT13 which includes all the ASCII printable characters except space. Rot47 substitutes every character with the 47th character that follows it in the ASCII range.

Every character and its counterpart:

! " # $% & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _  a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ P Q R S T U V W X Y Z [ \ ] ^ _  a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ ! " #$ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O

I ROT47( your code) and you ROT47( the output)

• Your code is supposed to at least output 1 character within the [33,126] ASCII range.
• When ROT47 is applied on your code, the output should also be ROT47 of the previous output
• solve in the fewest bytes possible

Below a ROT47 converter taken from decode

var input = document.getElementById("input");
var editor = CodeMirror(input, {
lineNumbers: true,
tabSize: 2,
mode: 'javascript',
theme: 'monokai'
});
editor.setSize(900, 100);
document.getElementById("button").onclick = function(){
editor.setValue(rot47(editor.getValue()));
}

//implementation below from https://www.dcode.fr/rot-47-cipher
// Javascript
function rot47(x){
var s='';
for(var i=0;i<x.length;i++){
var j=x.charCodeAt(i);
if((j>=33)&&(j<=126)){
s+=String.fromCharCode(33+((j+14)%94));
}
else {
s+=String.fromCharCode(j);
}
}
return s;
}
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.60.0/codemirror.min.css" integrity="sha512-xIf9AdJauwKIVtrVRZ0i4nHP61Ogx9fSRAkCLecmE2dL/U8ioWpDvFCAy4dcfecN72HHB9+7FfQj3aiO68aaaw==" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.60.0/codemirror.min.js" integrity="sha512-hc0zo04EIwTzKLvp2eycDTeIUuvoGYYmFIjYx7DmfgQeZPC5N27sPG2wEQPq8d8fCTwuguLrI1ffatqxyTbHJw==" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.60.0/theme/monokai.min.css" integrity="sha512-R6PH4vSzF2Yxjdvb2p2FA06yWul+U0PDDav4b/od/oXf9Iw37zl10plvwOXelrjV2Ai7Eo3vyHeyFUjhXdBCVQ==" crossorigin="anonymous" />
</head>
<body style="background-color:#333333
">
<div id="input">
</div></br>
<button id="button" style="background-color: #17202a
;color:white">ROT47</button>
</body>

### Meta questions:

• Is it an interesting challenge?
• Is the explanation clear?
• suggestion for a title.
• why does it look normal in edit mode but not in the result 😡. – Alex bries Mar 23 at 19:43
• Fixed the formatting. SE doesn't show tables unless they have an empty line before and after them – caird coinheringaahing Mar 23 at 19:56
• so valid answers and their input must be printable ASCII? Or should it ignore anything not printable? – Wezl Mar 24 at 16:45
• It looks like the reference implementation leaves non-printable characters and space alone. It would be helpful to specify that. – Wezl Mar 24 at 16:50
• Well, if you look on main, this is a alternate of an alternate of a rip-off of a rip-off of a rip-off of a rip-off of a rip-off of a rip-off. (see this). Which is not to say it's a bad challenge. – A username Mar 25 at 8:40

# Leave a wake of dead cells behind you

Conway's Game of Life is a well known cellular automaton "played" on an infinite grid, filled with cells that are either alive or dead. Once given an initial state, the board evolves according to rules indefinitely. Those rules are:

• Any live cell with 2 or 3 living neighbours (the 8 cells immediately around it) lives to the next state
• Any dead cell with exactly 3 living neighbours becomes a living cell
• Any other cell becomes a dead cell

Game of Life is known for having simple rules yet structures can quickly become chaotic with minimal change.

Consider the following initial state: That is, TNB made up of live cells. Each letter has a $$\5\times7\$$ bounding box, with an empty column in between, for a $$\16\times7\$$ overall bounding box

After 96 generations, it reaches the following state: From this point, no meaningful change will happen: there is 1 still life and 1 oscillator which does not interact with the still life.

Now, let's place 2 $$\9\times9\$$ "areas" on either side: You are to place up to $$\81\$$ living cells in the red area in a configuration $$\C\$$, so that, when run, there is at least one generation (the target generation) for which the following is true:

• The red box is empty (i.e. consists of $$\81\$$ dead cells)
• The configuration in the blue box is equal to $$\C\$$
• All other cells on the board are dead.

For example, let's assume your starting configuration $$\C\$$ is Then, for this to be a valid answer, the following state would have to be reached by at least 1 generation: (and there's no other living cells on the board)

What the board looks like before and after the target generation is irrelevant, so long as at least one generation meets these conditions.

Your score is equal to the number of living cells in $$\C\$$, aiming for fewer cells, with ties being broken by fewest generations until the target generation

# Meta

• What if this is impossible? – Beefster Mar 24 at 15:44
• @Beefster Then I'll happily accept a proof of impossibility – caird coinheringaahing Mar 24 at 16:24

# To count the sum of all Unicode characters of a given input under an interesting constraint

• Welcome to the site, and thank you for using the sandbox! Can you confirm that answering with a normal (base-10) number is OK? – Adám Mar 25 at 6:37
• Thanks for the comment, edited accordingly- Final answer can to be calculated in any base (either Hexadecimal, or base-10 or binary as per the program) no need to convert back. – Aatmaj Mar 25 at 9:55
• I know you've posted this already, but generally I recommend leaving challenges in the sandbox for a week. – Adám Mar 25 at 11:19
• Ohk. I will remember it from the next time. thanks a lot – Aatmaj Mar 25 at 11:19
• I've edited this down to a stub now that it's been posted to save space – caird coinheringaahing Mar 30 at 21:38

# Sum of two squares

Given an integer $$\n\$$, determine whether $$\n\$$ can be expressed as the sum of two square numbers, that is $$\\exists a,b\in\mathbb Z|n=a^2+b^2\$$.

   0 -> truthy
1 -> truthy
2 -> truthy
3 -> falsy
4 -> truthy
5 -> truthy
6 -> falsy
7 -> falsy
11 -> falsy
9997 -> truthy
9999 -> falsy


Relevant OEIS sequences:

This is , so shortest answer as measured in bytes wins.

• This is a subset of this problem. – hyper-neutrino Mar 31 at 5:29
• @HyperNeutrino yes, and I have that listed as a related problem. There's actually another method of solving this problem involving prime factors which doesn't work for that one, so I'm hoping that's novel enough to warrant a separate challenge. – hakr14 Mar 31 at 18:16
• My bad, didn't notice the link. And yes, I don't think it'd be a duplicate here; I do agree that there will probably be unique approaches to this specific problem. – hyper-neutrino Mar 31 at 18:18
• A couple answers here used the prime-factorization approach, and a few used the approach of counting divisors of the form 4k+1 and 4k+3 respectively. – xnor Apr 2 at 6:50

# Irreducible Rube Goldberg Sort (WIP)

You are given a list containing at least 10 integers. You must sort them in the most complicated and roundabout way possible.

Your task is to write $$\n\$$ programs (or functions) which, when combined in a specific constant sequence (specifically, feeding the output of the current step into the input of the next step), result in a sorted version of the original list. This sequence of programs should be set up in such a way that the system will not work if any subset of steps is removed. (for example, compressing and decompressing the stream, roundabout encryption that cancels itself out, etc...)

Your score is $$\n\$$. Highest score wins.

## Rules, Clarifications, and Notes

• Standard rules and loopholes apply
• Any method of I/O is fair game. It does not need to be consistent across all programs/functions.
• You may use any number of programming languages to solve the problem.
• It should not take an unreasonably long time to sort a list of up to 1000 elements using your system of programs. It should be reasonable to run it from start to finish during a lunch break (30 minutes)
• Lists can contain any integer from -999,999,999 to 999,999,999, inclusive, and may contain indistinguishable duplicates.
• Your system of programs should work for lists of any size if given enough time and space.
• What is there to put an upper bound on the size, other than irreducibility? I'm almost certain there's a way to get an infinite score pretty trivially. – Redwolf Programs Apr 1 at 16:30
• I suspect there's a way to have an arbitrarily complicated sequence of programs as well and I'm not quite sure how to limit that, aside from performance (the 30 minute rule) – Beefster Apr 1 at 16:33
• Does the process have to be deterministic (e.g. no implementation of bogosort)? I think your rules imply that, but it might be good to state explicitly. – water_ghosts Apr 1 at 18:17
• Throwing in a randomizer step probably wouldn't be irreducible. – Beefster Apr 1 at 19:13
• So a recursive approach (e.g. one similar to Stooge sort) is a no-starter? – Bubbler Apr 4 at 23:31
• @Bubbler feeding a step's output into its own input is not allowed, so yes, that probably wouldn't work. Basically, the idea is that you could run this as a bash pipeline and no matter what the input sequence is, you wouldn't be able to remove any subset of steps and have it still work. – Beefster Apr 5 at 23:06

# Ball game KoTH

• For the controller, instead of telling the bot which one it is, you could just use positive numbers for being closer to the bot and negative numbers if it's on the other side. This might also potentially be interesting if the other player's energy and moves were unknown. – Redwolf Programs Mar 26 at 5:50
• You're the KoTH expert - I'll change those. – A username Mar 26 at 7:50

# Dominate a zero-sum game

Write a rectangular code that takes a rectangular input and output it. If the code is repeated horizonally and vertically for times, output the input rectangular repeated for same amount of times.

Take an example, if your submission is

CODE
HERE


, then program

CODECODECODECODE
HEREHEREHEREHERE
CODECODECODECODE
HEREHEREHEREHERE


inputting

01
23
45


should output

01010101
23232323
45454545
01010101
23232323
45454545

• Nice one. But I didn't understand if there is s specific output. – math Apr 4 at 11:51

Create a C program that is less than 120 characters the produces the most ASM possible.

This limit does not include the def of main, or including headers. If a function is called the chars in the function count toward limit. The same goes for macros. The compiler used will be GCC 10.2 -O3 targeting x86-64.

The code conforms to these parameters and produces the most instructions wins.

I have a few questions regarding this. Is the character limit too limiting? Is the choice of compiler a good one? Is the optimization level being -O3 a good idea? Please share any other thoughts you have.

Thanks

• I don’t see a reason to limit the size of the program. You could score based on Assembly Instructions per Source Byte to encourage small code sizes without excluding a clever 121 byte solution. I also don’t think the rules around #include headers and counting the size of any functions called are clear (How many characters are in printf?). You could ban explicit #includes but allow implicit function declarations as long as the compiler accepts them. – water_ghosts Apr 5 at 2:17
• Should printf be 6 chars or should it be the size of the definition of the function printf? I'm not sure about this. – expr_champ2 Apr 5 at 3:57

# KotH: Assembly Anarchy

Draft. Just posting this so I don't forget I had this idea. Feel free to suggest improvements to the general idea here.

Basically, there would be a computer with memory and a processor. Programs would be submitted in a custom assembly language, and they would try to run a function (their flag) as many times as possible. They could try to interfere with other programs, by doing things like replacing the pointer to another bot's flag with their own, or preventing other bots from being run.

• I like the concept. It needs a lot of fleshing out, though. – jumbot Apr 9 at 13:42

# Poor Man's DRM

Write a program that only prints Welcome at the first execution and first execution only. All executions after the first execution should only print Where money.

Anything is allowed as long as the following condition is met: An execution ends after the program exits. So the second execution can only start after the first execution exits completely.

Reason for the condition: to prevent submissions that linger around in the memory and keep a runtime counter.

• any things that are disallowed? E.g. can a program write to its source file? – Wezl Apr 8 at 20:18
• @Wezl no, actually that's what I originally had in mind when writing this, but I decided to keep all the options open. -- edit for clarification: by "no", I meant it is allowed. – goodguy Apr 8 at 20:18
• @goodguy Nice challenge. You may want to look at Standard Loopholes and main article – math Apr 9 at 14:36

# Cooperative counting

• looks like a nice challenge – math Apr 9 at 11:11
• I can't wait to code a bot for this challenge! – math Apr 10 at 8:56
• @math patience :) – jumbot Apr 10 at 9:45

# Multiplicative Persistence #2

• Hi, once again, is it clear enough? – math Apr 8 at 11:59
• How do the examples work? – l4m2 Apr 8 at 16:04
• @l4m2 If you mean how I coded that, I made an ungolfed version in python. – math Apr 8 at 16:07
• @l4m2 Or if you mean how the inputs are chosen, just somewhat random numbers. Except the first two. – math Apr 8 at 17:33
• Is it a duplicate? – math Apr 9 at 14:42

# Find the traitor cops-and-robbers (WIP)

In this challenge, the cops are the robbers/moles and the robbers are the cops/investigators.

## Cops

Cops will write a program that will output one of the following strings:

• "Hello World!"
• "Totally not evil stuff"
• "Good morning"
• "Innocent things"

However, when n specific characters are removed, where 0 < n < length of cop's program, the resulting program should output one of the following strings:

• "Bye World!"
• "Top secret stuff"
• "Evil things"
• "Horrible morning"

Cops will reveal the original program and n, but not the resulting program. They will also reveal the 2 strings that must be outputted by the original and transformed programs.

A cop's score is $$\\binom n r\$$, or $$\\frac{n!}{r!(n-r)!}\$$, where $$\r\$$ is the size of the cop's program and $$\n\$$ is the number of characters to be deleted. The lower the score, the better.

### Rules

• The original and transformed program may output in different ways, as long as the cop specifies what they are.
• The characters to be deleted do not have to be adjacent.

## Robbers

Robbers must find a way to make the cop's program output the chosen 2nd string by removing any n characters (not necessarily the same as the cop's).

## Example cop

Python, n = 1

a = ["Totally not evil stuff", "Hello World!"]
print(a)


The original string is "Hello World!", and the transformed program prints "Totally not evil stuff".

## Example robber

Python, cracks Foobar's answer

a = ["Totally not evil stuff", "Hello World!"]
print(a)


Deleting the 1 at the end of the first line prints the target string.

## Questions for Meta:

• Which original and transformed strings should I use?
• Is this a duplicate?
• This could be kind of difficult to write a cop for that doesn't just rely on someone brute forcing it – Redwolf Programs Apr 11 at 0:21
• @RedwolfPrograms Hmm, you're right. I guess just saying "pls don't brute force" wouldn't work. Maybe instead of a string, submissions could implement a mathematical function? You wouldn't be able to verify, say, cosine using just brute force. – user Apr 11 at 0:23
• That could be really cool actually. If you had a variety of ones like sqrt, tan, factorial, sum of proper divisors, and so on it would be a lot of fun. – Redwolf Programs Apr 11 at 0:30
• @RedwolfPrograms Only problem would be that there wouldn't be any more traitors to root out :( I made the challenge just for the title – user Apr 11 at 0:46

# Exchange of money in least notes

Suppose A and B are two good friends. A has borrowed $$\n\$$ dollar from B. Now B wants the money back from A and A is also ready to give it. But the problem is A has only $$\x\$$ dollar notes and B has $$\y\$$ dollar notes. They both want to keep the number of notes in exchange as low as possible.

As an example if $$\n=37\$$, $$\x=5\$$ and $$\y=2\$$, then the least amount of notes in exchange will be nine 5 dollar noted from A then four 2 dollar notes from B will make 37. This solution is found through brute forcing with a python program.

Here in the challenge your input will be values of $$\n, x, y\$$ and output should be the least of amount of notes as possible for A, B. A will give notes first and B later. Input and output seperator can be anything, no leading zeros in input numbers, no negative numbers in input. Standard loopholes apply and shortest code wins.

Test Cases

37 5 2 -> 9 4
89 3 8 -> 35 8
100 12 7 -> 13 8

• I'm almost certain there's a closed form solution to this, and if not one that's very close to closed form. – Redwolf Programs Apr 12 at 4:57
• Is it guaranteed that the given values of $n$, $x$ and $y$ lead to a valid solution? E.g. there's no solution for $n=21$, $x=6$, $y=4$. – Delfad0r Apr 12 at 8:22
• @Delfad0r input is guaranteed to valid – Wasif Apr 12 at 8:23