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.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

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]

| |

2956 Answers 2956

80 81
83 84

Proving that a Russian cryptographic standard is too structured

| |
  • \$\begingroup\$ Nice challenge. I have some suggestions for usability for solvers. Please say what language your example code is in (C?), and an online runnable version -- the community standard is TIO which is maintained by a site mod (example in Python). A pseudocode version or explanation would also be appreciated. It would be useful to include a listing of the permutation as 256 numbers from 0 to 255 written in base 10. The references would be cleaner as inline hyperlinks. \$\endgroup\$ – xnor Jun 6 '19 at 21:39
  • \$\begingroup\$ You should allow submissions to be programs or functions, which is default. Also, please change the scoring to bytes. I sympathize with wanting a fair comparison for 7-bit vs 8-bit languages, but past efforts have proved unpopular, and people now generally think of competitions as being within each language. You can leave the conversion to bits for your personal leaderboard. \$\endgroup\$ – xnor Jun 6 '19 at 21:46
  • \$\begingroup\$ Also, please make the challenge as self-contained as possible, which means putting into the challenge body the parts of the linked papers that are important for solvers. Here, I think this is mainly how the function p works. In particular, what does it mean that the table k is an affine function, and how can it be implemented as such? Does s have any structure? \$\endgroup\$ – xnor Jun 6 '19 at 21:52
  • \$\begingroup\$ Thanks a lot for your comments! I have updated the challenge and did my best to take them into account. Is it clearer now? \$\endgroup\$ – picarresursix Jun 6 '19 at 23:50
  • \$\begingroup\$ Yes, thanks for the edits. Now that you've explained that the core of the code is discrete log, I have some questions on that which other solver might have too. I take it the char declaration is to limit the values to 8 bits and discard bits? If I think of the field of size 256 as GF_2[X] modulo a certain irreducible polynomial, does the update a=(a<<1)^(a>>7)*29 correspond to multiplying by a polynomial? Could the initialization be l=0, a=1 instead? Note that LaTeX is enabled here, in case it's easier to write formulas. It also could help to say that ^ is xor, not power. \$\endgroup\$ – xnor Jun 7 '19 at 0:21
  • \$\begingroup\$ The answer to your questions are yes---mostly. The unsigned char are indeed used to discard some bits. We could alternatively replace a=(a<<1)^(a>>7)*29 with a=(a<<1)^(a>>7)*285 (where 256^29==285, in which case we wouldn't need the unsigned chars. This code snippet indeed corresponds to a multiplication by a polynomial. However, we cannot start at l=0,a=1. For some reason, the designers of $\pi$ used a variant of the logarithm such that $\log_2(1)=255$ instead of $\log_2(1)=0$. Both are "correct" in the sense that $\alpha^{255} = \alpha^{0} = 1$ but this variant is less common. \$\endgroup\$ – picarresursix Jun 7 '19 at 0:28
  • \$\begingroup\$ I added these clarifications to the challenge. \$\endgroup\$ – picarresursix Jun 7 '19 at 0:45
  • \$\begingroup\$ The output of your C code seems to not match the table. \$\endgroup\$ – xnor Jun 7 '19 at 1:02
  • \$\begingroup\$ The table was wrong rather than the C code. Thanks for catching it! I fixed it as well as the corresponding TIO link. To further simplify the verification, I added a link to the wikipedia page of Kuznyechik which contains the table of the function p. \$\endgroup\$ – picarresursix Jun 7 '19 at 1:18
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – xnor Jun 7 '19 at 1:57

Continue a progression

The \$k\$th generalized mean \$M_k\$ of a set of numbers is defined as $$M_k(a_1,\dots,a_n)=\root^k\of{\frac{a_1^k+\dots+a_n^k}n}.$$ \$M_0\$, the geometric mean, is defined through a limit \$\lim_{k\to0} \root^k\of{\frac{a_1^k+\dots+a_n^k}{n}} = \root^n\of{a_1\cdot\dots\cdot a_n}\$. \$k\$ does not have to be integer.

An arithmetic progression is (according to Wikipedia) a sequence of numbers such that the difference between consecutive terms is constant. A geometric progression is a sequence of numbers such that the ratio between consecutive terms is constant.

There is a simple way to generalize these (that also explains why on earth is geometric progression named geometric): for a progression of order \$k\$ for any 3 consecutive elements \$a\$,\$b\$,\$c\$ \$M_k(a,c)=b\$. This way, the arithmetic progression is of order 1 and the geometric progression is of order 0. The order does not have to be integer.

The task is, given 3 real positive numbers \$a,b,c\$, to find the next term in the progression formed by them.


  • If multiple valid outputs exist, you can output any of them.
  • It is guaranteed that a valid output exists.
  • An output is valid if \$|o_{correct}-o_{program}| \le10^{-5} \cdot \max(o_{correct}, 1)\$.

Sandbox stuff

  • I still have to prepare some test cases, especially for non-integer orders.
  • Has this been asked before?
  • Do multiple correct outputs ever exist? I feel like very often there are infinitely many.
  • Does Mathematica have a built-in?
  • Should I add a time limit? I feel like brute-forcing all floating point numbers and checking if they are valid outputs might be shorter than actually calculating.
  • Should I restrict the order to be integer, or even just 0 or 1 (leaving only arithmetic and geometric progressions)?
  • Is there a simple and beautiful formula for the next term that I was unable to find and that all answers will have to copy from each other? I could neither get Mathematica nor myself to solve any related equations.
  • Is the grammar correct enough?
| |
  • \$\begingroup\$ I think The task is, given 3 real positive numbers ... is a bit problematic, as receiving them sounds like a daunting task. \$\endgroup\$ – Jonathan Frech Jun 13 '19 at 15:21
  • \$\begingroup\$ @Jonathan Surely reading three numbers or taking them as function arguments or whatever is your language's alternative is the least thing you have to do here? \$\endgroup\$ – the default. Jun 13 '19 at 15:25
  • \$\begingroup\$ I think proving that submissions will always meet your validity criterion will be rather daunting. This will probably further encourage solutions that just try every single floating point number? I'd recommend saying that floating point issues won't be counted against the submission, but you still have a bit of a problem. If you do add a time limit I'd recommend saying that it only need be tested on the cases you provide (and maybe remind users that hardcoding is a loophole ;) ) \$\endgroup\$ – FryAmTheEggman Jun 13 '19 at 17:30
  • \$\begingroup\$ The time limit only on the test cases thing makes sense to me. What does "not counting floating point issues mean"? I think most solutions will have to use binary or ternary search, and that needs a, uh, stopping precision or a iteration count to be close enough. I think we can remove the need to verify it on all numbers by preparing a lot of test cases! \$\endgroup\$ – the default. Jun 14 '19 at 3:58
  • \$\begingroup\$ Not every solution will use that, and even if they do they may still run into a problem where they can't get a solution well enough based on their native floating point type and have to do a bunch of extra work. I think it works well as a catch-all that prevents golfers from having to struggle with weird edge cases. But generally I think you are right that just having enough test cases will be good enough (also I didn't get notified by your comment because someone else has commented already, you'd need to use @). \$\endgroup\$ – FryAmTheEggman Jun 14 '19 at 18:08
  • \$\begingroup\$ @FryAmTheEggman double-precision floating points have around 14 digits of precision, and 1e-8 is a perfectly common epsilon for such tasks (and I use 1e-5). And if I assume floating point numbers are arbitrary precision, that implicitly disallows binary/ternary search, as it will never produce the exact answer. And since the only two solutions I know are Mathematica NSolve and alternatives and searching for the order and then for the next number, this disallows all remotely interesting solutions known to me. \$\endgroup\$ – the default. Jun 15 '19 at 2:46
  • \$\begingroup\$ Assuming the languages that people use to answer your challenge will use a reasonable convention is not a particularly good one! I didn't meant arbitrary precision but arbitrarily larger precision based on what you have specified. It is probably fine the way you have it, I just think it is better to think about nonstandard languages when you can. If you put no time limit, some solutions may try to iterate over all floating point numbers of a particular precision, for example. Sorry if this has gotten out of hand, maybe I'm not doing a good job explaining what I mean? \$\endgroup\$ – FryAmTheEggman Jun 15 '19 at 3:16
  • \$\begingroup\$ So in short, given inputs \$a,b,c\$ find a \$k\$ such that \$a^k + c^k = 2b^k\$ and then find and output a \$d\$ such that \$d^k = 2c^k - b^k\$? There is a significant problem in that \$k=0\$ is always a solution to the first equation, so I think that the geometric mean would have to be tested first as a special case. \$\endgroup\$ – Peter Taylor Jun 18 '19 at 11:03
  • \$\begingroup\$ @PeterTaylor I think so. I feel like there actually is a simple and beautiful solution that everyone will have to copy from each other here. \$\endgroup\$ – the default. Jun 18 '19 at 11:08

Nearest match with limited values

When writing my solution for this challenge, I found that I needed to generate a target value using nothing but multiplication and increments/decrements, using a restricted set of values to use in the multiplication. Given that my choice of values was restricted, I had to brute-force what the optimum solution was. gObviously, this seems like a programming challenge!

The challenge is this: Given a target value t and set of allowed multiplier/multiplicand values, find the solution t=x×y±c (x and y are from the set of allowed values), that has the smallest value of c. If c is zero, indicate the solution as an exact match.

As this is a challenge, smallest code size wins. The standard rules apply.

Example program (ungolfed): Try it online!

I don't think that I saw this particular challenge before, but I may have missed some. This is my first challenge, so please let me know how I can make it better!

| |
  • \$\begingroup\$ Thanks for using the sandbox! This is mostly fine, except for two main things: "indicate that the solution as an exact match" is not really fleshed out enough, and that you don't have any test cases in the body. There are some other minor things, like specifying t and the allowable values to be integers (can they be negative?), and if returning all of the optimal x,y pairs is acceptable. As a challenge, I'm a bit unsure if this is particularly interesting due to its simplicity, but I don't think it is so simple that it is bad or anything. \$\endgroup\$ – FryAmTheEggman Jun 16 '19 at 17:56

Political Simulator

It's election time, and your job is to beat your competitor in a head-on rivalry! You are both trying to win over a city of 256 people in a 16x16 grid. Right now, the city hasn't been divided into voting regions yet, but that's where your gerrymandering skills come in! You can also campaign in arbitrary areas of the city to gain support.

General mechanics

The game starts out with each bot having $100 and all 256 voters being neutral (value 0). In the below notation, <x> refers to the grid space at x (so, 0 <= x < 16), and [x] refers to the block at x (so, 0 <= x < 4). The city starts out divided into 16 4x4 voting blocks. Each turn, both players get to perform one move:

  • C <x0> <y0> <x1> <y1> - campaign in the area bound by (x0, y0) and (x1, y1), inclusive, which will make all neutral voters with at least as many of your voters compared to your opponent's voters in their Moore neighborhood (diagonals included) vote for you. This only counts neighbors in your campaigning area; that is, voters at the corners of your campaign area only have three neighbors. Additionally, opponent's voters with at least 4 of your voters in their neighborhood will switch to your side (note that this means that you cannot swing votes in the corners of your campaign area). This costs $1 per square, and if you do not have enough money, your turn will be skipped. Additionally, you must have 0 <= x0 <= x1 < 16 and 0 <= y0 <= y1 < 16; otherwise, your turn will be skipped.
  • M [x0] [y0] [x1] [y1] - Attempt to merge the voting region containing the block (x0, y0) with the voting region containing the block (x1, y1). Note that here, 0 <= x0, x1 < 4 and 0 <= y0, y1 < 4. If the voting regions containing these two blocks touch, then the merge will succeed. This costs $(max(# blocks in first region, # blocks in second region) - 1) * 25; that is, if you merge a voting region containing 3 4x4 blocks with a voting region containing 2 4x4 blocks, it costs $50. This means that an initial merge of untouched regions is free. If you don't have enough money, or the regions don't touch, or your input is invalid, your turn will be skipped.
  • U [x] [y] - Attempt to unmerge the voting region containing the block (x, y). If successful, it will take all blocks in the voting region containing your specified block and separate them all. This costs $(# of blocks in the region - 1) * 50. If you don't have enough money, or your input doesn't fit 0 <= x, y < 4, your turn will be skipped.
  • B <x> <y> - Bribe the person at (x, y) with the amount specified by their bribing cost (initially $5), which raises their bribing cost by $2. This makes them vote for you. If you don't have enough money, your turn will be skipped.

At the end of every other turn (including the end of the first turn), you will gain $50.

Win condition

Each region will have all of its votes summed up. Then, if at least 50% of voters are not neutral and the number of votes for the two parties is not exactly the same, whichever party has more votes wins that region; otherwise, the region is neutral. The game ends when all regions are non-neutral and one party has strictly more regions than the other party (basically, you can call an election at any time, so as soon as you can win, you call the election and win).

I/O Format

I/O will be done via STDIN/STDOUT to allow (almost) any language to be used. On each turn, your bot will be presented with the following input:

Line 1: the number of regions, R
Line 2 to 5: a grid of the voting regions consisting of a 4x4 of capitalized hexadecimal digits. For example, a possible voting region configuration with 11 regions is:


Line 6: N M, the amount of money you have, and the amount of money your opponent has.
Line 7 to 22: the 16x16 grid consisting of 0, 1, and 2, where 0 is a neutral voter, 1 is one of your voters, and 2 is an opponent voter.

For example, the starting configuration will be:

100 100

You will be given this input with a terminating newline, and you need to output one of the four commands indicated above (if you want to do nothing, then output anything invalid or output a newline, but if you don't output, your bot will be presumed frozen and you will lose).

Unless someone needs otherwise, bots taking more than 2 seconds on a turn are killed and lose.


Your submission must work correctly in under 2 seconds per turn. Your program should block for input and will be run once and will be fed 22 lines of input per move and should give exactly one line of output per move.

Every bot will be run against every other bot. Each round, the simulation will be run twice with each bot getting the first move in one of the simulations. If both bots win exactly one simulation, the tiebreaker goes:

  • the bot that wins by a wider margin of regions wins (that is, whichever bot had a higher difference between their regions and the opponent's regions)
  • the bot that wins by a wider margin of popular vote wins
  • the bot with more popular votes wins
  • the bot that took fewer moves to win wins
  • failing these, the round is declared a tie

The bots will be run until one of them wins three rounds. If ten rounds have passed and neither bot wins, it is declared a tie, giving each bot half a win.

The bots will be ranked by wins, with earlier submissions winning ties.


  • Is this game balanced and strategizable?
  • I will probably leave this challenge open for two weeks before declaring a winner; submissions can still be made afterwards but may or may not be graded.
  • Any clarifications or specifications needed?
| |
  • \$\begingroup\$ I'm not sure if giving $1 per voter vs giving a fixed allowance is better. $1 per voter leads to more run-away wins (quicker games are definitely better), but giving a fixed allowance gives the AI more turns to flesh out their strategy. The section under "rules" is confusing. I'm having trouble figuring out what a round, subround, and matches are. \$\endgroup\$ – Nathan Merrill Jun 16 '19 at 5:59
  • \$\begingroup\$ @NathanMerrill Hm, that's fair enough. I'll clarify the scoring. \$\endgroup\$ – HyperNeutrino Jun 16 '19 at 13:34
  • \$\begingroup\$ That's clearer. That said, I don't understand why you are grouping by rounds. Wouldn't it be simpler to have, say, 10 games, and then follow the tiebreaker rules to determine the winner. \$\endgroup\$ – Nathan Merrill Jun 16 '19 at 16:08
  • 1
    \$\begingroup\$ Also, the moves aren't very clear, it took me several reads to understand them. You are reusing the word "region" to mean both a set of squares, as well as one of the specific 4x4 set of squares. Also, it isn't clear when the coordinates refer to square coordinates vs region coordinates, I'd have a different notation for those. \$\endgroup\$ – Nathan Merrill Jun 16 '19 at 16:13
  • \$\begingroup\$ "This costs $max(# blocks in first region, # blocks in second region) * 25; that is, if you merge a voting region containing 3 4x4 blocks with a voting region containing 2 4x4 blocks, it costs $50." Is this right? Shouldn't the example cost $75? \$\endgroup\$ – Alion Jun 17 '19 at 14:30
  • \$\begingroup\$ @Alion I forgot to subtract 1 from that lol. The original spec was their sum but I made it max, and it's supposed to be -1 still. \$\endgroup\$ – HyperNeutrino Jun 17 '19 at 15:49
  • \$\begingroup\$ @NathanMerrill I've updated it; area refers to campaigning, block is the 4x4 overlaying grid, and region is an arbitrary shape of the 4x4 blocks. \$\endgroup\$ – HyperNeutrino Jun 17 '19 at 15:51
  • \$\begingroup\$ "This means that an initial merge of untouched regions costs $25." How? max(1, 1) - 1 gives 0. \$\endgroup\$ – Peter Taylor Jun 18 '19 at 10:31
  • \$\begingroup\$ @PeterTaylor Sorry, that was left over from an earlier revision of the computation. Will update. \$\endgroup\$ – HyperNeutrino Jun 18 '19 at 12:18
  • \$\begingroup\$ Bribing seems ridiculously inefficient, both cost- and time-wise. I'm having a hard time imagining a situation where it would be the correct play, especially considering how much money each player makes every turn. Cutting the budget by about 50-80% would likely resolve the issue. If you've studied this problem more closely than I have and are aware of situations where it is indeed appropriate, however, feel free to ignore my suggestion. \$\endgroup\$ – Alion Jun 18 '19 at 19:47
  • \$\begingroup\$ @Alion I have not analysed the balance of the moves and what strategies would be optimal, but yeah, I think it's a very nuanced move that would only ever be used if you need to hit a specific region and force converting someone can allow you to use a campaign to cover the area. But yeah, I'll probably leave it in there and I'll look into the cost and budget balancing. \$\endgroup\$ – HyperNeutrino Jun 18 '19 at 20:14
  • \$\begingroup\$ @Alion, there's no point campaigning before bribing. You need to somehow jump-start the scenario. \$\endgroup\$ – Peter Taylor Jun 19 '19 at 11:57
  • \$\begingroup\$ @PeterTaylor "Campaign[ing] [...] will make all neutral voters with at least as many of your voters compared to your opponent's voters [...] vote for you." In other words, 0 >= 0. \$\endgroup\$ – Alion Jun 19 '19 at 12:06
  • \$\begingroup\$ 1) Does bribing make the person vote for you until opponent's bribe, regardless of campaigning? I only just realized this, so if this is the intended mechanic, I would recommend making it a bit more clear. 2) I know that you are planning on tuning the numbers, but I think I might've found a quick and easy forced win for player 1, or at least something very close to one, so that's a bit more incentive for that. I feel like the game is just too ridiculously fast paced for any strategy to show up at the present. I could be wrong, but everything I try points to that conclusion. \$\endgroup\$ – Alion Jun 19 '19 at 12:32
  • \$\begingroup\$ @Alion No, it just sets their affiliation to you and the opposition can gain that vote by campaigning. About the pace, I will probably need to reduce the budget so player 1 can't just win half the game on the first move. \$\endgroup\$ – HyperNeutrino Jun 19 '19 at 12:39


Assume that there is a number a. In every conversion of that number, the number can either convert itself to its value plus the value of one of its digits, or convert itself to its value minus the value of one of its digits.

In this situation, find the minimum number of conversions one has to make in order to get to the number b. If b cannot be reached, output -1.


Input one line containing the integers a and b (where 1 <= a, and b <= 10^6).


Output a line containing one integer, which represents the minimum amount that one has to convert the number.

Example input and output (s)

Input:  1 10
Output: 5


-> 1+1=2
-> 2+2=4
-> 4+4=8
-> 8+8=16
-> 16-6=10
=> 10
| |
  • 2
    \$\begingroup\$ At first sight this looks like just another shortest path question, but reachability is actually quite subtle. Do you have a proof of decidability? \$\endgroup\$ – Peter Taylor Jun 22 '19 at 18:33

Meta command-line flag parsing

The challenge

Write a program or function which determines whether or not a chosen command-line flag has been passed into the compiler or interpreter, but without accessing command-line parameters directly.


  • You must take in no input.
  • You are free to choose the flag that is being detected, but it must:
    • be a flag, meaning a boolean command-line parameter that does not take any arguments (e.g. -O3 in gcc)
    • not print anything by virtue of being present (e.g. flags that print a version number or usage help are disallowed)
  • The output must be 1 if the flag is present, and 0 otherwise.
  • The program must successfully run without errors, whether or not the flag is present.
  • You may not make use of the arguments passed to the compiler/interpreter, whether directly by value or by a property such as string length, array length.
  • Separately from the chosen flag, other command line parameters can be used, so long as they remain the same when running the code with and without the flag in question.
  • This is ; shortest answer in bytes wins!

Sandbox Questions

  • Are there any other edge cases or loopholes that should be accounted for here?
  • Is this a , despite the challenge not being related to input?

Feedback welcome!

| |
  • 1
    \$\begingroup\$ I think this may have quite a few problems with determining what counts as a valid flag, what counts as accessing them, and what counts as an error. For example, Pyth has a flag -d which turns on debug printing. So any program with constant output would work. But that doesn't seem like what you have in mind, would it be acceptable? \$\endgroup\$ – FryAmTheEggman Jun 21 '19 at 19:57
  • \$\begingroup\$ @FryAmTheEggman Indeed, that's somewhat problematic. Maybe restricting output to either 1 or 0 would stop such trivial solutions from passing, though at the cost of punishing some other languages. I don't want to completely bar short-but-clever solutions, though, as I find that they can often be surprisingly creative; the example you posted is just something that would end up being used in too many solutions. \$\endgroup\$ – negative seven Jun 21 '19 at 20:11
  • \$\begingroup\$ That may help, but you are right that it will restrict solutions a lot. I think this is a challenge that is worth running past quite a few people so you can get an idea of which flags are actually worth (and possible) to rule out. \$\endgroup\$ – FryAmTheEggman Jun 21 '19 at 20:23
  • 1
    \$\begingroup\$ Thinking of Japt here which takes its flags via an HTML input: if I'm understanding correctly, I wouldn't be allowed to simply read the value of that input, right? What about accessing Japt's internal variable for storing flags, would that be allowed? Also, should our solutions run no matter which flag is used or need we only support our chosen flag and no flag? Again thinking of Japt which has a flag that negates it's output; obviously that's going to be problematic! \$\endgroup\$ – Shaggy Jun 22 '19 at 22:14
  • \$\begingroup\$ @Shaggy Both the input and internal variable would classify as "accessing the list of arguments", which is disallowed. Only two sets of command line parameters need to be supported: [some set of starting parameters not including the chosen flag, if any] and [the same set of starting parameters] + [the chosen flag]. I'll try to clarify both of these things. \$\endgroup\$ – negative seven Jun 23 '19 at 5:09

GPA calculator

A GPA is sort of weighted average based on the grades obtained in certain courses. There are a number of different systems, but for this challenge we'll use the following grades and their numeric values:

A: 4
B: 3
C: 2
D: 1
F: 0
P: —

The grade is P is a special case. For some courses, students can sign up to take a course as Pass/Fail. In the case of a Pass (P), the course has no effect on their GPA whatsoever, but in the case of a Fail (F), the course does affect the GPA.

All courses are weighted by the number of hours/credits they are taken for. So give the following transcript:

Course            Hours   Grade
------            -----   -----
Next Gen Perl       6       A
Advanced C-minar    1       C
Starting with Java  3       B

We would calculate the total points as 35 (6*4 + 1*2 + 3*3), and then divide it by the number of hours, or 10 (6+1+3) for a final GPA of 3.5. If Starting with Java had been given an F, the total points would be 26 with 10 hours, for a GPA of 2.6. However, if it had been a P, the total points would still be 26, but with only 7 hours, the GPA would be 3.71428571429…


An arbitrarily long list/array/sequence/etc of transcript entries. The entries are simply a two item list/array/sequence/etc with one item being an integer value (doesn't have to be an actual Int value, floats are fine) of hours, and the other being the string ('A','B'...). The above example would have been:

  [6, 'A'],
  [1, 'C'],
  [3, 'B']

You may assume that the list will have at least one computable grade (so no empty transcripts, nor transcripts consisting only of P). If your language does not have strings, then you may use numbers for A/B/C/D/F/P, but their values must be similarly spaced (e.g. 10,11,12,13,14,25)


A number representing the GPA (float or other non-Int value)

Scoring and Restrictions

Codegolf, so shortest code in bytes wins. Standard rules apply.

Sandbox questions

I thought about allowing for either +/- grades (A+, A, A-, B+...) which would definitely prevent using ASCII values as easily, but then that led me to the thought of having a second input which is a list of possible grades with their equivalent value, but I think that would start over complicating it and way over benefit languages with built-in hashing. Thoughts?

| |
  • \$\begingroup\$ Dupe \$\endgroup\$ – FryAmTheEggman Jun 21 '19 at 20:01
  • \$\begingroup\$ @FryAmTheEggman not a dupe. This one adds the P which makes it a good bit more complciated. \$\endgroup\$ – user0721090601 Jun 21 '19 at 20:03
  • \$\begingroup\$ I disagree, solutions can just filter out all the grades with P and then exactly reuse the result from the question I linked. Unless I've missed something that definitely fits in the criteria for being a duplicate. \$\endgroup\$ – FryAmTheEggman Jun 21 '19 at 20:06
  • \$\begingroup\$ @FryAmTheEggman Between filtering, vastly different input/output (all of which could/would significantly modify entries — the input/output in particular was a strong criticism of the one you linked to), I think it's sufficiently different and golfed answers wouldn't be trivially different. But in any case, I asked about feeding in +/- or arbitrary grades which absolutely would be a totally different question. Perhaps instead of being dismissive, you could be constructive. \$\endgroup\$ – user0721090601 Jun 21 '19 at 20:24
  • \$\begingroup\$ It is possible that I'm being too harsh, but I don't think I am. The only real problem with the other question compared to this one is the rounding, which could basically just be dropped from the answers. While I agree that this isn't identical, I don't think it has enough reason to exist as even with the +/- grades it's still just looking up values then applying a weighted average. It is certainly possible that I am in the minority, but I think my skepticism should encourage you to find other people's opinions before posting. \$\endgroup\$ – FryAmTheEggman Jun 21 '19 at 21:03
  • \$\begingroup\$ I agree with @FryAmTheEggman; the core of both challenges is identical. The only real difference here is having to filter the Ps which is a trivial modification for most languages. Having said that, though, I wouldn't swing my hammer at this until a few solutions had been posted, in the hope that I would be proven wrong. \$\endgroup\$ – Shaggy Jun 22 '19 at 22:26



I originally wrote it in Chinese and am still working on translating it. Sorry for the inconvenience.

Given an array containing n integers A1,A2,…,An, where all of their initial values are 0. Please implement the four operations to the array described below:


Given the positive integer x and y, let every number in the range Ax~Ay (including Ax and Ay) be added by the given positive integer c;
Given the positive integer x and y, let every number in the range Ax~Ay be (similarly to the previous spec; the rest of the spec also conforms that rule) multiplied by a given positive integer c;
Given the positive integer x and y, let every number in the range Ax~Ay be changed to a given positive integer c;
Given the positive integer x and y, with regard to a given positive integer p, evaluate the value of the following expression :```[pow(Ax, p) + pow(A(x + 1), p) + … + pow(Ay, p)]7```


In the first line of the test case, there are two positive integers n(where 1<=n), which represents the length of the array.

Then, input operations sequentially, where each operation occupies one line, and the input will be 4 positive integers as in: type x y num, where type is either 1, 2, 3, or 4; these identifiers correspond to the corresponding operation as described above. The meaning of x and y corresponf to the description (where 1<=x<=y<=n). When type is not 4, num will be the positive integer given c(where 1<=c<=10000); when type is 4, num will be the given positive integer p(where 1<=p<=3)。


For each test case, for every 4 operation for the array, output the value of the corresponding expression.

Example input

3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3

Example output

| |
  • 1
    \$\begingroup\$ Is it supposed to have restricted-complexity? Or pure golf? \$\endgroup\$ – jimmy23013 Jun 27 '19 at 11:37
  • \$\begingroup\$ I will add the category later after I translate the problem. \$\endgroup\$ – user85052 Jun 27 '19 at 11:46
  • 1
    \$\begingroup\$ In that case it's restricted-time. But you have to specify exactly how it is tested. 8 seconds doesn't mean much without the test cases and the the exact computer it will run on. restricted-complexity is much simpler. And just to confirm, you wrote this question, and it's not a homework problem from elsewhere, is it? \$\endgroup\$ – jimmy23013 Jun 27 '19 at 11:56
  • \$\begingroup\$ Yes, I wrote the question; I will accept your suggestion. \$\endgroup\$ – user85052 Jun 27 '19 at 11:58
  • 1
    \$\begingroup\$ Because, I think it is designed to be O(n+qlogn) in some algorithm competition. If more than that, any straightforward algorithm will probably work, and it's better to just removed the restriction. (Also note that on CG.se, in a challenge that there is a known best algorithm, coming up with the algorithm is generally not supposed to be the main challenge. If you go for O(n+qlogn), they will simply ask for a reference algorithm.) \$\endgroup\$ – jimmy23013 Jun 27 '19 at 12:10
  • 1
    \$\begingroup\$ Don't use multiple test cases. Make the list format flexible and q implicit. I'm not sure what's the best way to input multiple operations, but at least you could make operation types consistent and distinct value. If there is no time or complexity limit you don't need mod 10007. Even if there is a limit, it is probably better to make this an input. \$\endgroup\$ – jimmy23013 Jun 27 '19 at 12:18
  • 1
    \$\begingroup\$ I think if you wrote this you probably know that O(n+qlogn) and O(n^3) (or simply without restriction) makes a lot of differences. The code would be much longer for O(n+qlogn). And for reference, this question asking for suffix tree or alternatives had the first and only non-deleted answer about 2 years later. Not that you can't post it in either case, but... just make sure you know what you are doing. \$\endgroup\$ – jimmy23013 Jun 27 '19 at 12:29
  • 1
    \$\begingroup\$ I mean at least you could make operation types any consistent and distinct values, instead of 1, 2, 3, 4. \$\endgroup\$ – jimmy23013 Jun 27 '19 at 12:31

Answer chain: decreasing character scores

Assign a non-negative integer value to each letter in the alphabet, and write a function or program which takes as input a character string and outputs the sum of of the values of the letters in the string. Characters outside of [a-z] and [A-Z] have value 0.

Now run your code, taking as input the code of each of the previous answers in the order they were posted (including your own). The resulting sequence of scores should be strictly decreasing.

For example, if you are 4th to answer and your code defines a function \$f\$, then the output should verify \$f(c_1)>f(c_2)>f(c_3)>f(c_4)\$ where \$c_1\$ is the code of the 1st answer, \$c_2\$ is the code of the 2nd answer, ..., \$c_4\$ is the code of your answer.

When there will have been one week with no new answer, the 2nd-to-last answer will be declared the winner.


  • The values you assign may be the same as or different from those used by previous answers.
  • The value 0 is allowed.
  • Different letters may be assigned the same value.
  • Upper and lower case versions of the same letter may have different values.
  • Letters with diacritics, such as é or Ä, have value 0.
  • Your code need not handle letters which have not occurred in any of the previous answers (so if no answer so far has used the letter W, it's OK if your code fails on strings with a W).
| |
  • 1
    \$\begingroup\$ Using characters like this seems to have some problems. Do answers get to pick encodings? Or is it really more like \$ f(c_{1},e_{1}) \$ where \$ e_{i} \$ is the encoding used by the ith answer? I think this may work better if you say it should work on bytes, then answerers can choose to interpret those bytes as characters in whatever encoding they want. \$\endgroup\$ – FryAmTheEggman Jun 24 '19 at 3:45
  • \$\begingroup\$ @FryAmTheEggman I have been thinking about this as well. I want it to be easy to set up on TIO, which means that solvers should be able to just copy-paste the code of previous answers. Forcing solvers to take into account the esoteric codepoints of golfing languages would be a hassle. I'd be more inclined to let answerers pick the encoding, but I suppose that might create potential loopholes. \$\endgroup\$ – Robin Ryder Jun 24 '19 at 14:34
  • \$\begingroup\$ Wouldn't asking for a hexdump of the code to be in each answer ensure that the solutions are fairly accessible? TIO also has problems with displaying particular characters (null bytes especially) and other things like that each text box has one fixed encoding. \$\endgroup\$ – FryAmTheEggman Jun 24 '19 at 14:39
  • \$\begingroup\$ @FryAmTheEggman How about restricting to letters (without diacritics)? Anything not in [a-z] or [A-Z] must have value 0. I think this circumvents the problem. Or maybe extend to letters+digits, or even all ASCII characters. \$\endgroup\$ – Robin Ryder Jun 24 '19 at 16:35
  • \$\begingroup\$ I don't think that works with your setup at all because a submission with no characters in whatever range you pick must always score exactly zero so it necessarily ends the chain. \$\endgroup\$ – FryAmTheEggman Jun 24 '19 at 16:49
  • \$\begingroup\$ @FryAmTheEggman Yes, and then whoever submitted that is guaranteed to lose, since the second-to-last answer wins. \$\endgroup\$ – Robin Ryder Jun 24 '19 at 20:41
  • \$\begingroup\$ Ah, I missed that, sorry. It still seems to have trouble with languages that could write all of their code using bytes outside the range you select and then throw in a small number of other characters, but I don't know if that is "broken" enough to make it unfun. \$\endgroup\$ – FryAmTheEggman Jun 24 '19 at 22:55
  • 1
    \$\begingroup\$ @FryAmTheEggman Potentially, an answerer could use only non-letters, add a single a, and then all following answers would need to assign a large value to a and avoid that letter in their own code. That seems OK to me, but I am a fan of lipograms... Anyway, I have updated the challenge following this helpful discussion; let's see if there are further comments. Thanks for your feedback! \$\endgroup\$ – Robin Ryder Jun 25 '19 at 22:05
  • \$\begingroup\$ Can a letter be assigned the value 0? That would be a non-negative integer \$\endgroup\$ – Nick Kennedy Jun 27 '19 at 14:51
  • \$\begingroup\$ @NickKennedy Yes, 0 is allowed. \$\endgroup\$ – Robin Ryder Jun 27 '19 at 15:02

Enable 2-char Jsfuck

Provide a shortest code that makes JavaScript able to do everything JavaScript is supposed to do, i.e. able to access(so no deleting [].prototype.toString unless you have a backup, even if you can simulate one [].prototype.toString) and exec anything, with only [ and ]. You can choose your environment(FF/node/etc). Answering in 6-char JsFuck or something similar is welcomed.

E.g. If you run

Array.prototype[''] = 'a';
Array.prototype['a'] = 'b';
Array.prototype['b'] = function() { console.log(this[0]); };

then [][[]] = [][''] = 'a', and [][[][[]]] = []['a'] = 'b', so [[][[]]][[][[][[]]]] = ['a']['b'] = function(){console.log('a')}.

Of course, this is an invalid answer, because it can't do prompt(web browser) or fs(node) or anything similar, or even calling the console.log.

| |
  • 1
    \$\begingroup\$ This is not clear as is. Are we making a transpiler from JS to JSFuck with the winning criterion code-golf? Do we need to support all JS input, or just some subset? \$\endgroup\$ – lirtosiast Jun 25 '19 at 17:13
  • \$\begingroup\$ So a solution like translating "[[]"→( "[]["→) "[]]"→+ "][["→[ "][]"→] "]]["→! is valid? \$\endgroup\$ – Adám Jun 25 '19 at 18:18
  • \$\begingroup\$ @lirtosiast I said "makes JS able to do everything in2c", not "make a language that do everything" \$\endgroup\$ – l4m2 Jun 26 '19 at 9:28
  • \$\begingroup\$ @Adám I don't think it's possible. +[] turns into []]][[][] which is not even valid JS code \$\endgroup\$ – l4m2 Jun 26 '19 at 9:29
  • 2
    \$\begingroup\$ @l4m2 Please include your not-golfed reference implementation so we can understand what you mean. \$\endgroup\$ – Adám Jun 26 '19 at 9:34
  • \$\begingroup\$ @l4m2 If I understand this right, you're saying that we should write code that modifies the JavaScript environment such that all JavaScript code can be converted into JavaScript code that only uses characters [ and ]. Basically, add something to Array.prototype that makes the [] characters JavaScript-complete. \$\endgroup\$ – wizzwizz4 Jul 24 '19 at 13:28
  • \$\begingroup\$ @wizzwizz4 right \$\endgroup\$ – l4m2 Aug 8 '19 at 15:11

Tips for golfing in H

As for H as described here, what general tips do you have for golfing in H? I'm looking for ideas which can be applied to code-golf problems. Tips have to be specific to H (e.g. "remove comments" is an answer).

Tips in Standard H are also on-topic, although its spec is in a bad condition. You can use the H description provided in the first link to solve anything you don't understand about.

Please post one tip per answer. Also, please specify which H implementation you are using if your code runs only under a specific H implementation, as different H implementations can have different behavior.

| |
  • 2
    \$\begingroup\$ Why do you want to ask this when H doesn't even exist? \$\endgroup\$ – Adám Jun 28 '19 at 12:40
  • 2
    \$\begingroup\$ What's the rush? Also, H as linked, isn't a programming language, and it has a very strict definition, so there's no much room for golfing. The only thing I can think of is to omit quotes in the rare instances where you want a string that looks like one of the 1999 integers in the range -999–999. \$\endgroup\$ – Adám Jun 28 '19 at 12:57
  • 1
    \$\begingroup\$ That would be a duplicate. \$\endgroup\$ – Adám Jun 28 '19 at 13:10
  • \$\begingroup\$ Tips for golfing in Turing Machine but Way Worse also only has 1 tip. \$\endgroup\$ – user85052 Jun 28 '19 at 13:14
  • \$\begingroup\$ I can also think of a lot of those examples, as in: codegolf.stackexchange.com/questions/19423/… codegolf.stackexchange.com/questions/101557/… codegolf.stackexchange.com/questions/96682/… \$\endgroup\$ – user85052 Jun 28 '19 at 13:42
  • \$\begingroup\$ It does not matter whether it is a programming language or not; this question only cares whether H can be golfed or not. \$\endgroup\$ – user85052 Jun 28 '19 at 13:47

Find the closest hex colour shorthand

In CSS, colours can be specified by a "hex triplet" - a three byte (six digit) hexadecimal number where each byte represents the red, green, or blue components of the colour. For instance, #FF0000 is completely red, and is equivalent to rgb(255, 0, 0).

Colours can also be represented by the shorthand notation which uses three hexadecimal digits. The shorthand expands to the six digit form by duplicating each digit. For instance, #ABC becomes #AABBCC.

Since there are fewer digits in the hex shorthand, fewer colours can be represented.

The challenge

Write a program or function that takes a six digit hexadecimal color code and outputs the closest three-digit color code, where closeness is measured by adding together the difference between each component of the full color code and the corresponding component of the shorthand color code.

Here's an example:

  • Input hex code: #28a086
  • red component
    • 0x28 = 40 (decimal)
    • 0x22 = 30
    • 0x33 = 51
    • 0x22 is closer, so the first digit of the shortened color code is 2
  • green component
    • 0xa0 = 160
    • 0x99 = 153
    • 0xaa = 170
    • 0x99 is closer, so the second digit is 9
  • blue component
    • 0x86 = 134
    • 0x77 = 119
    • 0x88 = 136
    • 0x88 is closer, so the third digit is 8
  • The shortened color code is #298

Your program or function must accept as input a six digit hexadecimal color code prepended with # and output a three digit color code prepended with #.


  • #FF0000 → #F00
  • #00FF00 → #0F0
  • #D913C4 → #D1C
  • #C0DD39 → #BD3
  • #28A086 → #298
  • #C0CF6F → #BC7
| |

Golf an H quine [duplicate]

Your task is to write a quine program in H (described in my esolangs.org userpage). (It is unclear whether it is possible.) Referring to Computer Science stack exchange, which seems unappropriate.

| |
  • \$\begingroup\$ Can you explain your comment? I cannot understand it. \$\endgroup\$ – user85052 Jul 1 '19 at 11:19
  • 5
    \$\begingroup\$ Note that challenges that require the answers to be in a specific language are generally discouraged.* Is there any reason someone wanting to golf a quine in H would not just answer this? \$\endgroup\$ – Adám Jul 1 '19 at 11:26
  • 1
    \$\begingroup\$ Now your espolangs userpage says Programming Puzzles and Code Golf. This is just what PPCG stands for. We are not called that any more. \$\endgroup\$ – Adám Jul 1 '19 at 11:27
  • \$\begingroup\$ I am trying to retain the style of the rest of the esolangs pages. (e.g. see this page) \$\endgroup\$ – user85052 Jul 1 '19 at 11:30
  • 1
    \$\begingroup\$ Information contained in public Wikis does occasionally get stale. You should update all those references to PPCG. \$\endgroup\$ – Adám Jul 1 '19 at 11:31
  • \$\begingroup\$ To clarify: is the current name "Code golf & Coding challenges"? \$\endgroup\$ – user85052 Jul 1 '19 at 11:34
  • 1
    \$\begingroup\$ The tour page seems to say Code Golf Stack Exchange. \$\endgroup\$ – Adám Jul 1 '19 at 11:35
  • 1
    \$\begingroup\$ @Adám Wait, we're now known as CCSE? :S I thought the new name was indeed "Code Golf & Coding Challenges" (CGCC).. \$\endgroup\$ – Kevin Cruijssen Jul 1 '19 at 11:37
  • 1
    \$\begingroup\$ As for the 'challenge', we already have a general quine challenge as linked by @Adám in his first comment. When you have more rep you could offer a bounty on that challenge stating you want to see if someone could come up with a quine in H. But, is H even released yet? If yes, maybe the first step might be to ask Dennis in the Nineteenth Byte Chat to add H to TIO, and also have a github with the source code/compiler of H. \$\endgroup\$ – Kevin Cruijssen Jul 1 '19 at 11:40
  • 1
    \$\begingroup\$ The new site name is "Code Golf", and the subtitle is "& coding challenges". You can refer to the site with or without the subtitle \$\endgroup\$ – trichoplax Jul 1 '19 at 11:44
  • 1
    \$\begingroup\$ (referring to it off site should probably include "Stack Exchange" as other golfing sites are available) \$\endgroup\$ – trichoplax Jul 1 '19 at 11:49
  • 1
    \$\begingroup\$ Relevant \$\endgroup\$ – Adám Jul 1 '19 at 11:56

Machine Learning Golf: Fashion MNIST

The first instance of Machine Learning Golf received a lot of intention but also revealed some problems (mostly caused by people in this community being too clever ;-)).

I intend to address those issues in this second installment:

Fashion MNIST is a dataset of 60,000 labelled 28x28 pixel grayscale images of fashion items (T-shirts/tops, Trousers, Pullovers, Dresses, Coats, Sandals, Shirts, Sneakers, Bags and Ankle boots).

Your task is to design and train a neural network that correctly identifies these images. Here are the rules:

Performance Goal

To qualify, your model must achieve at least 95% accuracy on the training set (i.e. you must identify at least 57,000 images correctly).


You may use any language and framework of your choice.

Your dataset must be taken as the current version of Fashion MNIST found here or in the references listed in that repo's README (for convenience).

You may reshape, permutate, rescale and offset entries in the dataset. However, modifications made to one entry must be performed on all entries.

You may transform the labels any way you like. (But you may, obviously, not change which labels correspond to which images.)

During training, you're allowed to use any dataset you want (in fact, you are allowed to come up with your weights however you like). Hence the above limitations are only relevant to assess whether your model meets the stated performance goal.

Your model

  • must be a 'traditional' feed forward neural network, i.e.a node's value is calculated as a weighted linear combination of some of the nodes in previous layers (which may include a bias node with constant value 1) followed by an activation function. Note that this allows you to skip layers and use convolutional/residual layers,
  • may only use the following standard activation functions:
    1. \$\mathrm{linear}(x) = x\$,
    2. \$\mathrm{softmax}(\vec{x})_i = \frac{e^{x_i}}{\sum_j e^{x_j}}\$,
    3. \$\mathrm{selu}_{\alpha, \beta}(x) = \begin{cases} \beta \cdot x & \text{, if } x > 0 \\ \alpha \cdot \beta (e^x -1 ) & \text{, otherwise} \end{cases}\$,
    4. \$\mathrm{softplus}(x) = \ln(e^x+1)\$,
    5. \$\mathrm{leaky-relu}_\alpha(x) = \begin{cases} x & \text{, if } x < 0 \\ \alpha \cdot x & \text{, otherwise} \end{cases}\$,
    6. \$\tanh(x)\$,
    7. \$\mathrm{sigmoid}(x) = \frac{e^x}{e^x+1}\$,
    8. \$\mathrm{hard-sigmoid}(x) = \begin{cases} 0 & \text{, if } x < -2.5 \\ 1 & \text{, if } x > 2.5 \\ 0.2 \cdot x + 0.5 & \text{, otherwise} \end{cases}\$,
    9. \$e^x\$
  • must take a single entry of the (preprocessed) training set as its only input and
  • return the predicted label, in the format you've specified, as its only output,
  • if a given weight occurs multiple times in your model, you may reuse it to lower your overall score,

Your answer must include (or link to) all code necessary to check your results -- including the trained weights of your model. In particular, you must include all preprocessing steps of your dataset.


The neural network with the smallest number of weights (including bias weights) wins.

Parameters used to preprocess your data don't count as weights.



There is a tutorial for the Fashion MNIST dataset available on Tensorflow which serves as an excellent starting point if you decide to use TF as your framework.

This challenge had already been posted on the main site and got closed there. The purpose of this post is threefold:

  1. Is the community interested in this particular (and this kind of) challenge (in general)?
  2. How can the user experience for the target audience be improved? Specifically:
    • What are likely causes of confusion?
    • Can we streamline the structure?
    • Are some of the rules too restrictive or not restrictive enough?
    • Are there any loopholes I've overlooked? (For instance, preprocessing the training data opens up the possibility of encoding labels into the feature set. Some of the rules are already designed to prohibit this but it's entirely possible that they don't suffice.)
  3. Any other constructive feedback?
| |
  • 2
    \$\begingroup\$ I think a lot of community members don't know anything about machine learning. You might try saving this one for later and working to think of some entry-level challenges that work as a sort of tutorial when done together. \$\endgroup\$ – mbomb007 Jul 4 '19 at 16:59
  • \$\begingroup\$ @mbomb007 While I like the idea, it seems pretty tough to come up with challenges that are both simple enough to solve without knowing machine learning and yet won't just get solved without using ML at all. That's what happened with my entry-level challenge. Still, I'm sure there are a few people here who would enjoy this kind of challenge and seeing them might spark the interest of others. \$\endgroup\$ – Stefan Mesken Jul 4 '19 at 17:21
  • 4
    \$\begingroup\$ I think it's worth considering the questions and requests for clarifications you were asked in the comments of your previous challenge and making sure you've clearly addressed all of them here. \$\endgroup\$ – xnor Jul 4 '19 at 20:17
  • 2
    \$\begingroup\$ I think there's a good chance the best strategy for this challenge isn't anything that looks like training a neural net, but some form of massive over-fitting like looking up a few specifically-chosen pixels with a lookup table, implemented with neural net primitives. I'd suggest you make a good effort at trying to optimize both strategies yourself to see how that turns out. \$\endgroup\$ – xnor Jul 4 '19 at 20:22
  • \$\begingroup\$ @xnor The previous issues have been addressed, as far as I can tell, and I'm not concerned about overfitting. If you can identify a few relevant bits of information to pass the test while staying within the rules, that's fine with me. \$\endgroup\$ – Stefan Mesken Jul 5 '19 at 4:36
  • \$\begingroup\$ I should make clear that the intention of this challenge is to provoke people to come up with tricky ways to lower their score -- it's not meant to result in neural networks you would actually use in production. Hence I'd like the rules only to guard against approaches that trivialize this task (like encoding labels into the feature set via preprocessing). And testing indicates that you might be able to come up with a solution using \$\ll 1000\$ weights -- beating every traditional approach by a long shot. (Which, to me, is pretty exciting.) \$\endgroup\$ – Stefan Mesken Jul 5 '19 at 4:55
  • \$\begingroup\$ If doing hardcoding-style stuff is fine, then it's confusing to mention training as in "Your task is to design and train a neural network" if training is actually optional. And "I intend to address those issues in this second installment" makes it sound to me like you're trying to make the challenge watertight against unexpected clever approaches, which I think isn't what you're trying to convey. \$\endgroup\$ – xnor Jul 6 '19 at 2:05
  • 2
    \$\begingroup\$ Let me also reiterate what mbomb007 said about many community members not knowing anything about machine learning. I think it would be good to write up a friendly introduction with everything that's needed for the challenge while keeping unfamiliar terminology to a minimum. Separately, scoring by distinct weights strikes me as a really bad idea. I wouldn't be surprised if the optimal score is 1, achieved by an enormous network all with only weight 1 that encodes the whole dataset using its topology or its choice of gates. Even convolution layers seem very exploitable combined with copying. \$\endgroup\$ – xnor Jul 6 '19 at 2:10
  • \$\begingroup\$ @xnor 'if training is actually optional'.. Hardcoding weights, as far as I'm concerned, is a form of training. That's fine -- you may come up with your weights any way you like. But I think you're right about the distinct weights bit. I'll add a mathematically precise definition of what I have in mind that will also serve as a rough introduction to neural networks. I didn't intially want to do that because I think it distracts from the actual challenge but at this point I'm convinced it needs to be done to avoid disputes. \$\endgroup\$ – Stefan Mesken Jul 6 '19 at 3:57
  • 1
    \$\begingroup\$ @xnor, yes: it's quite easy to show that \$\textrm{selu}_{0,1}\$ and weight -1 gives a Turing-complete system. \$\endgroup\$ – Peter Taylor Jul 6 '19 at 7:23
  • \$\begingroup\$ @PeterTaylor That can't be right. You have to, at least, allow recurrent layers or some similar feature. Otherwise you won't be able to model the Ackermann function. \$\endgroup\$ – Stefan Mesken Jul 6 '19 at 22:20

Calculate a constant from its characteristic function

You are given in some language-dependent way (e.g. a lambda parameter) a characteristic function which is basically another way of saying a function. This function will take an integer input and return true or false, or 1 or 0, or any other two 1-byte values of your choice. You can decide whether you need the function to be 0-indexed or 1-indexed.

Your job is then to take this function and calculate the floating-point value obtained by interpreting the values of this function as a binary fraction. You must use as many significant digits as possible. I will assume IEEE double precision by default but you many use single precision if your language specifically supports it.

For example, if a function returns the sequence 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 (this is OEIS A010051), then your program or function will output 0.41468250985111166 as any further terms will be less than the precision of a double-precision value.

You can decide whether you want to round the 54th significant bit up or not.

This is , so the shortest program or function that breaks no standard loopholes wins!

| |
  • \$\begingroup\$ I'm missing an explicit statement of where the binary point goes. Also, some tests which cover corner cases (minimum, maximum, denormal). \$\endgroup\$ – Peter Taylor Jul 8 '19 at 10:57
  • \$\begingroup\$ @PeterTaylor The binary point goes before the first value as retrieved, so 0, 1, 1, 0, 1... becomes .01101.... For corner cases would it help if I said that at least one of the first 1000 elements will be "true"? \$\endgroup\$ – Neil Jul 8 '19 at 11:30
  • \$\begingroup\$ That would eliminate 0 as a possible output, whereas I think is itself one of the corner cases. It would also eliminate denormal numbers. The smallest positive double value is \$2^{-1074}\$. \$\endgroup\$ – Peter Taylor Jul 9 '19 at 6:19

Make a bigger number

Each answer on this question must be a complete program (not a function) that outputs a positive integer in decimal (trailing newlines are permitted). Output should be either passed to STDOUT or displayed on the screen. The output number must also be larger than all the numbers output by all the valid answers at the time of posting. One person may not post two consecutive answers.


Your answer will be scored with the following formula


Where \$B\$ is the number of bytes in your answer and \$B'\$ is the number of bytes in the longest answer before your answer posted by someone other than yourself. Lower scores will be better.

| |
  • \$\begingroup\$ Could you please clarify some more rules? E.g, in these sorts of challenges, using the same languages twice is prohibited. Even if you're fine with it, just clarify that to avoid confusion. Also, state when it will end and whether a lower/higher score is better. Further, some languages don't have an 'integer' type, while others have many - how could they get around this? \$\endgroup\$ – Geza Kerecsenyi Jul 9 '19 at 20:19
  • \$\begingroup\$ @GezaKerecsenyi Prohibiting double language use is only used in specific scenarios it is in general it tends to be very bad rule to have as it only causes confusion. I definitely do not see it as the default and I don't want to give the impression that it is. Since programs have to be complete for this challenge (we are viewing programs as black boxes) types should not be a problem. Maybe I need to make this clearer in the post. And on the lower vs higher, that is definitely something important I was missing. Thanks! \$\endgroup\$ – Wheat Wizard Jul 9 '19 at 21:08
  • \$\begingroup\$ Answer chaining questions should have some inherent mechanism whereby it gets harder to answer over time. As it stands, this can run forever. \$\endgroup\$ – Peter Taylor Jul 10 '19 at 13:43
  • \$\begingroup\$ @PeterTaylor I was under the impression that later answers would get harder because those challenges have scoring mechanisms that benefit later answers. \$\endgroup\$ – Wheat Wizard Jul 10 '19 at 13:51
  • \$\begingroup\$ I'm not certain that I'm interpreting that comment correctly. The answer chaining challenges I've participated in didn't have scoring per se, but "the penultimate answer wins". \$\endgroup\$ – Peter Taylor Jul 10 '19 at 15:01
  • \$\begingroup\$ @PeterTaylor I was being a bit more general in my statement but that is the specific mechanism that I see a lot. \$\endgroup\$ – Wheat Wizard Jul 10 '19 at 15:01
  • \$\begingroup\$ Hm... actually, Peter Taylor's point isn't entirely wrong. An issue I can see is that the scoring formula will probably end up making each answer at least exponentially longer than the previous one, and that two or more people could actually duel just by adding more bytes to their code, e.g. A: 50000 9s, B: 5E50 9s, A: 5*10^99E99 9s, etc. In my opinion, the previous scoring formula (\$\frac{B_{n-1}+1}{B_n+1}\$) was much better, but with the highest score being the leader. \$\endgroup\$ – Erik the Outgolfer Jul 10 '19 at 17:24
  • \$\begingroup\$ I think I can parse that response, but I don't get the subtext at all, so I'll rephrase my point as a question in the hope of eliciting a concrete response: what prevents two people from spinning this out to infinity just by copying the previous answer and adding +1? \$\endgroup\$ – Peter Taylor Jul 12 '19 at 10:49
  • \$\begingroup\$ @PeterTaylor In my mind two things 1) it probably won't get them better scores 2) it wouldn't be very fun. I am a little concerned though since these are not excellent motivators. I am going to think about other scoring mechanisms that might further disincentivise this. Or perhaps some restrictions on answers. \$\endgroup\$ – Wheat Wizard Jul 12 '19 at 13:34

Output Ordinal Numbers up to n

Moved to Output Ordinal Numbers up to n.

| |

Write an X-SAMPA Interpreter


Write an X-SAMPA interpreter that, when given an X-SAMPA string, outputs an IPA string.

Some Background

SAMPA is a system for encoding sounds from various languages into a computer-readable ASCII format. X-SAMPA is a descendant that encodes the International Phonetic Alphabet (IPA) instead. The IPA is a character set that represents (almost) all sounds that a human can make. A large majority of IPA is based on the usual Latin character set (a-z), along with some supplementary characters (θ ʌ ŋ χ, etc.).

The Challenge

  • Input is a string of X-SAMPA.
  • Translate the X-SAMPA string into IPA.
  • Output is a string of IPA.
  • Input and output can be given using any convenient method.
  • Standard loopholes are forbidden.
  • X-SAMPA charts can be found here.
  • Characters not defined in X-SAMPA should be ignored.
  • You must implement the entirety of X-SAMPA.
  • This is so lowest in bytes wins.


this is a test input --> this is a test input
THIS IS A TEST INPUT --> θɥɪʃ ɪʃ ɑ θɛʃθ ɪŋʋʊθ
H\El\L\0 W@R1d --> ʜɛɺʟ0 ʍəʁɨd
123456789 --> ɨøɜɾɫɐɤɵœ
d_"i_+a_-c_/r_/i_0t_hi_=c_>s_?\ --> d̈i̟a̠čři̥tʰi̩cʼsˤ
Code GO\lf & CodI\ng Challen\ges\ --> çode ɣʘlf ɶ çodᵻnɡ çhallenɡeɕ
clicks O\|\ǃ\=\|\|\ --> clicks ʘǀǃǂǁ
mixed~!@#$%^&*(){}[]<>,.?/:;"' --> mixed#$ˌ^ɶ*(͡æʉ[]<>,.ʔ
impl ejec b_<p_> --> impl ejec ɓpʼ
| |
  • 3
    \$\begingroup\$ Way too many edge cases here: What about supporting impossible diacritics i.e. a character marked both syllabic and nonsyllabic? The charts should be included so the challenge is self-contained. \$\endgroup\$ – lirtosiast Jul 17 '19 at 15:49
  • 1
    \$\begingroup\$ I was considering omitting You must implement the entirety of X-SAMPA and instead needing to implement only a subset, namely not the diacritics. \$\endgroup\$ – bigyihsuan Jul 17 '19 at 16:11
  • 1
    \$\begingroup\$ "Input is a string of X-SAMPA" makes "characters not defined in X-SAMPA should be ignored" redundant \$\endgroup\$ – trichoplax Jul 28 '19 at 19:27

Brute-force the switchboard

Posted here!

| |
  • \$\begingroup\$ It looks good to me! I'll remove my old comments now. Also, thanks for using the sandbox! :) \$\endgroup\$ – FryAmTheEggman Jul 18 '19 at 20:55
  • 1
    \$\begingroup\$ @FryAmTheEggman Thank you so much for the suggestions! I'll keep it up a bit longer in case anyone else remembers or finds a dupe. \$\endgroup\$ – Rin's Fourier transform Jul 18 '19 at 20:56
  • 5
    \$\begingroup\$ Poor guy indeed having to do binary counting instead of using a Gray code... \$\endgroup\$ – Neil Jul 18 '19 at 20:56

The Acrobat Competition

Anyone may post this to main once this question is done. I only care about people enjoying solving problems. (I do not want the reputation for this question.)

After someone cloned so many Jimmy's to disrupt the world, Jimmy started to be stressed about the existence of his dwarf forms; his circus leader started to ignore him, focus on the dwarves, and gradually gave him less salary.

He has to win an acrobat competition to gain attention from his leader again. (He does care about his salary.)


The first line of input will contain the acrobatic power of Jimmy; it is represented as Jimmy's (/o\) separated with spaces; invalid Jimmy's should be ignored.

After this line, there are two lines of dwarf Jimmy's also represented by their shapes: (o); invalid dwarf Jimmy's should be ignored.

The combined power between two dwarf (x as the top line of dwarf Jimmys and y as the bottom line of dwarf Jimmys) is √x²+y² (the exact floating-point number).

If Jimmy's acrobatic power is larger than the two dwarf Jimmy's, output a truthy value. Otherwise, output a falsy value.

Example input/outputs

This outputs a falsy value:

/o\ // o /o\ o o\ //o\\ /o\ /o\ /o\
o o o o
/o\ l o j oe o lo . o aso o feo o

This outputs a truthy value:

/o\/o\ /o\ /o\ /o\ /o\ /o\ /o\
o	o o 	 o
o	o o o	o o oo o o o o
| |
  • \$\begingroup\$ two dwarf Jimmy's should be two lines of dwarf Jimmy's? \$\endgroup\$ – bigyihsuan Jul 22 '19 at 19:40
  • \$\begingroup\$ You should probably work through an example because I'm not sure what x and y relates to. Is x the number of dwarves in the top line, and y the number in the bottom? \$\endgroup\$ – Veskah Jul 23 '19 at 19:55
  • \$\begingroup\$ @Veskah It looks that way. \$\endgroup\$ – wizzwizz4 Jul 24 '19 at 18:37

Insert an exclamation mark between everything

This challenge is highly "distilled" from this question. Special thanks to Akababa!

In this task, you should insert an exclamation mark at the start of the string and after every character.


  • There will always be a non-empty-string input. The input will not contain tabs either. You can assume that the input only contain non-extended ASCII printable characters and newlines.
  • This is a contest; the shortest answer should win.


  • 4 newlines result in 5 newline-delimited exclamation marks. It is very hard to put this as a Markdown text, so this is stated instead.
1 2 3 4 5 6
129591 129012 129127 129582



!1! !2! !3! !4! !5! !6!
!1!2!9!5!9!1! !1!2!9!0!1!2! !1!2!9!1!2!7! !1!2!9!5!8!2!
asd afjoK ak:e
KFkepjgop sgpaoj   faj


!a!s!d! !a!f!j!o!K! !a!k!:!e!
! ! ! ! !f!O!J!O!E!;!
! ! ! ! !K!F!O!
!K!F!k!e!p!j!g!o!p! !s!g!p!a!o!j! ! ! !f!a!j!

A base test case with only one character:




(Auto-completion! Just kidding, there is no such thing.) Contains exclamation marks:




| |
  • 2
    \$\begingroup\$ "replace the null character with an exclamation mark" is misleading. Better wording is "insert an exclamation mark at the start of the string and after every character", though there could be something more concise. The challenge is rather simple but viable. \$\endgroup\$ – lirtosiast Jul 28 '19 at 4:37
  • 2
    \$\begingroup\$ You seem to have issues with markdown in the examples: One of your examples have tabs, but they render as four spaces which is very confusing. You can have actual tabs render by using &#9; instead of literal tabs. Your empty input collapses to zero lines which you can fix by inserting a space which won't render. The output for that case does have a space, which is wrong. \$\endgroup\$ – Adám Jul 28 '19 at 7:17
  • 1
    \$\begingroup\$ For the 3rd example, which shows no visible input, it's worth specifying what the input is so it's obvious at a glance. Also, the output contains only one exclamation mark, suggesting there are zero characters in the 3rd input, which appears to conflict with "There will always be a non-empty input". Could you clarify what "non-empty" means? Depending on their programming language background, some people will not regard the empty string as "non-empty" so this could be confusing. \$\endgroup\$ – trichoplax Jul 28 '19 at 18:14
  • 1
    \$\begingroup\$ If the input can contain newlines, it's worth including test cases that include newlines too. Perhaps a multiline input and also one composed solely of newlines \$\endgroup\$ – trichoplax Jul 28 '19 at 18:17
  • 1
    \$\begingroup\$ May input contains exclamation marks? \$\endgroup\$ – tsh Jul 29 '19 at 5:01
  • \$\begingroup\$ @tsh Yes, I added a test case. Exclamation marks are printable ASCII characters. \$\endgroup\$ – user85052 Jul 29 '19 at 5:37
  • \$\begingroup\$ Oh no, I forgot to add an objective winning criterion! Does anyone have suggestions about the criterion?(I will go with code-golf temporarily.) \$\endgroup\$ – user85052 Jul 29 '19 at 7:14
  • 1
    \$\begingroup\$ I would indeed suggest code-golf. As for the test case of only newlines. Why are there seven newlines in the input, but only five exclamation marks in the output? I would expect eight exclamation marks instead. \$\endgroup\$ – Kevin Cruijssen Jul 29 '19 at 8:52
  • \$\begingroup\$ There should only be 4 in the sample input. I seem to have problems with Markdown. \$\endgroup\$ – user85052 Jul 29 '19 at 8:59
  • 1
    \$\begingroup\$ @A__ Yeah, the markup can be a bit annoying at times. Using <pre><code>4 newlines</code></pre> makes it somewhat better, but not much. Maybe simply stating 4 newlines result in 5 newline-delimited exclamation marks is enough. Anyway, I've prepared two solutions for when it goes to main. \$\endgroup\$ – Kevin Cruijssen Jul 29 '19 at 9:11
  • 1
    \$\begingroup\$ @KevinCruijssen I can not ask this question on main, as my question asking limit was reached. You may want to post this question yourself if you wish. \$\endgroup\$ – user85052 Jul 29 '19 at 9:31
  • 1
    \$\begingroup\$ Didn't even knew there was such a thing, but apparently there indeed is. Probably because some of your challenges were confusing at first so people down-voted/close-voted before it was fixed after 20+ edits. Let's leave it in the Sandbox for now. Not sure if your question ban could be lifted somehow. Also, if I post this challenge myself I can't really post my two answers, since it's usually best to wait a few days before answering your own challenges. ;) \$\endgroup\$ – Kevin Cruijssen Jul 29 '19 at 9:42
  • 1
    \$\begingroup\$ I am puzzled as to why you're question-banned. Although you have some downvotes and deleted questions (not as much of an issue on our well moderated site), you have multiple questions with positive score. Seems the algorithm should change. \$\endgroup\$ – lirtosiast Jul 29 '19 at 20:27
  • \$\begingroup\$ @KevinCruijssen Answering your own questions seems to be fine. There seems to be no problems arising when jimmy23013 answered their own question immediately after they asked it. \$\endgroup\$ – user85052 Jul 30 '19 at 0:04
  • 1
    \$\begingroup\$ @A__ That's a tip question. :) For an actual challenge it would be weird posting your own solution before giving other users with the same programming language a chance first. \$\endgroup\$ – Kevin Cruijssen Jul 30 '19 at 7:24

Give me the jitters! / Add noise to data

When graphing data, it can often be helpful to display points as a scatterplot, but when duplicate data exist, you'll have multiple points graphed on top of one another. For fairness, we break ties at random with R's jitter function.


  • x, a numeric (floating point) array. There will be at least 3 distinct values in the array.
  • factor, a numeric value
  • amount, a numeric value or some sort of non-numeric value (your choice). You may select your desired non-numeric sentinel value for amount.


  • A single array y where:
    • y[i] = x[i] + a uniformly random number from -a to a

a is defined as follows:

  • Let z = max(x) - min(x)
  • If amount==0, a = factor * z/50
  • If amount is NULL or the , a = factor * d/5 where d = min(diff(sort(unique(x)))), i.e., the smallest difference between adjacent unique values.
  • Otherwise, a = amount.

Add test cases

Does this add anything beyond already existing challenges?

| |

Output your place

Your challenge is simple. Output your program's place as an integer at the time of execution. The shortest program is first place, and the earlier submission wins a tie.

If your solution is tied with another in age as well as length, you may output either

All answers must begin with # [Language Name], [N] bytes alone on the first line.

You may access this page (URL). No URL shorteners are allowed. Standard IO and loophole rules hold.

As you may have noticed, this is , so the shortest answer (in bytes) wins. Happy golfing!

| |
  • \$\begingroup\$ This will be very hard to test, no? So each program needs to find "its" post or at least have its own byte count and time stamp hard-coded? \$\endgroup\$ – Adám Jul 31 '19 at 20:14
  • \$\begingroup\$ @Adám Correct. It'll be interesting to see how those two approaches fare, I hope. \$\endgroup\$ – Khuldraeseth na'Barya Jul 31 '19 at 20:23
  • \$\begingroup\$ You might want to specify 1 indexing for clarity. \$\endgroup\$ – Wheat Wizard Aug 1 '19 at 14:03
  • \$\begingroup\$ @SriotchilismO'Zaic The shortest program is first place was meant to specify that. Too subtle? \$\endgroup\$ – Khuldraeseth na'Barya Aug 1 '19 at 18:53
  • \$\begingroup\$ Ah I thought that was intended to say that it was code-golf. I think it is likely clear. \$\endgroup\$ – Wheat Wizard Aug 1 '19 at 18:54
  • 1
    \$\begingroup\$ 0 bytes, output is 0 indexed. or 0 bytes, outputs via exit code \$\endgroup\$ – Jo King Aug 2 '19 at 4:13
  • \$\begingroup\$ @JoKing I thought of that. Some minutes searching TIO yielded nothing, unfortunately. \$\endgroup\$ – Khuldraeseth na'Barya Aug 2 '19 at 4:14
  • 4
    \$\begingroup\$ From experience, questions like this need to be very explicit about what assumptions can be made about the context in which the answers are executed, because otherwise there will be debates on whether JS programs can execute in the console of a browser window which is currently open on the page. \$\endgroup\$ – Peter Taylor Aug 2 '19 at 7:36

Buffer Evaluation

Given a printable ASCII string, but with leading spaces(0x20) and backspaces(0x08), return it "buffer-evaluated".


For the inputted line, if you encounter a space, enter a space; otherwise, remove the rightmost character.

If you encounter a backspace when the buffer is empty, simply do nothing.


After the inputted program, if the cursor is 0, output an optional trailing newline. If the cursor is not 0, output the string in the buffer and an optional trailing newline.

Example(s) and expected output


This is ; the shortest answer wins.

| |
  • 1
    \$\begingroup\$ Please avoid adding unnecessary fluff like a cumbersome I/O format which just serves to make the challenge appear to be about layout when it is really just simple summing. \$\endgroup\$ – Adám Aug 9 '19 at 6:06
  • 3
    \$\begingroup\$ This might be more interesting if there was no such thing as a negative buffer, and backspacing while at 0 did nothing, meaning it isn't just a simple sum of list anymore \$\endgroup\$ – Jo King Aug 9 '19 at 6:09
  • 1
    \$\begingroup\$ @JoKing Good idea. Or maybe: Given a printable ASCII string, but with leading spaces and backspaces, return it "evaluated". E.g. "⌫⌫   ⌫hi" gives "  hi" \$\endgroup\$ – Adám Aug 9 '19 at 6:16
  • \$\begingroup\$ Related \$\endgroup\$ – Adám Aug 9 '19 at 6:39
  • \$\begingroup\$ Related, but not taking into account backspacing empty text. I don't like the special case of 0, since logically, the output should be an empty string, not a backspace \$\endgroup\$ – Jo King Aug 9 '19 at 6:48
  • 1
    \$\begingroup\$ Regarding 0 → BS: Please avoid exceptional edge cases. \$\endgroup\$ – Adám Aug 9 '19 at 7:08
  • \$\begingroup\$ Many languages will put a trailing line break after the output, further serving to indicate the the process has been completed. \$\endgroup\$ – Adám Aug 9 '19 at 7:09
  • \$\begingroup\$ Your "Output " section seems to be a leftover from the previous version of the challenge: return it vs output how many \$\endgroup\$ – Adám Aug 9 '19 at 7:11

Do X without Y

The goal is drawing an X on an empty 3x3 raster "canvas". You have to do so by drawing pixel by pixel, showing each intermediate step. But there should never be an Y visible along the way.


  • You should start by outputting a 3x3 image of one background color. In each step one of the pixels must be changed to the foreground color.
  • You can use any two colors.
  • Instead of using pixels in an image, you can also use a string- (leading/trailing zeros/newlines are ok) or 2d-array/matrix representation.
  • An X is represented as follows:
o.o  (o = foreground, . = background)

while an y can be any of the following

o.o  o.o  ..o  o..  
.o.  .o.  .o.  .o.
o..  ..o  o.o  o.o

(title reference)

| |
  • \$\begingroup\$ May we also toggle a foreground color back to a background color later on? I.e. would for example these steps be allowed (note the top-middle 'color'): (start:) ... ... ... > o.. ... ... > oo. ... ... > ooo ... ... > ooo .o. ... > ooo .o. o.. > ooo .o. o.o > (end/X:) o.o .o. o.o? Also, does the X have to be visible in the foregound color, or may it also be in the background color? I.e. would for example these steps be allowed: (start): ooo ooo ooo > o.o ooo ooo > o.o .oo ooo > o.o .o. ooo > (end/X:) o.o .o. o.o? \$\endgroup\$ – Kevin Cruijssen Aug 13 '19 at 13:51
  • \$\begingroup\$ Remind me to upvote this question when it's posted; the title is just awesome \$\endgroup\$ – tjjfvi Aug 13 '19 at 14:01
  • 1
    \$\begingroup\$ Wouldn't this work: 1.2 .5. 3.4 (... ... ... > o.. ... ... > o.o ... ... > o.o ... o.. > o.o ... o.o > o.o .o. o.o)? \$\endgroup\$ – tjjfvi Aug 13 '19 at 14:03
  • 1
    \$\begingroup\$ -1. I don't think there's enough room for variance here. It basically reduces to a Kolmogorov complexity problem that is pretty simple in itself. \$\endgroup\$ – Beefster Aug 13 '19 at 21:18
  • \$\begingroup\$ @tjjfvi Yes that would work. \$\endgroup\$ – flawr Aug 13 '19 at 21:24
  • \$\begingroup\$ @Beefster I agree, as it is now it also felt a little bit too restricted. I honestly just wanted to come up with something silly to justify the title:) \$\endgroup\$ – flawr Aug 13 '19 at 21:24
  • \$\begingroup\$ @KevinCruijssen That is an interesting extension. I think it would indeed make sense to abolish the idea of foreground/background and just have two colors, and letting people toggle back and forth as many times as they want. \$\endgroup\$ – flawr Aug 13 '19 at 21:26
  • \$\begingroup\$ If the two things I asked in my comment aren't allowed, @tjjfvi approach is the only one possible (in any order of the corners of course) from what I can see, so maybe it's indeed good to allow both to have at least some variance in the challenge approaches. Although I guess most people would use either the one posted by tjjfvi being five steps or the second one I posted being four steps anyway. :) \$\endgroup\$ – Kevin Cruijssen Aug 14 '19 at 6:17
  • \$\begingroup\$ Could also have the answers take input of the starting pixels and/or the canvas size. \$\endgroup\$ – tjjfvi Aug 14 '19 at 12:09
  • \$\begingroup\$ idea: what if this were expanded to some sort of fractal/recursive version? You could specify an integer between, say, 0 and 9, and create X's out of X's recursively to that depth, but with the restriction that you can't ever create a Y out of any 5 evenly spaced pixels. \$\endgroup\$ – Beefster Aug 30 '19 at 21:18

Crossing Sequences


| |

A triangle is worth a thousand lines

Vulkan is a relatively new cross-platform graphics API which is very powerful yet extremely verbose and detailed.

Arguably one of the most infamous saying on Vulkan, especially among beginners is, "The 1000 Lines journey". That is, getting a simple triangle to render on the screen takes a ton of code (~1k lines of C/C++).

It's time to break, nay, golf the stigma!


Your challenge is writing a valid Vulkan-API based program which outputs a triangle to the screen. The windowing system is up to your choice as well as the colors/size of the triangle/screen itself.

The final script/compiled program should be able to be executed (preferably on a platform which does not require extra tools/hardware) and the output made visible in order to count as a valid solution.


None. (Any if you require it, but it will also account into the score)


A visible triangle on the screen. The following rules apply:

  1. The color of the triangle and the color of the background should be different.
  2. The size of the triangle should be noticeable. That is, any person with healthy eyesight should immediately be able to notice it.

Note: The final output triangle must be an actual call to drawing a 3 vertexed mesh and not simply points which render to some 4 pixels on screen.

Hardware constrains

Since the setup code differs greatly from GPU to GPU, you can assume that all the extensions are supported and that the GPU/driver is capable of executing a valid API call. Namely, input validations aren't mandatory, swapchain is present, queues are optimal, etc...


Standard 1 (source code) byte = 1 point scoring, less is better. (The shaders source file sizes also counts towards the final score)

Note There are currently but a few available bindings for Vulkan which means that the language choice isn't as wide as other challenges. However, there is plenty to choose from with different paradigms, thus it shouldn't harm the creativity of the solutions :)

