This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. 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.

Sandbox FAQ


To post to the sandbox, scroll to the bottom of this page 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, though you can optionally add a title at the top. 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.


The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.


Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!


3933 Answers 3933

7 8
10 11

Regex Golf Generators



The cops must post a 150 byte or less program in any language that outputs between 20 and 200 strings of printable ASCII (this excludes newlines), half of them "match" strings and half "don't match" strings. You can't output an odd number of strings -- there must be one don't match for each match.

The strings can be output as two lists of strings, or one list with a fixed delimiter between the "match" and "don't match" sections. The "match" and "don't match" lists can come in any order.

The following special characters are not allowed in the strings: ()[]*+?.\|^$.

Note that the program must be deterministic, and the language must be revealed.


The robbers must pick a cop answer and submit a regex in any flavor that matches the "match" strings but does not match the "don't match" strings.

The regex must be shorter than min(<length of all the match strings> + <number of match strings>-1 + 4, <length of all the don't match strings> + <number of don't match strings>-1 + 10), as this is the length of the regex that simply hardcodes it: ^(<match string 1>|<match string 2>|...)$ or ^(?!(<don't match string 1>|<don't match string 2>|...)$).*.

The shortest regex posted for that submission wins (note that there can and should be multiple competing cracks for one submission).


The robber's score is simply their number of wins (posted the shortest regex for a given submission) -- higher is better.

The cop's score is max(byte count of winning regex - byte count of submission - 4*(number of match strings - 10) for each submission) -- again, higher is better (you should be maximizing the length of the cracks and minimizing the length of your code). The byte count of the winning regex for an uncracked submission is the length of the hardcoded regex. Self cracks are permitted but must be marked as non-competing and will not count toward your cop or robber score.

The winning cop and robber will be announced 2 weeks after the posting of this challenge. Submissions will be allowed after that, but will not count towards your score.

  • \$\begingroup\$ Can they be a list of lists, i.e. [['string1',truthy],['string2',falsy]...]? With truthy/falsy being match/don't match. \$\endgroup\$
    – Riker
    Feb 15, 2017 at 17:41
  • 2
    \$\begingroup\$ I've said this in chat, but I'm listing it here for reference: 1. No need to have a fixed number of match strings. 2. No need to remove regex special characters. Everybody has the same benefit of using them. 3. No need to have a maximum regex length. It's like having a maximum bytes on a code-golf. 4. I don't see why you want to aggregate the cops' scores. Simply make it a standard maximum-score-wins. Otherwise, a person who posted the best scoring submission may lose to another who only posted a single decent submission. 5. Disallow self-cracks. It's too abusive for robbers. \$\endgroup\$ Feb 16, 2017 at 1:42
  • 2
    \$\begingroup\$ What's the point of allowing a "Retina flavor" of regex? Wouldn't that be identical to .NET? \$\endgroup\$
    – feersum
    Feb 16, 2017 at 8:23

Machines learning arithmetic

Note: Feel free to take and use this challenge, either the entire challenge as is, or just parts of it.

I've made a complete rewrite of this question. I figured the original version was more complex than it had to be. The task is essentially the same. The original challenge text had 4 upvotes and can be found in the edit history.

You will receive 30 lists of integers. Those lists are the result of a polynomial expression y = p(x) = a*x^4 + b*x^3 + c*x^2 + d*x + e, for x in the inclusive range [-1e5, 1e5]. Let's call those lists L1, L2 ....

I reserve the right to make changes to the lists by changing constants and the order if solutions seem to be custom made for those 30 lists.


Your task is to figure out what the constants a, b, c, d, e are for each of those 30 lists.

You will write a code that pulls numbers from each list (one list at a time). It must ask for the y-values for individual x-values, as many as you want, but one at a time. When you think you have enough information, you'll attempt to guess the value of the constants.

You'll do this for all 30 lists.


The lowest score wins!

  • You get 1 point for every number you pull from the list
  • You get 10 points for every attempt to crack the code (guess a, b, c, d, e)
  • The scores for all lists will be added up.

If no submission cracks all lists successfully then the one that cracked the most will win. Tie breaker #1 will be fewest points, tie breaker #2 will be time of submission.

Rules and clarifications:

You can assume all constants to be integers

The lists will be formatted in this way (suppose the expression for L1 is: 2*x). I'm using MATLAB/Octave syntax for a cell array. You can change this to fit your needs (language).

L1 = {[-200000, -199998, -199996, ... -4, -2, 0, 2, 4, ... 199996, 199998, 200000], [0 0 0 2 0]};

You can change the format to fit your needs, but you must not mix the list and the values for a, b, c, d, e.


You ask for y for four different input values, and get the results:

L1(0) = 0
L1(1) = 0
L1(2) = 2
L1(3) = 12

Your function guesses (for some reason) that this is x^3-2x^2+1, and attempts to crack it:

L1([0, 1, -2, 0, 1]

You have tried 4 values, and attempted to crack it once. This gives you 4 + 10 = 14 points.

You try a few more values:

L1(-9) = 6480
L1(-7) = 2352
L1(7)  = 2352
L1(9)  = 6480
L1(100)= 99990000

You're now confident that this has to be: x^4-x^2, and attempt to crack it again:

f([1 0 -1 0 0])

You have successfully guessed the constants a, b, c, d, e, and get a score of `14 + (5 + 10) = 29 points.

You have 29 functions left.

  • I'll have to post the lists on some suitable place (where)?
  • Can I ban builtin interpolation functions somehow without risking the "unobservable requirements", "x without y" pitfalls?
  • Anything else?
  • \$\begingroup\$ This isn't yet 100% clear to me, but I've upvoted because it looks like an interesting idea that will make a great challenge once fine tuned. \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 10:58
  • \$\begingroup\$ :) Anything in particular that isn't clear, or everything in general? \$\endgroup\$ Jan 18, 2017 at 11:00
  • \$\begingroup\$ I've edited... It was never intentional to have the number of bytes mixed in here... I'm probably just so used to writing it that I didn't even notice it :P \$\endgroup\$ Jan 18, 2017 at 11:03
  • \$\begingroup\$ Will it be done like: 1. "start writing your function" 2. "end of function writing period" 3. "release black box function for scoring submissions"? To avoid learning the expressions and tuning the functions to fit. \$\endgroup\$
    – Emigna
    Jan 18, 2017 at 11:04
  • \$\begingroup\$ I guess you could have a controller that generates new random test cases each time to allow the competition to be open ended, but rescoring the old entries might reorder them in some cases. Might need to average over a number of different sets of test cases. \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 11:07
  • \$\begingroup\$ The given example of h(x) = ((3*x*x*x)/(x+1))+1 is incompatible with "You can assume the functions will give integer results back". But basically it's a case of guessing and verifying a rational function of some bounded degree? \$\endgroup\$ Jan 18, 2017 at 11:09
  • \$\begingroup\$ If you want a variety of languages to be able to compete without having to implement arbitrary size integer arithmetic, you could use modular arithmetic. For example, everything is mod 256, or 65536. \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 11:10
  • \$\begingroup\$ @Emigna, good question :) One solution could be: Provide x number of functions on a certain format. After the submission is posted it will be tested against the "real" cases that are of similar difficulty, but different. I think I can have some fairly easy, and some quite hard. But it's a really good question, so I'm not sure... I'm open for ideas :) \$\endgroup\$ Jan 18, 2017 at 11:11
  • \$\begingroup\$ @PeterTaylor, I made a blooper when making the examples. Using rational functions with input arguments and 8/10(?) significant figures in the output is probably a good idea. I think 10 is low enough that rounding shouldn't be an issue as long as you have the correct function..? And it can be restricted to 3/4/5..9th degree polynomials. \$\endgroup\$ Jan 18, 2017 at 11:15
  • \$\begingroup\$ Peter's comment also makes me wonder what happens for division by zero. Will this be avoided somehow or will we be informed that a particular input causes an error? Will the error be specifically "division by zero" or just "error"? \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 11:16
  • \$\begingroup\$ First comment @trichoplax: You have a point, but it will also make it harder, since it will no longer be a continuous function. Second comment: I think an error message / warning of some sort would suffice. Handling that error should be very simple, since this isn't code golf. It will probably be 1-3 lines of code. Giving inf for divison by zero, and error for 0/0 could also be a solution (that's the default solution in MATLAB). \$\endgroup\$ Jan 18, 2017 at 11:21
  • \$\begingroup\$ Note that if you want continuous functions you would need to avoid rational functions, but it sounds like you're happy with piecewise continuous if you don't mind "inf" and "error" in some places? \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 11:34
  • \$\begingroup\$ @trichoplax, What do you think? Is modular arithmetic a good idea? Should I skip division (impossible to avoid division by zero if not)? \$\endgroup\$ Jan 18, 2017 at 11:51
  • \$\begingroup\$ I really don't know. I'm just suggesting possibilities. Someone more mathematical would probably be useful for assessing whether modular and rational functions would be interesting to crack. Are you aiming for a situation where most people can write code that cracks all 10, but getting a low score is challenging, or where most people can only crack a proportion of the 10? \$\endgroup\$
    – trichoplax
    Jan 18, 2017 at 11:59
  • 1
    \$\begingroup\$ Parentheses should be removed since it makes this challenge much more difficult... and it is already really difficult without them \$\endgroup\$ Jan 19, 2017 at 0:44

This message is open for anyone to adopt and post to main. For more details, see the chat room or meta post.

Ping an IP address continually and report the dropped to returned ratio

Create a console program that pings an IP address at most once per second and reports the ratio of dropped to returned packets to the screen in real time.

The IP address will be provided on the command line in standard IPv4 notation. (eg.

The 'ping' method should be ICMP echo (See here for a summary of ICMP packet structure) with a packet size of at least 32 bytes.

Your program must be "standalone" and cannot rely on external programs, libraries, or resources.

This is so let the shortest answer win

  • \$\begingroup\$ ping isn't enough? \$\endgroup\$
    – TheDoctor
    Apr 7, 2014 at 19:31
  • \$\begingroup\$ ping works great, except you have to tell it when to stop to get the final tally \$\endgroup\$ Apr 7, 2014 at 19:32
  • \$\begingroup\$ I think you're assuming that everyone will interpret this as sending the same ICMP control packet that ping sends, but it would be an improvement to the question both to make this explicit and to link to some documentation about ICMP. \$\endgroup\$ Apr 7, 2014 at 22:46
  • \$\begingroup\$ Actually I left it ambiguous. Any IP request that elicits a response can be considered a ping. \$\endgroup\$ Apr 8, 2014 at 1:00
  • \$\begingroup\$ Alright, lets make it easier and say ICMP specifically... \$\endgroup\$ Apr 8, 2014 at 12:16
  • \$\begingroup\$ Well this doesn't have enough upvotes...I'll leave it in the sandbox, but likely it will not be posted \$\endgroup\$ Apr 9, 2014 at 12:17
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$
    – user58826
    Jun 9, 2017 at 16:34
  • \$\begingroup\$ @programmer5000 be my guest :) \$\endgroup\$ Jun 9, 2017 at 16:40

Me, Me, Me!

Edit: changed success when the input matches the source code to when the input is any permutation of the source.

Your code is clearly superior to all other code. In fact, your code is so great that it prints itself when the opportunity arises (but not when any other, inferior code is around.)


Write a program or function that takes a string as input. If the string is equal to some permutation of the characters in your source code, then output the entire source code. Otherwise, output Gross.

If your language uses a non-ascii encoding, "character" is defined as whatever a character in your source looks like. If it's unreasonable to take input in that format, you can treat the bytes of your source as their respective extended ascii codes.


Takes a string using whatever input mechanism your programming language provides.


Prints either the entire source of your program or the word Gross. No additional output is permitted.


  • You can take input using any reasonable method. (Stdin, function parameter, etc.)
  • A string a is a permutation of a string b iff each character in the alphabet appears the same number of times in a and b.
  • This is Shortest code (in bytes) wins.
  • \$\begingroup\$ quine? -- \$\endgroup\$
    – MD XF
    Jun 7, 2017 at 21:32
  • \$\begingroup\$ @MDXF it will have the quine tag, of course – but it's not strictly a quine unless it gets the right input! I just didn't see how to add tags in the answer... \$\endgroup\$ Jun 7, 2017 at 21:34
  • 1
    \$\begingroup\$ Use [tag:quine] in the header. And yes, we accept the quine tag for quine variants :-) \$\endgroup\$
    – MD XF
    Jun 7, 2017 at 21:34
  • 2
    \$\begingroup\$ trivial extension of this challenge \$\endgroup\$ Jun 7, 2017 at 23:14
  • \$\begingroup\$ aw shucks. I figured something like this existed already, just didn't know what to search for. \$\endgroup\$ Jun 8, 2017 at 14:36
  • \$\begingroup\$ actually, @DestructibleLemon I could be missing something obvious but I don't think the extension is trivial. Printing its own source code is, I would say, significantly harder than printing "true" as long as I add the usual restriction that it can't read its own source. \$\endgroup\$ Jun 8, 2017 at 14:38
  • \$\begingroup\$ @rogaos If the test on the input passes, printing its source code is as simple as printing the input string. \$\endgroup\$ Jun 8, 2017 at 15:33
  • \$\begingroup\$ @NonlinearFruit true of course, but adding the print statement may make the quine harder to construct in the first place. (Except in languages like javascript, which are basically reading their own source anyway.) Maybe the challenge would be improved by transforming the input string in some way, or crashing on "correct" input? \$\endgroup\$ Jun 8, 2017 at 15:38
  • \$\begingroup\$ @rogaos it is the difference between printing true and printing the input \$\endgroup\$ Jun 8, 2017 at 23:29
  • \$\begingroup\$ modified to use permutations of the input rather than the input itself \$\endgroup\$ Jun 19, 2017 at 18:21

What is your Operating System?

I can't believe we haven't had this one before

To avoid any doubts about what constitutes a separate OS, you must return an index into your chosen subset (containing minimum two) of the following OS families. You may order your set as you like, so include your ordered set, and state if you use zero or one based indexing. You may also bunch together families you cannot distinguish between.

  Windows, Minix, Linux, macOS, BSD, HP-UX, AIX, Solaris, Unix, Z/OS, OS/2, QNX

Your score is your byte count divided by the square of the number of indices your code can return – given that it is run on the appropriate OSs, of course.

You do not have to account for virtual machines, emulation layers etc., e.g. WSL and Wine.


Your code can detect Windows, macOS, AIX, and Linux. It returns 0 for Windows, 1 for macOS, 2 for AIX, and 3 for Linux. Your score is a sixteenths of your byte count.

Your code can distinguish between Z/OS, OS/2, and UNIX/Linux/AIX. It returns 1 for Z/OS, 2 for OS/2, and 3 for any UNIX-like OS. Your score is a ninth of your byte count.

  • \$\begingroup\$ 2 is definitely better than 1. After that I think it may just be your preference for the kinds of answers you want. I think 3 will promote more answers that reach, while 2 will promote more 2 answers. However, if you really want to reach maybe make the denominator grow as a square? These scoring mechanisms are unfortunately very important to these kinds of challenges as well as very hard to figure out beforehand. I'd ask around and see what other people think! \$\endgroup\$ Jun 15, 2017 at 0:37
  • \$\begingroup\$ @FryAmTheEggman Thanks. \$\endgroup\$
    – Adám
    Jun 15, 2017 at 0:39
  • \$\begingroup\$ Are not macOS, BSD, and Linux Unix? Is OSX considered the same as macOS? \$\endgroup\$
    – Wheat Wizard Mod
    Jun 21, 2017 at 14:53
  • \$\begingroup\$ The I/O requirements are rather strict, could you not just print/return the name of the OS? \$\endgroup\$ Jun 21, 2017 at 14:56
  • \$\begingroup\$ @WheatWizard Yes, but you may pick whichever many you want from that list, so you can bunch all Unixes together or keep them separate, or you can detect specific flavors while also detecting vanilla Unix. \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:02
  • \$\begingroup\$ @musicman523 I'd rather have comparable output from all solutions. \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:03
  • 3
    \$\begingroup\$ It seems like people with access to proprietary OSs will have an advantage in this problem. For example, to ensure my code runs on Windows I have to buy windows, because I don't own it. I happen to own a copy of OSX, but other users might not given me an advantage. I feel like this is problematic. (also is OSX considered the same macOS?) \$\endgroup\$
    – Wheat Wizard Mod
    Jun 21, 2017 at 15:09
  • \$\begingroup\$ @WheatWizard You're right, but that will be problematic in detection of OSs no matter what the challenge is. And yes, good luck testing your solution on Z/OS… \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:34
  • \$\begingroup\$ It's not just that. If I claim to detect Windows, which versions of Windows do I have to test it on? And what can I assume about e.g. the C header files that are available? \$\endgroup\$ Jun 21, 2017 at 15:35
  • \$\begingroup\$ @WheatWizard Oh, and yes, OSX and macOS are the same (I don't expect anyone to submit an answer that will run on MacOS 9-) \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:35
  • \$\begingroup\$ @PeterTaylor Good point. Any ideas how to fix this or is it doomed? \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:36
  • 1
    \$\begingroup\$ I suspect that the difficulties around specification and testing might explain why this hasn't been asked already. \$\endgroup\$ Jun 21, 2017 at 15:44
  • \$\begingroup\$ Why numbers only? Why not just outputs? \$\endgroup\$ Jun 21, 2017 at 16:00
  • 1
    \$\begingroup\$ Is the set of OSes listed there exhaustive? (I've done some programming on SunOS in the past, for example, although I don't have access to it right now.) Also, "Unix" seems a bit strange to have in the list; many of the listed OSes (e.g. BSD and Solaris) are flavours of Unix. It's also worth being aware of cases like WSL and Wine; which OS should they count as? \$\endgroup\$
    – user62131
    Jun 22, 2017 at 10:28
  • \$\begingroup\$ @ais523 "Unix " allows submissions to bunch together various flavors as one, and also allows differentiating the other Unixy OSs from vanilla Unix. I'll add a note about virtual machines etc. \$\endgroup\$
    – Adám
    Jun 22, 2017 at 14:54

One OEIS after another

  • 1
    \$\begingroup\$ This sounds fun! \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 22:32
  • \$\begingroup\$ Awesome frickin' idea. You might wanna add what to do when one answer reaches 289,585 bytes ('cause obscure esolangs). ;) \$\endgroup\$ Jul 19, 2017 at 22:41
  • 1
    \$\begingroup\$ @totallyhuman I would've thought that that score is about right for Java, so I'll address that \$\endgroup\$ Jul 19, 2017 at 22:59
  • \$\begingroup\$ A possible problem is that many languages have "add 1" and "subtract 1" or similar functions that are inverses of each other. So you could add any even amount of bytes. For example, sequence A005843 (the even integers) in CJam can be ri2* or ri2*()()()()()()()() \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 23:07
  • \$\begingroup\$ Ah, no, the rule is that removing any subset of the characters must give wrong output. That rule is enough to invalidate the above \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 23:08
  • \$\begingroup\$ I think the rule about the program having to be pristine is bad for this challenge. It makes writing answers incredibly difficult in most languages. Why do you care if people change the length of their post? All they can do is control which sequence appears next. \$\endgroup\$ Jul 19, 2017 at 23:19
  • \$\begingroup\$ You might want to bold or otherwise emphasize unused language, as I missed it the first couple times I read through (or just remove that restriction, because it would be more fun if we had to go through all sequences instead of all languages ;) ). Also, what to do about very short sequences, such as the busy beaver sequence? \$\endgroup\$
    – Stephen
    Jul 21, 2017 at 13:01

Invisible Ink, Easy

In the physical world, invisible ink usually becomes invisible when it dries, and is then is readable if it is exposed to heat or chemicals of some kind. The invisible ink in this challenge will be readable when exposed to highlighting.

Create a full program or function that takes in text from the console (using a prompt) and outputs it the console so it cannot be seen unless highlighted.

enter image description here

enter image description here


  • Assume that the console is a solid color (black, white, green, etc.).

Let's play Othello (Reversi)!

Open for takeover

I don't have the time to devote to this right new, and not for the foreseeable future. Anyone who wants this idea, the post, and any code I have in the repo should comment below.

Side note on the code, I have a gorilla repl file in the repo that I can use to run test games on, and get screenshots of during any point of the game. If you want I can make up screenshots for the rules section since I have everything setup on my end for that.

This would be a king of the hill about reversi. Yep. I'm going to write up the post and controller later The controller is being written here: https://github.com/JJ-Atkinson/reversi-koth-ppcg , but I'm putting this here so show the idea is taken ;)

Post start


(you can probbably skip this if you've played Reversi before)

enter image description here

(images from http://www.coolmath-games.com/0-reversi)

Reversi is a two player game with a simple goal - own the most pieces on the board.


  • \$\begingroup\$ You will need a complete set of rules, and some high-level description of the controller (as well as a detailed spec when it's written), and you'll need to work out some victory criteria. \$\endgroup\$ Jun 29, 2017 at 6:50
  • \$\begingroup\$ Yep, all that is in the works. I'll add a questions section when it is ready for review. \$\endgroup\$
    – J Atkin
    Jun 29, 2017 at 18:46
  • \$\begingroup\$ As for a longer title, you could simply do "Let's play Reversi" \$\endgroup\$
    – Shelvacu
    Jul 3, 2017 at 22:46
  • 1
    \$\begingroup\$ This is not Reversi. This is Othello. Source. In Reversi as it was originally played, the starting configuration was not predetermined, like it is in Othello. Players would take turns setting down the first four pieces in the center of the board \$\endgroup\$
    – Okx
    Jul 4, 2017 at 11:23
  • \$\begingroup\$ Thanks for the heads up! I'll keep reversi in the title, since I've always seen this game called reversi. \$\endgroup\$
    – J Atkin
    Jul 4, 2017 at 15:54
  • \$\begingroup\$ @JAtkin But it is not called Reversi. I quote: Unfortunately, because the games look similar and have similar rules, and “Othello” is a trademark and “Reversi” is not, many board game sellers, websites, software makers, etc., wanted to piggy back on the popularity of Othello by calling their game “Reversi”. Quite aggravatingly, they never use the rules of real Reversi (as far as we've ever seen). I insist that you remove all instances of Reversi from your post. \$\endgroup\$
    – Okx
    Jul 5, 2017 at 17:22
  • \$\begingroup\$ I understand fully that Reversi is not the correct name of this game. However, many people (myself included) have not heard of Othello, and only know about Reversi, even if our understanding was incorrect. I plan to keep both names. I think I'll include the article you reference, but I won't remove Reversi. This is not because I dislike being correct, it is because I believe that it brings the tangible benefit of wider recognition and perhaps higher viewership of the post. I will have a strongly defined rules section so any concern about confusion about rules can be dismissed. \$\endgroup\$
    – J Atkin
    Jul 7, 2017 at 1:11

Prime encode integers!

In this challenge, you must convert inputted natural numbers into a prime encoding.

The sequence of the primes, and 1, is a complete sequence (We're going to consider 1 an honourary prime for this challenge). What this means is that it's possible to express any positive integer as a sum of the terms of the sequence (without reusing terms). For example, the powers of two are a complete sequence, and you can encode numbers in them (this is binary).

As with binary, you use a sequence of 1s and 0s to represent which terms are used. 1011 will represent 5 + 1 + 2, or 8. 8 could also be represented as 10001, or 7+1. the place values represent primes:

... 13 11 7 5 3 2 1

continuing with all of the primes to the left

In this challenge, you must output a string of 1s and 0s, such that the place value primes sum to inputted strictly positive integer

Test cases

8 -> 10001 or 1011
2 -> 10
11 -> 1111 or 10101 or 100000 (I might have missed one of the possibilities?)
13 -> 1000000 or any other possibility

you may use any valid representation of the in

input note:

input is 1 strictly positive integer

you do not need to consider the value 0, even though it is possible to represent in this system, by just outputting zero

  • \$\begingroup\$ I'm assuming input is n>0? IO in all normal means? Is this code-golf? I'm also assuming we can return any valid combination? \$\endgroup\$ Aug 4, 2017 at 10:48
  • \$\begingroup\$ didn't it specifically say n>0? and also specifically say you can return any valid representation? \$\endgroup\$ Aug 4, 2017 at 22:49
  • \$\begingroup\$ It does specifically say "strictly positive", but a long way after it says "inputted integers". It's best to state restrictions like that as early as possible to avoid misleading or confusing readers. \$\endgroup\$ Aug 6, 2017 at 19:00

Find the longest Factor-Multiple sequence

Inspired by this riddle.

A Factor-Multiple sequence is any sequence where A[n+1] is either a multiple or factor of A[n].


Create a full program or function that, given a list (or any other accepted input) of positive integers, returns (one of the) the longest possible Factor-Multiple sequence containing those numbers. Each number can only be used once and each number in the input will be unique.


As mentioned above, input is a list of integers. If your language only supports strings, or if you like doing so, you may take input as strings instead.


You can output your sequence in any way you like as defined on meta.


Test cases

More need to be added.

Input                                                Output                 
1 2 3 5 7 11                                         2 1 3 or 3 1 2 or 11 1 7 etc.
1 2 3 4 5 6 7 8 9 10                                 5 10 1 4 8 2 6 3 9  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20   11  1  7 14  2  8 16  4 12  6 18  9  3 15  5 10 20 


  • Need to add more test-cases

  • Can't think of any relevant rules, did I miss any?

  • \$\begingroup\$ Related (same problem, different graph). \$\endgroup\$ Aug 15, 2017 at 22:28
  • \$\begingroup\$ @PeterTaylor Thanks for the link. From what I can see, that challenge has a one-directional graph, while in this challenge if a is connected to b => b connects to a. I am not sure if that changes the algorithms involved, but it would be interesting to see them golfed. \$\endgroup\$
    – JAD
    Aug 16, 2017 at 7:20
  • \$\begingroup\$ Actually the biggest difference is that the other one asks for approximate answers and this one asks for exact answers. \$\endgroup\$ Aug 16, 2017 at 7:25

I'm symmetric, not palindromic!


Inspired by I'm a palindrome. Are you?, where it is presented the shocking fact that “()() is not a palindrome, but ())(”, I asked myself what instead is ()() and the answer is simply: it is a string with a vertical symmetry axis!

The task

Write a program or function that takes a string S (or the appropriate equivalent in your language) as input, checks for symmetry along the vertical axis, and returns a truthy or falsy value accordingly. You can use any reasonable means to take the input and provide the output.

Reflectional symmetry

Reflectional symmetry around a vertical axis (or left-right symmetry) means that if you put a mirror vertically at the exact center of the string, the reflected image of the first half of the string is identical to the second half of the string.

For example, the following strings are reflectional symmetric around a vertical axis:

[A + A]

while the following are not:

WOW ! wow

Rules of the contest

• Your program or function will receive only printable ASCII characters. You can include or not the empty string, (which is symmetric, of course!) as legal input, which is better for you.

• The ASCII characters that can be considered symmetric with respect to the vertical axes are the following (note the initial space, and the difference between uppercase and lowercase letters):


The ASCII characters that can be considered “mirrored” and their corresponding characters are:


Note that, since they are mirrored, you can have both () as well as )(, /\ and \/, etc.

All the other ASCII printable characters must be considered asymmetric and without a mirrored corresponding character.

• This is a challenge: the shorter your program is, measured in bytes, the better, in any programming language.

• Kudos to people that will produce a symmetric program!

  • \$\begingroup\$ You seem to be missing two pairs of mirror-able characters: qpdb. Also, I'm not sure about the mixed-win criteria: "this is code-golf ...but I will mark as accepted the shortest symmetric program, if there will be at least one!", I'd go for "imaginary brownies" or just "kudos" (let the upvotes or bounties reward). \$\endgroup\$ Sep 6, 2017 at 9:54
  • \$\begingroup\$ Thanks a lot, @JonathanAllan, I will correct the text about mirrored characters, and the criteria for winning. \$\endgroup\$
    – Renzo
    Sep 6, 2017 at 9:57
  • 2
    \$\begingroup\$ This question is very confusing, because the string it gives as an example of vertical symmetry is actually vertically symmetric, but the definition it gives of vertical symmetry is actually the definition of horizontal symmetry. \$\endgroup\$ Sep 6, 2017 at 11:10
  • \$\begingroup\$ @PeterTaylor, my definition is in accord with wikipedia: “If the letter T is reflected along a vertical axis, it appears the same. This is sometimes called vertical symmetry.” I said that one should put “a mirror vertically”. If you think it is ambiguous, however, I will change “vertically symmetric” with “has a vertical symmetry axis” or “has a left-right symmetry”. Or I could add a picture. \$\endgroup\$
    – Renzo
    Sep 6, 2017 at 11:51
  • \$\begingroup\$ The very next sentence in the Wikipedia article you quote says that this is an ambiguous phrasing and best avoided. I must say that I didn't know it was ambiguous: this is the first time I've seen anyone say that an object with a vertical axis of symmetry has vertical symmetry, and I have understood since I was a small child that an object with a vertical axis of symmetry has horizontal symmetry (and so, presumably, has the person who upvoted my comment). Since questions on PPCG should be unambiguous, I can only advise a rewrite which explicitly uses the word "axis" everywhere. \$\endgroup\$ Sep 6, 2017 at 12:00
  • \$\begingroup\$ @PeterTaylor, ok, thank you very much for your comment, I will change the question. Do you think I should change also the title? \$\endgroup\$
    – Renzo
    Sep 6, 2017 at 12:14
  • \$\begingroup\$ Yes, but in the title it would suffice to say "symmetric". Which symmetry is a detail which can be left for the body. \$\endgroup\$ Sep 6, 2017 at 12:36
  • \$\begingroup\$ @geokavel, thanks, I corrected it. \$\endgroup\$
    – Renzo
    Sep 6, 2017 at 15:06

Simulate Alpha Decay

  • \$\begingroup\$ Is output to stderr ignored? \$\endgroup\$ Sep 23, 2017 at 21:33
  • \$\begingroup\$ @JonathanFrech Most likely yes, since this is allowed by default. \$\endgroup\$ Sep 23, 2017 at 22:34

Zoom box drawing characters

Here are some sample box drawing characters:

╶┤ ├╴

How do we zoom them? Well, we need to triple their size. The result looks like this:

   ┃     ┃
   ┃     ┃
╺━━┫     ┣━━╸
   ┃     ┃
   ┃     ┃

As you can see, what happens is this:

  • Each box drawing character is replaced by its heavy version (for extra thickness)
  • The box drawing characters are extended using the heavy horizontal and heavy vertical characters, resulting in a separation of three between the original characters

You can use any reasonable character I/O format. You will only need to support spaces and the 15 basic box drawing characters, plus newlines if you need them as line separators. You can only require rectangular input, but your output may contain arbitrary whitespace padding, except on the left, so that the characters in the zoomed image are aligned.

This is , so the shortest solution in bytes that violates no standard loopholes wins, but if you're using UTF-8 encoding then you can score all box drawing characters as 1 each.

  • 3
    \$\begingroup\$ RIP Charcoal, it doesn't use UTF-8 :P \$\endgroup\$
    – ASCII-only
    Oct 6, 2017 at 11:58

Does it have a square? (simple version)

Given a matrix of 0s and 1s, determine if there are 4 points that are 1 and are the corners of a square.

Here's an example to clarify, with a possible square (in bold):

0 0 0 0 0 0 0 1
0 0 0 1 0 1 0 0
0 0 0 0 1 1 0 0
0 0 0 1 0 1 0 0
1 0 0 0 0 0 0 1
0 1 1 0 0 1 1 1
1 1 1 1 1 0 0 1
0 1 0 0 1 0 1 1
1 1 1 1 0 0 1 0
1 0 0 1 0 1 0 1
0 0 1 0 1 0 1 1
1 0 0 1 1 0 1 1
Another possible square is the following:

0 0 0 0 0 0 0 1
0 0 0 1 0 1 0 0
0 0 0 0 1 1 0 0
0 0 0 1 0 1 0 0
1 0 0 0 0 0 0 1
0 1 1 0 0 1 1 1
1 1 1 1 1 0 0 1
0 1 0 0 1 0 1 1
1 1 1 1 0 0 1 0
1 0 0 1 0 1 0 1
0 0 1 0 1 0 1 1
1 0 0 1 1 0 1 1

There are many squares in this matrix, but the point isn't to count the squares, just to determine if there's a square in it. Since there is a square in it, your solution, given this matrix, must return a truthy value.

Given this matrix, your solution must return a falsy value:

0 0 0 0 0 0
0 1 1 0 0 1
0 1 0 0 1 1
0 1 1 0 1 0
You can see there's no square in there.


  • Since the input is a matrix, it will always be rectangular.
  • Probably needless to say, the sides of a square must be equal.
  • The corners of a square must all be 1.
  • A square must have at least side length 2 to be considered a square, otherwise this challenge would be extremely trivial.
  • Standard Loopholes, as usual, are forbidden.

Test cases

This section is under construction.

  • \$\begingroup\$ Related. \$\endgroup\$ Oct 27, 2017 at 22:52
  • \$\begingroup\$ Is a 2x2 square a square? \$\endgroup\$ Oct 27, 2017 at 23:22
  • \$\begingroup\$ @MagicOctopusUrn A square must have at least side length 2 to be considered a square \$\endgroup\$ Oct 28, 2017 at 9:34
  • \$\begingroup\$ Can one's solution require that the matrix' dimensions are given? If so, can the input be a single list instead of a nested one? \$\endgroup\$ Oct 28, 2017 at 20:42
  • \$\begingroup\$ @Jonathan Relevant but not necessarily answering your question. \$\endgroup\$ Oct 28, 2017 at 22:06
  • \$\begingroup\$ @JonathanFrech Does your language really not support nested arrays (like e.g. Neim)? Otherwise I don't see why... \$\endgroup\$ Oct 28, 2017 at 22:08
  • \$\begingroup\$ @EriktheOutgolfer I was thinking of languages like C, where I find it simply nicer to only have to deal with one list, even though the language can handle nested lists. I just wanted to ask about, not necessarily influence, the validity of a solution taking a flat list. \$\endgroup\$ Oct 28, 2017 at 22:27

LaTeX truth tables

Write a program or a function that accepts the list of outputs from a logic function and outputs the LaTeX code for its truth table.

The inputs should be labeled as lowercase letters a-z, and the output should be labelled as F. The length of list of inputs will always be shorter than 2^25, which means that number of inputs will always be less than 25, so you can use letters from lowercase alphabet for input names.


A number n of inputs and list of length 2^n of binary numbers which represents the outputs of a logical function.


LaTeX code that produces the truth table for that function. Input and output values should be centered in rows. There must be a line between table header and its values and between inputs and output, so the code should be similar to that below.

\begin{tabular}{c * <NUMBER OF INPUTS>|c}



[0, 0, 0, 1]


a & b & F \\
0 & 0 & 0 \\
0 & 1 & 0 \\
1 & 0 & 0 \\
1 & 1 & 1 \\

Which when displayed in LaTeX shows the following truth table

Truth table

General rules

  • \$\begingroup\$ What happens if there are >25 outputs? Do we label them abcdef...uvwxz? Also, just to be clear, can we assume that there will be at most 25 variables present? Also, what is the winning criterion? (I recommend code-golf for this challenge). \$\endgroup\$
    – hyper-neutrino Mod
    Oct 31, 2017 at 20:09
  • \$\begingroup\$ There are not going to be > 25 input variables. I was thinking of shortest code so yeah, code-golf :) \$\endgroup\$
    – drobilc
    Oct 31, 2017 at 20:11
  • \$\begingroup\$ Okay. For the >25 variables part you might want to specify it, and you should add a note saying what the winning criterion is, and you might also want to consider what tags to use (probably just code-golf and maybe math, really). Once you add that ping me and I'd be happy to check it over :) \$\endgroup\$
    – hyper-neutrino Mod
    Oct 31, 2017 at 20:16
  • 1
    \$\begingroup\$ "The inputs should be labeled as lowercase letters a-z, and the output should be labelled as y." It isn't really clear from this whether 'y' can also be part of the inputs or not (I guess not). Another thing that came to my mind is that you could give the possibility of taking 'n' as an input in addition to the list of '2^n' values, since that could remove some annoying boilerplate from some answers and this challenge seems more about generating a structured output than computing the base-2 logarithm of a number. \$\endgroup\$
    – Leo
    Nov 1, 2017 at 0:17
  • \$\begingroup\$ I agree, should I label the output name to something else? Like uppercase F or something like that? I'll add number of inputs as an input. \$\endgroup\$
    – drobilc
    Nov 1, 2017 at 8:03

Insert Random Squares Here

Related challenges.

< Insert sales pitch here >

The Challenge

Given a width and a height, output an image filled with random squares.


Your program/function is given a width and a height in pixels.


yourProgram <width> <height>


You must display the result on the screen, or output an image file in any acceptable format.


  • The number of squares to be generated is a random natural number between sqrt(w * h) / 2 and sqrt(w * h) * 2 (inclusive).
  • Each square's color will be randomly generated for each with R, G, B ranging from 0-255 and with alpha values ranging from 1-255.
  • Each square's width/height will be a random value between 1 and min(w, h) (inclusive)
  • Each square must be placed randomly. Part of the square may be outside the output image, as long as at least one pixel of the square is visible.
    • Placement at sub-pixel coordinates (e.g. x=0.239420, y=2.8298329) is allowed but not required.
  • Each possible output must be equally likely to occur.
  • The output must have a white or transparent background.


Input and randomly generated parameters

Width: 10
Height: 20

Maximum square height: 10

Minimum number of squares: 8 Math.sqrt(10*20)/2 = 7.0710678118654755
Maximum number of squares: 28 Math.sqrt(10*20)*2 = 28.284271247461902

Number of squares  in this example: 8


Scaled 2000%:

Output with the parts of the squares that are off-screen

(Scaled 2000%.) The gray part is the part that is displayed on the screen.

  • \$\begingroup\$ does the background have to be transparent, or can it be a constant color? \$\endgroup\$
    – dzaima
    Nov 22, 2017 at 15:01
  • \$\begingroup\$ @dzaima I guess the "transparent" doesn't make sense if there is nothing behind the background. A better question is: Must the background be white? \$\endgroup\$
    Nov 23, 2017 at 13:10
  • \$\begingroup\$ @AdmBorkBork That's kind of what I meant to say with "Each possible output must be equally likely to occur". Think it needs clarification? \$\endgroup\$ Nov 23, 2017 at 13:44
  • \$\begingroup\$ @dzaima Clarified \$\endgroup\$ Nov 23, 2017 at 13:46
  • \$\begingroup\$ @user202729 Updated the rules to say the output must have a white or transparent background \$\endgroup\$ Nov 23, 2017 at 13:47
  • 1
    \$\begingroup\$ Ah, I had understood the "each possible output equally likely" to mean the positioning of the squares themselves, rather than a comment on the entirety of the random possibilities. Maybe just expanding that bullet point to read something like "The squares' number, color, size, and position must all be equally likely to occur" or similar wording. \$\endgroup\$ Nov 27, 2017 at 13:39

A Fine-Grained Mesh

If you've used Matlab before, it's highly likely that you've heard of meshgrid. It's a function that has since mostly been obsoleted by broadcasting, but it still has its uses sometimes.

The function itself is relatively simple. Given two vectors x and y of length m and n, create two 2-dimensional matrices X and Y both with m columns and n rows such that:

  1. Any row of X is a copy of x
  2. Any column of Y is a copy of y

But typing out meshgrid(x,y) takes so long, you know? I'd like to be more efficient with my coding. Your job is to reimplement this function in the fewest bytes possible.

Standard loopholes disallowed.

  • 2
    \$\begingroup\$ This is a classical case of do X without Y which is discouraged. The reason is that some languages might have something similar that is not quite equal, and then it is always the question: Where do you draw the line? I recommend against banning built ins. \$\endgroup\$
    – flawr
    Dec 10, 2017 at 19:46
  • \$\begingroup\$ @flawr I removed that as a requirement. \$\endgroup\$
    – Steven H.
    Dec 11, 2017 at 19:58
  • 1
    \$\begingroup\$ You could add "builtins that compute this are allowed but a second implementation without using that builtin are strongly encouraged" \$\endgroup\$
    – Giuseppe
    Dec 11, 2017 at 20:34
  • \$\begingroup\$ what types are x and y? Int, float, char, ...? \$\endgroup\$
    – Giuseppe
    Dec 11, 2017 at 20:36
  • \$\begingroup\$ x and y can be any vector-like type. Lists, arrays, actual vectors... \$\endgroup\$
    – Steven H.
    Dec 12, 2017 at 2:30

Flit - a simple board game for bots

I've made a human playable version of this game with a simple strategy to give an idea of how the game plays out. You can play it before or after reading the rules here - picking up the rules intuitively adds an extra challenge...

If playing this gives any idea about whether the KotH version would be better with 2, 4, or more players per game, or any other subtle adjustments that would help, please let me know.

Note: adjacency is vertical or horizontal - for this game there are no diagonal neighbours.


The board is a square grid. Each bot starts with 2 pieces of their colour, and gains more pieces by converting neutral pieces that appear from time to time. The objective is to end up with more pieces than your opponents.

Each turn, one bot moves. It chooses one of its pieces and moves it to be next to another of its pieces. There is no limit to the distance a piece can move in a single step, provided it lands next to a piece of the same colour.

Neutral pieces

There are initially zero neutral pieces.

A new neutral piece can appear at any time, regardless of whether there are already neutral pieces unconverted. A neutral piece will only appear on an empty square that has 4 empty neighbours, to prevent it being instantly converted.

If a neutral piece is adjacent to another piece, it is converted - it becomes the colour of that piece. A neutral piece can only ever be adjacent to a single other piece - it will be instantly converted before any other bot has a chance to move next to it.


A move is specified by an origin square and a destination square. It is a valid move if the origin square contains a piece of the bot's colour, and the destination square is empty and is adjacent to at least one piece of the bot's colour. Note that the piece being moved cannot also be the piece adjacent to the destination square (a piece cannot simply move next to its own previous position). Two distinct pieces are required - one to be moved, and one to be adjacent to the destination.

[Not moving is a valid move, and is indicated by specifying the same coordinates for origin square and destination square. not sure about this rule] Not supplying a move within the time limit also results in not moving, but repeatedly exceeding the time limit will lead to the bot losing the opportunity to make further moves.


The board information will not be supplied each turn. Instead the bot must keep track of the board state itself. Each time a change is made a message will be sent to all bots describing the change. If a bot chooses not to move, the non-move will not be broadcast.

The board starts empty. The initial two pieces for each bot will be broadcast to all bots, then the first bot will be sent a request for a move, to which it must respond within the time limit. Any response sent after the time limit expires will be discarded (any waiting input will be read and discarded before the next request for a move is sent to that bot).

Bots will therefore have complete information about the board state at all times.


Available: An available square is an empty square that has 4 empty neighbours


There are 4 bots competing in each game. Bots are numbered 1 to 4 and take turns in that fixed order.


The board is a 32 by 32 square grid. It wraps toroidally - every square has 4 neighbours. The board has no boundaries - no edges or corners to give an advantage.

Initial state

For each bot, one piece will be placed on a square chosen uniformly from the available squares. After all first pieces have been placed, a second piece will be placed for each bot in the same way. The initial state contains no neutral pieces.

Addition of neutral pieces

Each turn one bot will move. After that move has been made, the addition of a new neutral piece will be considered. A square will be selected at random. If that square is available then a neutral piece will be placed on it with probability 1/16. If the square is unavailable then play continues - a second square will not be selected. [This differs from the human playable version linked above: there a list is kept of all available squares and a neutral piece is placed on one of those with probability 1/6 each turn - I now prefer this approach so the rate of new neutral pieces does not slow in the end game]


All received messages will be terminated by a newline. Each bot will receive messages of two types: an update or a move request


x y c

where (x, y) is the square to be updated, and c is the new colour (which may be 0 for empty, 1, 2, 3 or 4 for a bot colour, or 5 for neutral).

Move request:


where M is the literal string "M" and indicates that a move is required.


The response must be terminated by a newline. A bot responds with a move in the following format:

x0 y0 x1 y1

where (x0, y0) is the origin square, and (x1, y1) is the destination square.

If origin and destination are identical, no move will be made. This is valid and does not lead to the bot being penalised. The bot will only be penalised if it fails to respond within the time limit.

Time limit

The time limit is 50ms. If a bot exceeds the time limit on 5 consecutive turns then it will no longer be prompted for moves. That bot will be frozen for the rest of the game.

Winning criterion

The winner is the bot with the most pieces when the game ends. There is no reward for second place. If two bots tie for first place, neither is rewarded.

The game ends when one of the following conditions is met:

  • the total number of turns taken exceeds 32,768 (8,192 per bot)
  • all 4 bots choose not to move consecutively
  • one bot has too many pieces to catch up with

Too many pieces to catch up with is defined as follows:

  • A, B and C are the numbers of pieces of the other 3 bots.
  • D is the number of pieces of the bot in question.
  • N is the number of neutral pieces.
  • E is the number of empty squares.
  • P is the number of potential neutral pieces. P = N + E - 4
  • M is the maximum number of pieces attainable by A, B or C.
  • M = Max(A+P, B+P, C+P)
  • If D > M then the bot has too many pieces to catch up with.

I've tried to make this game as simple as possible, while still having non-trivial dynamics.

  • 1
    \$\begingroup\$ Time limit could be abused - the bot is allowed to just take its sweet time for 4 turns straight, followed by a reset... How about average time? \$\endgroup\$
    – Alion
    Feb 18, 2018 at 12:40
  • \$\begingroup\$ Ah good point. I'll probably go with average time per move after an arbitrary 10 seconds to allow for high variance early on. \$\endgroup\$
    – trichoplax
    Feb 18, 2018 at 12:57
  • 1
    \$\begingroup\$ First player is at a very slight, systemic disadvantage. He's the only one that cannot see a neutral piece on his first turn. Piece spawning should probably happen before each player makes a move, instead of after. \$\endgroup\$
    – Alion
    Feb 20, 2018 at 14:58
  • \$\begingroup\$ Oh good point. That small difference is definitely relevant. Neutral pieces before rather than after a move sounds good. \$\endgroup\$
    – trichoplax
    Feb 20, 2018 at 17:18

Musical Washing Machine

I have a washing machine with a knob and several buttons. The knob selects the type of laundry and the buttons cycle through water temperature, etc. options. When pressed, these each create a musical note. There are five musical notes that can be made, in this ascending order: F A C D E

knob (K)
   When 360ed: play D and reset all other buttons
wash temp (T)
   1st press (cool -> warm): A
   2nd press (warm -> hot): F
   3rd press (hot -> cold): E
   4th press (cold -> cool): C
spin speed (S)
   1st press (medium -> max extract): F
   2nd press (max extract -> no spin): E
   3rd press (no spin -> medium): A
soil level (L)
   1st press (medium -> heavy): A
   2nd press (heavy -> extra heavy): F
   3rd press (extra heavy -> light): E
   4th press (light -> medium): C

The Challenge

Given a series of notes, determine if if can be played on my washing machine, and, if so, output the series of moves to generate it.

I/O coming soon to a washing machine near you

  • \$\begingroup\$ As a side note, there is a washing machine that plays the New Zealand Athem \$\endgroup\$
    – MickyT
    Aug 27, 2015 at 21:02
  • \$\begingroup\$ I think I understand, but it looks a bit confusing. Maybe you should give an example with an explanation. \$\endgroup\$
    – Beefster
    Feb 9, 2018 at 17:18

Make a Sierpinski triangle

Your challenge is to output a n-th order right-angle Sierpinski triangle, similar to this (third-order):

# #
#   #
# # # #
#       #
# #     # #
#   #   #   #
# # # # # # # #


A number, n, and a character (in this example '#');


A 2**n (two to the n) line Sierpinski triangle, made of the given character. You could consider it a two-state cellular automaton: the cells are separated by a single spaaace; if it is on, it contains the given character; Otherwise is contains a spaaace.



0 *






1 *


* *


2 *


* *
*   *
* * * *


this is codegolf so the winner is the answer with the least bytes. (NOTE: might add something tho do with triangles of the same character.)


it might be helpful to know that the n-th line contains the previous line xor that line shifted right by one cell (x^(x>>1)).

  • \$\begingroup\$ Welcome to PPCG and thanks for using the sandbox! There is a challenge to draw an Sierpinski Triangle which is broad enough to allow your format, so the challenge might be considered a duplicate. Then again I think the old challenge is no longer up to the current site standards and should probably be closed ... \$\endgroup\$
    – Laikoni
    Mar 10, 2018 at 10:08
  • 1
    \$\begingroup\$ This is also close enough to Generate Pascal's triangle that by the standards of this site (can answers be copied with trivial modifications?) I would consider it a duplicate. \$\endgroup\$ Mar 10, 2018 at 19:42

-(-(--x)--))> Code Kebabs! <-(-(--x)--))

Your goal is to parse Code Kebabs, they look like this:

-x--> 8
2 <-(-(--x)--))
-x-x-x--> -10
--x> 255

A Code Kebab is made up of 3 parts, the stick, the tip (< and >), and the stand (the number compared by)

stick tip stand 
--x-- >   -5

The stick

The stick contains 4 operators, and the variable (x) The operators are listed here, in order of precedence:

  1. ( ... ) | Brackets. They are the "veggies" on a code kebab. Everything inside them runs before the rest of the kebab, with the last, deepest pair going first. Brackets can be nested.

  2. v-- | Suffix decrementation. This is one of the 4 parts of the stick, and decrements the value supplied to it by one.

  3. v-v | Subtraction. This is the 2nd part of the stick, and subtracts the two values.

  4. --x | Prefix decrementation. This is the 3rd part of the stick, and decrements the value supplied to it by one.

  5. -v | Negation. This is the 4th and final part of the stick, and inverts the value supplied.

Each operator returns it's result, and can be used as input for other operators.

The Tip

The tip is one of two symbols: < or > When the tip is <, the stand must be left of it, with the tip being left of the stick. When it is >, the stand is to it's right, with the tip being on the right of the stick.

The Stand

The stand is any integer. That's all there really is to say about it.

Execution of the kebab

You can't execute a kebab without eating it!

Kebabs are executed in a loop until their condition (The result of the stick being less than the stand's value) is fulfilled. When execution is finished, the variable (x) is set to the result of the stick, X is printed, and execution resumes again unless the condition is fulfilled.

When execution starts for the first time, X is set to 10 beforehand.


  • Add test cases.

  • Clear a few things up.

  • Make the description of execution a bit clearer?

  • 1
    \$\begingroup\$ You should describe the difference between pre and post decrement. \$\endgroup\$
    – Pavel
    Apr 30, 2018 at 21:22
  • \$\begingroup\$ Also, how are the input variables initialized? \$\endgroup\$
    – Pavel
    Apr 30, 2018 at 21:22
  • \$\begingroup\$ A test case that has something like -x--5 to force parsing it as a subtraction and unary negation, rather than post-decrement x, would be very good. \$\endgroup\$ May 1, 2018 at 13:02
  • \$\begingroup\$ @AdmBorkBork Numbers aren't mentioned as a requirement for parsing, so -x--x would probably work better. But yea, good idea. \$\endgroup\$ May 1, 2018 at 13:48
  • \$\begingroup\$ @Pavel The input variable X is set to 10 beforehand, as mentioned in The execution of the kebab \$\endgroup\$ May 1, 2018 at 13:51
  • \$\begingroup\$ Is this correct? And if not, where is my flaw? The input is the Code Kebab (i.e. -x--> 8) with x=10 by default, and the output is the x once it fulfills the Kebab check. So for -x--> 8 with x=10 as start, it will do x-- first (so it becomes x=9), and then the -x negation (so it becomes x=-9), and then checks it with the tip (-9 > 8). This is false, so it continues with x now being -9? So then x-- again (x=-10), then -x again (x=10), and then the check again (10 > 8). Which is true, so it outputs 10 as result? I have the feeling I misunderstand it a bit.. \$\endgroup\$ May 2, 2018 at 11:08
  • \$\begingroup\$ Also, why is suffix decrementation before prefix? In most languages (Java, JS, C, etc.) it's usually the other way around. \$\endgroup\$ May 2, 2018 at 11:10
  • \$\begingroup\$ And one more question, is something like ---x (negation & prefix decrementation), or x---x (suffix decrementation & subtraction) a possible valid input? Or would these always be surrounded by parenthesis (---x would be -(--x) instead; x---x would be (x--)-x or x-(--x) instead). \$\endgroup\$ May 2, 2018 at 11:14

Nearest neighbors in a square lattice


Consider an infinite 2D square lattice. We can choose one point as the origin and label each point with a pair of integers that corresponds to points on the Euclidean plane:

enter image description here

Now consider the point at the origin, \$(0,0)\$. The set of lattice points closes to the origin (but not including the origin) is \$\{(1,0),(0,1),(-1,0),(0,-1)\}\$. We will call this set the \$1\$st nearest neighbors. The set of lattice points closest to the origin but not including the \$1\$st nearest neighbors is \$\{(1,1),(-1,1),(-1,-1),(1,-1)\}\$. We call this set the \$2\$nd nearest neighbors

Now we can define the \$k\$-th nearest neighbors as the set of points closest to the origin and not included in the union of the set of \$n\$-th nearest neighbors for \$n\in\{1,2,...k-1\}\$.

Define the sequence \$NN(k)\$ as the length of the set of \$k\$-th nearest neighbors.


Given \$k\$, compute \$NN(k)\$. This is A105352 on OEIS without the first element.


  • You may use 0- or 1- based indexing.
  • Given \$k\$, you may either output the first \$k\$ elements of the sequence or the \$k\$-th element.
  • You may alternatively take no input and output the sequence indefinitely.
  • Standard loopholes disallowed.

Here are some 1-indexed test cases:

n   NN(k)
1   4
8   8
9   4
10  8
38  16
52  8
80  8
121 24
145 12
  • \$\begingroup\$ OEIS A105352. \$\endgroup\$
    – Mr. Xcoder
    Sep 13, 2018 at 20:47
  • \$\begingroup\$ @Mr.Xcoder Thanks \$\endgroup\$
    – dylnan
    Sep 13, 2018 at 20:58
  • \$\begingroup\$ Could you allow the infinite sequence \$\{NN(1),NN(2),NN(3),\ldots\}\$ as output (with no input)? \$\endgroup\$
    – Delfad0r
    Sep 15, 2018 at 8:34
  • \$\begingroup\$ @Delfad0r Sure. \$\endgroup\$
    – dylnan
    Sep 15, 2018 at 16:33
  • 1
    \$\begingroup\$ Very related. Just filter out zeroes. \$\endgroup\$
    Sep 15, 2018 at 16:38
  • \$\begingroup\$ @user202729 Do you think it's a dupe? \$\endgroup\$
    – dylnan
    Sep 15, 2018 at 17:06
  • \$\begingroup\$ @dylnan I don't know... \$\endgroup\$
    Sep 17, 2018 at 13:08
  • \$\begingroup\$ IMO it's a dupe: adding a loop and an if test is a pretty trivial modification. \$\endgroup\$ Sep 17, 2018 at 14:34

Breaking into 3 Palindromes:

As discussed here and here, every positive integer can be written as the sum of 3 palindrome integers. Given a number "n", output these integers.


  • This is a code golf challenge. The shortest functional solution wins.
  • The input number "n" will be any integer greater than 0 but less than 1,000,000,000.
  • The three output numbers must be palindromes. Their sum must be "n".
  • A palindrome number is a number which is the same forwards as backwards. It can have any number of digits.
  • To make this easier, I will allow positive or negative palindrome integers.
  • Output and input can be formatted in any what that is convenient as long as it can be readily understood.


input: 5
output: 0,0,5

input: 1234
output: 1001,222,11

input: 3141592
output: 2200022,926629,14941
  • 2
    \$\begingroup\$ This is actually a very interesting problem. The paper which proved that this would work for any base lists 40 different algorithms that are used to find these values depending on the value of "n". I suppose there should be a requirement to solve this in a reasonable about of time to avoid brute force but I don't know how I should phrase that. \$\endgroup\$
    – kaine
    Sep 17, 2018 at 21:18
  • \$\begingroup\$ It's up to you, but time limit requires a particular computer to test the solutions on. \$\endgroup\$
    Sep 18, 2018 at 1:18
  • \$\begingroup\$ Maybe it would be a good idea to link that paper in the challenge. Also, I tried to bruteforce in 05AB1E, and the 1234 case already times out after 60 sec, so I won't even have to try 3141592.. It barely doesn't make it within the 60 sec, but does output most of the possible outputs. Maybe make this a [fastest-code] challenge instead of code-golf, so the goal is to solve it as fast as possible. Alternatively [fastest-algorithm] could be used as well, but usually when someone find one, others will copy it. \$\endgroup\$ Sep 18, 2018 at 6:41
  • 1
    \$\begingroup\$ Honestly, i don't think i am comfortable managing a fastest-algorithm challenge due to my own limited skill. I'm a pretty amateur programmer so if someone uses languages, libraries, etc. I'm unfamiliar with I won't be able to fairly judge them. This idea though (complicated but sounds simple) seems great for one of these challenges. \$\endgroup\$
    – kaine
    Sep 18, 2018 at 13:04
  • 1
    \$\begingroup\$ Would it be feasible to require the code to run within 20 minutes on Ideone? Is that linked to my computer's abilities? \$\endgroup\$
    – kaine
    Sep 20, 2018 at 13:39
  • \$\begingroup\$ I think if you keep this at base 10 (decimal only) it's not so bad. \$\endgroup\$
    – ouflak
    Sep 21, 2018 at 12:59
  • \$\begingroup\$ @ouflak I had no intention of leaving base 10. I'm really liking the Ideone idea but am not sure if people would be ok with that. \$\endgroup\$
    – kaine
    Sep 21, 2018 at 18:51
  • 1
    \$\begingroup\$ rnta.eu/cgi-bin/three_palindromes/pal3.py and somethingorotherwhatever.com/sum-of-3-palindromes The speeds for these are bad at all. One in python the other in Javascript. I'm doing a C++ version (completely ungolfed) as I'm at a bit of a lull at the moment. It's just a translation of the Javascript code with some tweaks. I'll post a link to that as well. I would forget the timings and go with the straight up challenge. \$\endgroup\$
    – ouflak
    Sep 26, 2018 at 9:22
  • 1
    \$\begingroup\$ I've done this up in non-golfed C++. Anybody know a site where I can put this online where people can run it? It's big, but fast. \$\endgroup\$
    – ouflak
    Oct 3, 2018 at 15:24
  • 1
    \$\begingroup\$ The non-golfed C++ is 36 kbytes. Maybe limiting this to just the 4 digit case might be OK. I might try that in LUA and see what it looks like. This is such a great idea. Unfortunate that the algorithms are so lengthy. \$\endgroup\$
    – ouflak
    Oct 8, 2018 at 13:56
  • \$\begingroup\$ @ouflak, the fact that the algorithms are lengthy is why I thought this would make a good challenge. It is ripe for optimization. I'm worried about posting this challenge though as I'm sure there are many algorithms that will give an answer eventually but are so slow they defeat the purpose of the challenge. \$\endgroup\$
    – kaine
    Oct 8, 2018 at 14:29
  • \$\begingroup\$ Ok, I've sorted out a much shorter algorithm in LUA for the three digit case, un-golfed. repl.it/repls/AchingEnchantedHack. This has given me an idea for how to sort out the general case, which I think now actually might not be so bad. \$\endgroup\$
    – ouflak
    Oct 9, 2018 at 7:43
  • \$\begingroup\$ Here is a solution that should work for any sized number. This is brutally un-golfed LUA. I haven't even taken the opportunity to use a recursive function where it obviously would apply. For 5 digit numbers and smaller, it's pretty quick, easily less than a second. For 6 digit numbers and above, it depends on how soon it finds the first set of palindromes. I had one number (390081) take a good five minutes on the test site. I'm sure it would be quicker on my machine. I'd like to think there are places for optimization for speed (as well as golfing). repl.it/repls/BlondWaryShareware \$\endgroup\$
    – ouflak
    Oct 9, 2018 at 11:59
  • \$\begingroup\$ Just one other comment on your constraints, I wouldn't allow negative palindromes as I'm not convinced this makes it 'easier'. Should I start golfing this thing? ;) \$\endgroup\$
    – ouflak
    Oct 9, 2018 at 12:10
  • \$\begingroup\$ @ouflak you can probably wait until i post it as a real question but your enthusiasm definitely implies I need to. \$\endgroup\$
    – kaine
    Oct 9, 2018 at 12:50

Classical construction golf: Wernick's list No. 47


Compass-and-straightedge construction, a.k.a. classical construction, is the construction of lengths, angles, and other geometric figures using only an idealized ruler and compass. A ruler can only be used to draw a straight line passing through two given points; a compass can only be used to draw a circle with two given points (a center, and a point on the circle).

All compass and straightedge constructions consist of repeated application of five basic constructions using the points, lines and circles that have already been constructed. These are:

  • Creating the line through two existing points
  • Creating the circle through one point, with another point as the center
  • Creating the point which is the intersection of two existing, non-parallel lines
  • Creating the one or two points in the intersection of a line and a circle (if they intersect)
  • Creating the one or two points in the intersection of two circles (if they intersect).

Five basic constructions

In addition to these listed on Wikipedia, we have the sixth basic construction:

  • Creating an arbitrary point on the plane, possibly with a constraint:
    • On a line ("line" includes straight lines and circles)
    • Not on a line
    • On a closed or open part of a line, bounded by existing points on it
    • Inside a closed or open region, bounded by existing lines

In any geometric problem, we have an initial set of symbols (points and lines), an algorithm, and some results. From this perspective, geometry is equivalent to an axiomatic algebra, replacing its elements by symbols.

This is the basis of the new kind of : classical construction golf.


Wernick's list is a collection of construction problems. The common objective is to recover the three vertices of a triangle, given three of its 16 characteristic points. They include:

  • \$A, B, C, O\$: three vertices and circumcenter,
  • \$M_a, M_b, M_c, G\$: the side midpoints and centroid,
  • \$H_a, H_b, H_c, H\$: three feet of altitudes and orthocenter,
  • \$T_a, T_b, T_c, I\$: three feet of internal angle bisectors and incenter.

Out of the 139 problems, some are solvable by construction, but some are not. The problem we'll tackle here is problem 47, where the given points are:

  • \$A\$: a vertex.
  • \$H_a\$: the foot of the altitude on side \$a\$; that is, the opposite side of the vertex \$A\$.
  • \$T_b\$: the foot of the bisector of angle \$B\$.

Given these three points, recover the other vertices \$B\$ and \$C\$.

enter image description here

Scoring & Winning criterion

Every usage of the six basic constructions (shown above) counts. For the line intersections, creating each point adds 1 score, e.g. if you need both intersections of two circles, you get 2 score from the step.

The solution with the lowest score wins.

Scoring example

Task: Construct the midpoint of two points \$A\$ and \$B\$.


  • Draw circle \$C_1\$ with center \$A\$ going through \$B\$. (+1)
  • Draw circle \$C_2\$ with center \$B\$ going through \$A\$. (+1)
  • Draw two intersections \$X, Y\$ of two circles \$C_1\$ and \$C_2\$. (+2)
  • Draw line \$f\$ going through the two intersections. (+1)
  • Draw line \$g\$ going through the two given points. (+1)
  • Draw the intersection \$M\$ of \$f\$ and \$g\$. (+1)

The score of this construction is 7.

Example task


GeoGebra is a free online geometry tool. In addition to basic and advanced constructions, it has construction protocol feature which clearly shows the steps used to create the final image. For the above example task, the construction protocol looks like this:

Example construction protocol

Out of 9 steps in total, the points \$A\$ and \$B\$ are given, so we can confirm that seven steps are taken for this particular construction.

It also supports scripting (in GGBScript and JS) for those who want to view this challenge as or . Among many geometry commands, the Prove and ProveDetails commands may help you identify if a particular construction is indeed correct.


I'm using a relatively easy problem here, in order to see how this new challenge type is received. If it goes well, I'll propose some harder and open-ended problems later.


  • Is this actually on-topic on PPCG? I'm asking this since this is the first challenge of its kind. I'll assume on-topic unless someone says otherwise on this meta question.
  • Maybe we need to tweak the difficulty of the challenge at hand. Is it too easy or too hard? Any other suggestions? I picked Wernick's list because it's not something you may see on Euclidea or similar, and the optimal (or elegant) solutions for many of the problems are not yet known. I'll go for the task this time, and try to ramp up in subsequent challenges.
  • 2
    \$\begingroup\$ I think it would be a stretch to consider this on-topic: proofs in logic can be argued to be as good as programs by reference to the Curry-Howard correspondence, but I don't really see extending that to proofs in general. It might be more interesting to instead ask for a program which generates proofs and score by the length of the generated proofs (although since the linked paper talks about a 6000-line program to search for them, that may be outside the scope of a reasonable PPCG challenge). \$\endgroup\$ Jul 23, 2018 at 11:35
  • \$\begingroup\$ On the difficulty of the given theorem: without much effort (5 minutes maximum) I have a solution scoring 16. It's certainly much easier than the existing proof-golf questions to get an answer, although I can believe that there may still be room to golf my solution. \$\endgroup\$ Jul 23, 2018 at 11:38
  • \$\begingroup\$ (In fact I've spotted one unnecessary intersection, so 15). \$\endgroup\$ Jul 23, 2018 at 11:49
  • \$\begingroup\$ Do you think this would be better here or on Puzzling? \$\endgroup\$
    Sep 30, 2018 at 12:02

The max() is not enough

The max() is not enough

  • \$\begingroup\$ This could do with a better title, any suggestions? \$\endgroup\$ Oct 2, 2018 at 22:14
  • \$\begingroup\$ "Max is only half the story" \$\endgroup\$
    – Quintec
    Oct 3, 2018 at 2:06
  • \$\begingroup\$ What if the largest integer in the list is not unique, do we output the second largest? I.e., with the list [1,8,4,8] do we output nothing because the 8 is duplicated, or do we output 4 instead being the largest unique integer? EDIT: Scratch the italic part before. Also, I assume we can take the input in any reasonable format? As an integer list, integer-array, integer-stream, comma-separated string, newline- or space-delimited STDIN, etc? Or is it mandatory to input it in a comma-separated string format? \$\endgroup\$ Oct 3, 2018 at 8:24
  • \$\begingroup\$ Ignore the first question. Just noticed it's either nothing if all values in the list are unique, or the max otherwise (even if the largest is not unique). In that case: Can the list contain negative integers or zero? And are we allowed to output another falsey value instead of an empty output? \$\endgroup\$ Oct 3, 2018 at 8:25
  • 1
    \$\begingroup\$ Can we have more test cases with all elements equal \$\endgroup\$
    – Jo King Mod
    Oct 3, 2018 at 10:05
  • \$\begingroup\$ I have a 5-byter ready, it's a great challenge if it isn't a duplicate! \$\endgroup\$
    – maxb
    Oct 3, 2018 at 12:40
  • \$\begingroup\$ @Quintec Great suggestion to focus on "max" - definitely inspired the new title! \$\endgroup\$ Oct 4, 2018 at 13:13
  • \$\begingroup\$ @KevinCruijssen / Anyone: I think failing to follow the rules to the letter should be permissible BUT carry some level of bytes as a penalty. I'm not sure what the usual is here - how about 15 bytes each for either using some other input format and for outputting garbage instead of no output? \$\endgroup\$ Oct 4, 2018 at 13:13
  • \$\begingroup\$ @JoKing Of course, although I'm curious to know - is this somehow non-trivial to infer from the existing cases? What's the catch? :P \$\endgroup\$ Oct 4, 2018 at 13:13
  • \$\begingroup\$ @maxb This will like be up "for real" sometime tomorrow UK time. Good luck! \$\endgroup\$ Oct 4, 2018 at 13:13
  • \$\begingroup\$ Nah, but it would help people catch if their solutions are invalid. Also, I would discourage byte bonuses/penalties, and just let solutions take input how they like rather than overriding the site defaults \$\endgroup\$
    – Jo King Mod
    Oct 4, 2018 at 13:28
  • 1
    \$\begingroup\$ @ElectricWarr The default is usually to have a flexible input and output formats. But if you insist on having a string comma-separated input, then I will use a split by comma instead to make it into a list in my program itself instead of taking the 15 bytes penalty, considering my full program with list input is just 5 bytes, and changing the comma-separated string to a list is +4 bytes (way below 15 ;p). I would advice to don't use penalties or bonusses at all for challenges btw (and use flexible I/O, but the I/O choice is still up to you of course if you insist on comma-separated strings). \$\endgroup\$ Oct 4, 2018 at 13:31
  • \$\begingroup\$ Btw, about "Assume input integers may be more than one digit but no larger than 4 bytes", your last test case has 6-byte numbers? \$\endgroup\$ Oct 4, 2018 at 13:36
  • 1
    \$\begingroup\$ @KevinCruijssen I figure I'll try strict requirements this time around and if it's a problem I'll avoid them in future. On 6-byte numbers - ha! - good point, I'll reword that. Of course I should have foreseen that here of all places "bytes" is a measure of length first and as a quantity of information second! \$\endgroup\$ Oct 4, 2018 at 13:46
  • 3
    \$\begingroup\$ Polyglot, 30 bytes Takes +15 for not taking any input and +15 for not outputting anything \$\endgroup\$
    – Jo King Mod
    Oct 5, 2018 at 1:54

Formulize the sum: Faulhaber's formula

Sums of the form Σkⁿ over k in 1..x can be turned into a polynomial of x whenever n is a natural number.


Σ1 = x
Σk = (1/2)x²+(1/2)x
Σk²= (1/3)x³+(1/2)x²+(1/6)x


You will take n as a non-negative integer input and output the coefficients in reduced fraction form of the resulting polynomial from leading coefficient down to the last non-zero coefficient.

This is code-golf, shortest code wins.

Test cases

0 #=> 1
1 #=> 1/2 1/2
2 #=> 1/3 1/2 1/6
3 #=> 1/4 1/2 1/4  0
4 #=> 1/5 1/2 1/3  0 -1/30
5 #=> 1/6 1/2 5/12 0 -1/12

(extra spacing here is just for clarity and is not necessary.)

  • \$\begingroup\$ 0 is positive? non-negative is better. \$\endgroup\$
    Nov 23, 2017 at 13:40
  • \$\begingroup\$ Fixed @user202729 \$\endgroup\$ Nov 23, 2017 at 13:41
  • \$\begingroup\$ Is outputting floating point coefficient allowed? Is errors from floating point imprecision allowed? \$\endgroup\$
    Nov 23, 2017 at 13:43
  • \$\begingroup\$ @user202729 No, because you get some fractions like 5/12 or 1/3 with non-terminating decimal expansions. \$\endgroup\$ Nov 23, 2017 at 13:45
  • \$\begingroup\$ What about the latter question? / Is errors from integer overflow (for large arguments) allowed? \$\endgroup\$
    Nov 23, 2017 at 13:47
  • \$\begingroup\$ @user202729 Yes, though you program should be able to handle up to, say, n = 20. \$\endgroup\$ Nov 23, 2017 at 13:48
  • \$\begingroup\$ I think the answer for 3 should be 1/4 1/2 1/4. \$\endgroup\$
    – alephalpha
    Nov 20, 2018 at 17:03
  • \$\begingroup\$ @alephalpha thanks \$\endgroup\$ Nov 21, 2018 at 18:31
  • \$\begingroup\$ Don't we already have a Bernoulli numbers challenge? \$\endgroup\$
    – lirtosiast
    Nov 26, 2018 at 19:45

The Hungry Moose


Moose face harsh conditions during the winter. According to one source:

Their winter foods are lower quality than what they eat in summer and provides less energy, consequently, they need to eat more of it. During harsh winters, having both extreme cold temperatures and deep snow, moose expend more energy than they take in and many can starve.


At noon on day 1, a hungry moose starts at a food source (the top left corner). Each morning, the moose may either walk to any 8-adjacent square or stay in place. Each evening, the moose clears the food and snow from its location (adding its net nutritional value to its calorie store and setting that value in the array to 0), and before the end of the day loses 1 calorie to the extreme cold.

The moose dies when its calorie store falls to 0 or below at the end of a day. In particular, if the value at the upper-left corner is 1, 0, or negative, the moose dies on day 1.


A 2D array of integers. Negative numbers represent calorie-negative deep snow.


The maximum number of days the moose can survive (counting day 1 as a full day).

Test cases (add)

6 0 -2 3
0 0 -5 -5
0 0 -1 3

42 -100 1
-100 -100 2
3 4 5

5 -3 1
1 -9 9
  • \$\begingroup\$ What happens if all the array values are all negative? Does the moose survive a single day or none at all? \$\endgroup\$
    – Belhenix
    Nov 22, 2018 at 20:21
  • 1
    \$\begingroup\$ A worked example would be useful. You also need to clarify if we can wrap around the array. \$\endgroup\$
    – Shaggy
    Nov 25, 2018 at 14:28

Inscriptio Labyrinthica

In the burial place of King Silo of Asturias there is an inscription that reads SILO PRINCEPS FECIT (King Silo made this).


The first letter is found in the very middle, and from there one reads by going in any non-diagonal direction radiating outward. The final letter is found on all four corners. In this challenge, you'll generalize the process to make them.


A string (or equivalent), and an integer. You may make the following assumptions about the input:

  • The string will have an odd length.
  • The integer will be an odd number between 1 and one less than twice the length of the string.


An inscriptio labyrinthica for the string, using the integer for the height (see models). Output should be each letter with no spaces, line break as default to your system/language.

Test cases

Note that an input of 1 or (length * 2 - 1) will result in a horizontal or vertical palindrome.

 Input: FOO, 3    Input: BAR, 1    Input: BAR, 3    Input: BAR, 5

Output: OOO      Output: RABAR    Output: RAR       Output: R
        OFO                               ABA               A
        OOO                               RAR               B

 Input: ABCDE, 5   Input: ABCDE, 3   Input: *<>v^, 3

Output: EDCDE     Output: EDCBCDE           ^v>v^
        DCBCD             DCBABCD           v><>v
        CBABC             EDCBCDE           ><*<>
        DCBCD                               v><>v
        EDCDE                               ^v>v^


This is so shortest answer in bytes wins. Standard loopholes forbidden.

(I feel like I've seen one similar, but searching around I couldn't find it, and I happened to be reading about this king when I got the idea).


In my original proposal, I had listed as a bonus to draw reading lines, but feedback was bonuses in code golf are discouraged. I still like that idea and am thinking about integrating it as a a main part of the challenge, but don't know if that would over complicate it or actually make it more interesting. The output for REI, 3 in such a case would be

↑ ↑ ↑
↓ ↓ ↓

The idea is that it would prevent simple flipping of data after calculating a quarter or half of the but still perhaps allow for some creative ways (I can think of some creative ways to do it shortly in some languages, but maybe it'll be overly complicated for others).

  • \$\begingroup\$ @trichoplax I've updated the challenge based on your feedback, let me know what you think. \$\endgroup\$ Jun 30, 2019 at 17:20
  • \$\begingroup\$ Looks good to me. +1 \$\endgroup\$
    – trichoplax
    Jun 30, 2019 at 18:24
  • \$\begingroup\$ you should now edit this to a link to the post and delete it. Thanks! \$\endgroup\$
    – Giuseppe
    Jul 24, 2019 at 19:11

Golf the truth and null values

In many programming languages there is a null and/or other special values. Sometimes they don't follow the normal rules of boolean operations. They may not even agree with the values of the same name in other languages.

Here are some different kinds of the "extended" boolean values, either borrowed from some languages or invented myself:

  • False.
  • True.
  • Absent. All operations between absent and another operand return the other operand.
  • Whatever. All operations between whatever and another operand returns whatever (itself).
  • Partial. If the result can be decided using the other operand, return that. Otherwise return partial (itself).
  • Error. An error as the first operand works like whatever, and an error as the second operand works like partial, except that "itself" means error. It has higher precedence than whatever and partial.

Your task is to define all these values in your language, and the 2 operations and or.

To be clear, the 2 operations should work exactly as in the following tables. The left column represents the first operand, and the top row the second operand.

and F T A W P E       or F T A W P E
  F F F F W F F        F F T F W P E
  T F T T W P E        T T T T W T T
  A F T A W P E        A F T A W P E
  W W W W W W W        W W W W W W W
  P F P P W P E        P P T P W P E
  E E E E E E E        E E E E E E E


You could use anything distinct and consistent to represent these values. You don't have to use a truthy value to represent true, or a falsy value to represent false. You are allowed and encouraged to use values that contain useful code, i.e. this loophole is not forbidden.

You are allowed to use actual errors or exceptions to represent some of the values. In this case the definition of that value should throw the same error, instead of represent the caught error. But the caught errors or the output messages should be distinct and consistent. Alternatively, you may choose to include STDERR in the output of your code, and use the printed message string as a normal value.

You may choose to pass functions generating and returning the values but doing nothing else to your code as input, in place of the values themselves, without counting the extra code.

You may use different ways of input/output for different values, as long as it is consistent for each kind of value, and it is possible to tell apart the first and the second operand.

You are allowed to use builtin functions and operators without boilerplate, in any argument order, even if you cannot save them in something callable in your language.

There could be some common code shared by all the 8 definitions and appear only once as header/footer. Other than that, the 8 definitions of operations and values must work independently from each other. The only way you can call something defined in the values in the operations is through a valid input method (e.g. you cannot set a variable in a value and read it in an operation).

Your score is the length of common code * 12 + the total length of the 2 operations * 6 + the total length of the values. Smallest score wins. The length of a value is either the length of the code generating it, or the length of itself unquoted if all the values are strings and you choose this way.

Abandoned rules

You are allowed to use operators, or chains of operators and values to represent the 2 operations, even if you cannot save them in something callable in your language. You may require the operands to appear at specific positions, but each operand must appear exactly once and be grouped together. You may choose whether to save operands in variables previously, and don't count the assignment if it doesn't add new information in the assignment (e.g. by changing its type). This makes it possible to use the built-in operators with short-circuit evaluation in languages that don't allow redefining them and preserve this characteristic, and may also make it shorter in some other languages.

Previous scoring: total length of the 2 operations * 50 + the total length of the values.

Possible follow-up

Original title: All the weirdness about the nulls

Extended tables including Valid in a previous version, Reverse aka Opposite by Zgarb, and Possible.

and T F N O W E V R P     or T F N O W E V R P
  T T F T O W E ? F T      T T T T T W T T T T
  F F F F F W F F F F      F T F F O W E ? T F
  N T F N O W E ? ? ?      N T F N O W E ? ? ?
  O O F O O W E ? O O      O T O O O W E ? O T
  W W W W W W W ? W W      W W W W W W W ? W W
  E E E E E E E ? E E      E E E E E E E ? E E
  V T F ? O F F ? ? ?      V T T ? T F F ? T ?
  R F F ? O W ? ? ? ?      R T T ? O W ? ? ? ?
  P T F ? O W ? ? ? ?      P T F ? T W ? ? ? ?

Other potential additions:

  • Default, that is opposite to Opposite.
  • Merge Possible with Valid.

Sandbox questions

  1. Will this be too easy in some languages that already have all of them?

    In languages that has True defined to be -1 and unifies bitwise and logical operations, most integers would works as Partial. GCD/LCM in APL is similar to this. SQL null is Whatever Partial. Most languages that has shortcut evaluation has errors as Error. Not sure about Absent, though.

    (Maybe the easiest way to find out is to post this question. It doesn't make the answer bad. But it's just some consideration in the sandbox for me to decide whether I'll post a stronger version.)

  2. Allowing "operators and chains of operators" seems to open a can of worms. Should I just remove this rule?

  • \$\begingroup\$ How about Opposite that behaves like the negation of the other operand? \$\endgroup\$
    – Zgarb
    Dec 11, 2016 at 19:10
  • \$\begingroup\$ @Zgarb Too similar to Other. For the "2 more to be added", I intended to make it possible to write expressions to 1) decide whether a variable is a specific value, and 2) return a specific value if a variable is true, or false otherwise. This may make the list more useful later. \$\endgroup\$
    – jimmy23013
    Dec 11, 2016 at 19:42
  • \$\begingroup\$ @Zgarb I gave up and even removed one, to make hardcoding the tables less likely to be the optimal way. \$\endgroup\$
    – jimmy23013
    Dec 13, 2016 at 17:56
  • \$\begingroup\$ if(whatever){/*???*/} \$\endgroup\$
    – Pavel
    Dec 13, 2016 at 20:23
  • \$\begingroup\$ @Zgarb I forgot this post for some reasons. Now I found your idea quite interesting. But I'll post the first version without it, and may add a stronger version if it worked well or is too easy, and may name it Degenerate to make most of the other results from operations make sense. \$\endgroup\$
    – jimmy23013
    Apr 30, 2019 at 8:40

Knight's tour

A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. For those who are not aware of how knights in chess work, knights are capable of moving in an L shape:

knight's moves

Tours generally apply to a regular chessboard of size \$8\$ however, it can be calculated for other sizes. For example, for a chessboard of size \$5\$, a possible knight's tour is:

5×5 knight's tour

Each grid size has quite a few combinations, for example, when \$n = 5\$, there are \$1728\$ possible tours and for a regular chessboard (where \$n = 8\$), there are \$19591828170979904\$. This is OEIS A165134.


Write a program/function that takes a grid size \$n\$ and outputs a possible valid board of integers.


  • Standard I/O rules apply.
  • Standard loopholes are forbidden.
  • \$n > 4\$
  • This challenge is not about finding the shortest approach in all languages, rather, it is about finding the shortest approach in each language.
  • Built-in functions that compute this sequence are allowed but including a solution that doesn't rely on a built-in is encouraged.
  • Explanations, even for "practical" languages, are encouraged.

Test cases

Yet to come.

  • 5
    \$\begingroup\$ "Your code will be scored in bytes, usually in the encoding UTF-8, unless specified otherwise.": So a Jelly answer will need to specify "Jelly (Jelly codepage)" or else it needs to count bytes of a unicode encoded source? Why not leave it out and let the tag code-golf handle the rules. And instead of generating test-cases, you could just add a program that validates the result as there are a lot of possible answers . \$\endgroup\$ Sep 22, 2018 at 14:19
  • 1
    \$\begingroup\$ @ბიმო Heh, I did this back with all my challenges when I was obsessed with creating "the perfect challenge template." I'll remove it. As for the test cases/validation program, I'll probably do both. \$\endgroup\$ Jul 12, 2019 at 1:55
  • \$\begingroup\$ @lirtosiast Oops, turns out I had mistaken the meaning of the Wikipedia section I just linked. I'll specify that a submission is not required to work on any \$n < 4\$. \$\endgroup\$ Jul 12, 2019 at 2:00
  • \$\begingroup\$ Another Mathematica built-in is coming~ \$\endgroup\$
    – tsh
    Jul 12, 2019 at 7:27
  • \$\begingroup\$ Can output be a list of coordinates? \$\endgroup\$
    – tsh
    Jul 12, 2019 at 7:29
  • \$\begingroup\$ Having both test cases and a validator sounds good to me too \$\endgroup\$
    – trichoplax
    Jul 14, 2019 at 7:59
7 8
10 11

You must log in to answer this question.

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