Helpful resources

| |
  • 2
    \$\begingroup\$ Could you perhaps add a link to the Vulcan API in your challenge description? It's personally the first time I heard about it, and had to google a bit. From what I could see the Vulkan API can be used either in C or C++, with no other languages supported, is that correct? In that case this challenge could be tagged: [code-golf]; [c]; [c++]; [graphical-output]; [geometry]. \$\endgroup\$ – Kevin Cruijssen Aug 14 '19 at 6:29
  • 1
    \$\begingroup\$ Sure! also, there are more than a few bindings for Vulkan already available, some even in "glofy" languages, such as lua and haskell: vinjn.com/awesome-vulkan/#bindings, I'll add some helpful links and directions in the challenge. \$\endgroup\$ – Elian Kamal Aug 14 '19 at 11:01
  • 1
    \$\begingroup\$ "The size and color don't matter as long as they are different." I think I got your point, but could you rephrase it a bit? I think you mean that the color should be different from the screen's, but I'm not 100% sure, could be "from a run to another run, the triangle has to be different (random size and color)". Plus, if you take this sentence out of context, it has no sense, as seen at start of this comment :) \$\endgroup\$ – V. Courtois Aug 14 '19 at 12:43
  • \$\begingroup\$ Yes I can see how it may seem unclear. What I meant was much more straightforward, "the background and the triangle color should be different" + The triangle itself should be visible too (A normal healthy human eye can see). The intent was clearing two loopholes: 1) Triangle and background are in the same color (Presenting a blank screen as an answer "It's a blue triangle on a blue background"). 2) Rendering a triangle which is too small to see without additional tools I'm not really sure how to formulate these to be honest.. \$\endgroup\$ – Elian Kamal Aug 14 '19 at 14:37

Get the number of upvotes of your own answer

Write a piece of code which makes a request to codegolf.stackexchange.com and prints the, up to date, number of upvotes to the specific answer in which you've posted that piece of code.

As a test case I'll post a (poor!) answer below (obviously only in the real question).

This is just a random idea I had when reading some other code golfing challenges, and I thought I'll post it here to see if it will fly.

| |
  • \$\begingroup\$ Standard procedure(although weird, it is inevitable): Post a placeholder answer, copy the URL, and then make a request to that URL. (Although how can I access the number of votes?) \$\endgroup\$ – user85052 Aug 20 '19 at 13:59
  • \$\begingroup\$ Yes, it would inevitably involve editing your answer (unless you embed a unique string in your answer just to find it...?). I admittedly have not tested this yet. I’ll have a play in python and make sure it’s not too hard to extract the information about the number of upvotes... \$\endgroup\$ – MarcinKonowalczyk Aug 20 '19 at 14:08
  • \$\begingroup\$ I recognise this would be a longer than usual challenge for core golf, but I thought exactly that would maybe make it interesting. \$\endgroup\$ – MarcinKonowalczyk Aug 20 '19 at 14:12
  • \$\begingroup\$ Can you define "core golf"? \$\endgroup\$ – user85052 Aug 20 '19 at 14:18
  • 6
    \$\begingroup\$ I'm afraid it's already done before 3 years ago, so it would be closed as a duplicated. \$\endgroup\$ – Kevin Cruijssen Aug 20 '19 at 14:21
  • \$\begingroup\$ Thank you for using the Sandbox and finding out it was a duplicate rather than posting it on main first. \$\endgroup\$ – MilkyWay90 Aug 20 '19 at 19:19
  • \$\begingroup\$ No worries. I came up with it all by myself so I’m still happy. ;) Also, @A__ “core golf” was, of course, a typo. \$\endgroup\$ – MarcinKonowalczyk Aug 20 '19 at 20:29

Approaching the Graham's number

Write a program that could theoretically output an integer with the minimum absolute difference to the Graham's number. Your code is cracked if a robber writes a program to output the Graham's number exactly, in the same language, with the edit distance to your code under a specific limit.

Builtins for the Graham's number is disallowed.

Details to be added, if I think this idea actually works.


How to set the limit?

  1. Fixed number of bytes.
  2. Fixed % of the code. Does the boilerplate count?
  3. Set by the cop. But how to fix the winning criterion?

Do the cops need to know a crack to make the submission valid?

| |
  • \$\begingroup\$ What does "could theoretically output an integer with the minimum absolute difference..." mean? Would a program that outputs "Hello, World!" in a loop be valid, assuming enough time and radiation? Would a program that outputs all odd numbers be valid? Do we just have to output any number? \$\endgroup\$ – the default. Sep 6 '19 at 17:18
  • \$\begingroup\$ @someone "Output an integer" means to output a string matching /-?[0-9]+/ exactly, or any equivalents in other allowed formats. No hello world or multiple numbers. I'm not sure why you would think that. \$\endgroup\$ – jimmy23013 Sep 6 '19 at 17:29

"Condense" String of Text

You will be given a string. You will be "condensing" it by combining the bits of characters into one.


  • The condensation works as follows:
    1. You are given a string with 8-bit characters, such as Hèl¹ò Wôrld, hex 48 e8 6c b9 f2 20 57 f4 72 6c 64
    2. Combines bits into 16-bit groups, from right to left. Above becomes hex 48 e86c b9f2 2057 f472 6c64, or H槲⁗汤.
  • You may assume that all characters in string range from 0x00 to 0xff.
  • Your resulting string would be encoded in UTF-16.
    • You may also assume that the resulting string won't contain characters from 0xd800 to 0xdfff, or the input containing any of ØÙÚÛÜÝÞß at even index in 0-index, or odd index in 1-index.
  • Standard loopholes apply.
  • This is code-golf so shortest code wins.


Input raw: abacaba
Input hex: 61 62 61 63 61 62 61
Outpt raw: a扡捡扡
Outpt hex: 61 6261 6361 6261
Input raw: Example.
Input hex: 45 78 61 6d 70 6c 65 2e
Outpt raw: 䕸慭灬攮
Outpt hex: 4578 616d 706c 652e
Input raw: ÿ!0ÿMÿEÿSÿSÿAÿGÿE0ÿCÿAÿN0ÿAÿPÿPÿEÿAÿR0ÿTÿOÿOÿ
Input hex: ff 21 30 00 ff 4d ff 45 ff 53 ff 53 ff 41 ff 47 ff 45 30 00 ff 43 ff 41 ff 4e 30 00 ff 41 ff 50 ff 50 ff 45 ff 41 ff 52 30 00 ff 54 ff 4f ff 4f ff 0e
Outpt raw: A message can appear too.
Outpt hex: ff21 3000 ff4d ff45 ff53 ff53 ff41 ff47 ff45 3000 ff43 ff41 ff4e 3000 ff41 ff50 ff50 ff45 ff41 ff52 3000 ff54 ff4f ff4f ff0e
Note that there are NULs in the input.
| |
  • 1
    \$\begingroup\$ You might want to specify an encoding for the 16-bit encoding. For example, if you use UTF-16, then the values D800-DFFF are not valid characters \$\endgroup\$ – ar4093 Aug 23 '19 at 18:21
  • \$\begingroup\$ This is essentially translation between encoding types, since the input bytes will be identical to the output bytes \$\endgroup\$ – Jo King Aug 25 '19 at 12:14
80 81
83 84

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .