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".

  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    May 15 at 14:05

4691 Answers 4691

90 91
93 94

Traffic lights

Easy challenge

Write a program that that graphically shows traffic lights on a crossroads. It should output animation. There should be red, red+yellow, green, blinking green, yellow. Bonus - pedestrian traffic light.

Complex challenge

Write a program that manages traffic lights in a town. Input is a graph of roads, information about where people want to drive (i.e. in morning they mostly drive at work, in evening they return home) tied to the graph. The system models cars and reports you current positions and speeds of each car. Drivers' goals are to be inferred from statistics. Your goal is to provide the most optimal operation mode of each individual traffic light, avoiding accidents.


  • Which tags to use? Should it be a ?
  • Which is more viable - the easy or the complicated challenge? Should I try to work the complicated one to be more CodeGolf-worthy?
  • 1
    \$\begingroup\$ I think both of these challenges are too vague for this site. In the first, you should provide precise requirements defining a 'traffic light.' For example, the cloud in this question is extremely well defined. Your second proposal could work as a code-challenge, again if you add much more precise requirements. \$\endgroup\$ Oct 28, 2014 at 18:54
  • \$\begingroup\$ I see you're from Belarus. You have blinking green traffic lights there? I've not seen them in any of the 5 countries I've lived in. Don't assume people will know the exact sequence you want to use. Also in the USA you can turn right on a red light, but in western europe I've never heard of this. I would go for the easy challenge first, but you need to specify it more. How should it be displayed (I'm assuming plan view, light drawn on the right hand side of the road as seen by the driver with red nearest the intersection?) Is there a specified timed sequence or does it depend on demand? \$\endgroup\$ Nov 9, 2014 at 13:35

My telephone is a computer!

I finally took the plunge and purchased a push-button telephone. It seemed a waste to just bin the old telephone, so I got working with some surplus chips and boards and things, and a soldering iron, and made it into a computer!

Now I need a program. DialCode(c) can do Prime Numbers! I think.

So I need some help with an algorithm for Prime Numbers, with the following limitations:

10 variables, which can contain any number from zero upwards, limited only by 32,767; (Var0 - Var9)

10 labels; (Label0 - Label9)

10 Machine Instructions;

EndBlock: Ends a block - if the block was actioned, implicity Continue Main is executed, 
otherwise continues with next instruction (EndBlock) 

Test > 0: Starts a block, can test multiple variables (If > 0 Var0 ...)

Test = 0: Starts a block, can test multiple variables (If = 0 Var0 ...)
Set variable to another variable (Var0 = Var1)

Set variable to 1 (Var0 = 1)

Set variable to 0 (Var0 = 0)

Increment variable by 1 (Var0 +)

Decrement variable by 1 (Var0 -)

Unconditional branch to label (Br Label0)

Continue MAIN (Continue MAIN)

Output variable (Output Var0)

Instructions prior to the first Test are executed only once, at the start of the program.

Continue MAIN can be within a block or a "special case" unconditional use which is the target for the completion of a non-nested block.

The first Test defines MAIN.

MAIN is executed an "installation setting" number of times. These are 10 for Testing, and 1,200 for Production.

A Test can define an internal block if appearing before an EndBlock. The completion of an internal block does not cause automatic iteration (but an explicit Continue MAIN can be used for that).

All variables are initially zero.

Example program

Var1 = 1 
If > 0 Var1 Var3 
    Var2 +
If > 0 Var2
    Var1 +
    Var3 +
Var2 +
Continue MAIN
Output Var1
Output Var2
Output Var3

MAIN is defined here by the first IF > 0. The first test is not true. The second test is not true. Var2 gets one added, and MAIN starts up again (the unconditional Continue MAIN). The first test is still not true. The second test is now true, and Var1 and Var3 get one added. Since the block was executed, there is an implicit Continue MAIN. From this point on, the first IF > 0 will always be true, its block will be executed, with another implicit Continue MAIN so the program will finish quickly.

The above program demonstrates how to implement a "case-like" structure. Put another way:

Var1 = 1
BlockControl repeat 10 times
    Var1 > 0 And Var3 > 0
      Var2 +
    Var2 > 0
      Var1 +
      Var3 +
      Var2 +
Output Var1
Output Var2
Output Var3

The output from the program will be 2, 9, 1.

Algorithm can be demonstrated in any language, even pseudo-code (if guaranteed to work). Explanations will probably make your Answer more popular.

It is not required to write an emulator of the CPU, only to limit your choice of instructions in your language to those logically equivalent to what is supported by the CPU. DialCode(c) itself is a subset of your language (subject to differences in syntax)!

There is no input. Output can be whatever is convenient. Feel free to use any specialist libraries, as long as they follow the above limitations.

The Winner must work to the limitations. The most popular working algorithm will be chosen. Where submissions are effectively the same algorithm, the one posted first, which I was able to understand, is the tie-breaker.

Sandbox Questions

I can't find a question here about generating Primes only using addition and subtraction. I know one way to do it, so all the guff above is to funnel thought towards a known solution. The solution I've seen uses 10 variables, 10 or fewer types of instructions, and Labels are fun, but not necessarily necessary.

Not sure of a reasonable time-limit to impose before the Accept.

When I came across an algorithm for this, I thought it was really cool. Very easy to implement without knowing how the algorithm actually works, difficult to come up with the algorithm. Great fun finding out how the algorithm works.

I would like to see a wide range of answers in a lot of languages, so that even fairly inexperienced users can have a crack at implementing. That's not going to work with one question, because I don't think it is an easy type of algorithm to develop (without foreknowledge or practice).

So I was thinking one question to get an algorithm, a second question for implementation. I was thinking of "fastest code" but that puts Assembler/compiled languages/others as the natural rankings for that.

Prompted by a comment by @isaacg, I'm now thinking "total number of DialCode(C) instructions executed" may work for a follow-up implementation question.

So, Question One - get a nice algorithm. Question Two, implement in as few DialCode(C) instructions as possible.

Any implementation is going to be Ssssslllllooooooowwwwww, with a capital S. Fewest DialCode(C) instructions is fastest code, whatever language the DialCode(C) is written in. Reasonably level playing field.

I'll have a go at the suggested shortening of the question :-)

  • \$\begingroup\$ I like the challenge, but three comments: 1. The post might be a bit long, try to shorten it up a bit. 2. Why is it a popularity contest? Why not have an objective victory condition, e.g. fewest instructions? 3. What does this have to do with a telephone? \$\endgroup\$
    – isaacg
    Oct 24, 2014 at 19:36
  • \$\begingroup\$ @isaacg Thanks. In reverser order; the telephone solely as a massively humorous way to limit everything to 10; perhaps not everyone can come up with an/the algorithm, but pretty much anyone can implement the algorithm, I didn't want APL 3 and everyone goes home, I want algorithm, and if successful a follow-up for implementation; if I take the humour out, it should be much shorter... \$\endgroup\$ Oct 24, 2014 at 21:22
  • \$\begingroup\$ Okay, I think I get the humor, and that seems good. Perhaps you could have the tiebreaker between people with the same algorithm be fewer number of operations in your language used, not fewer characters. \$\endgroup\$
    – isaacg
    Oct 24, 2014 at 21:25
  • \$\begingroup\$ @isaacg Thanks again. I'll update the Sandbox Questions bit to try to expand on my thoughts on the follow-up. \$\endgroup\$ Oct 24, 2014 at 21:39
  • \$\begingroup\$ Awesome, I'm looking forward to the question. \$\endgroup\$
    – isaacg
    Oct 24, 2014 at 21:43
  • \$\begingroup\$ @isaacg Finally got some time cleared to update this and cover the release. Any further suggestions, more shortening or otherwise, welcome. \$\endgroup\$ Oct 30, 2014 at 16:42

This is an idea for an incremental answer-dependent question. I'm interested in comments. I will keep it here for a while and probably reword it at some point.

Print the name of the language of the previous answer

The first answer to this question must print the name Code-Golf without using any letters in Code-Golf.

Each answer that follows will have to print the name of the previous language, but without using any characters in the previous program (you can use letters in the language name, but not the code they posted). Each language can only be used once.

The winner is whoever posts the most valid answers. If there is a tie, then the length of each program is added together, and the answerer with the smallest total length is the winner.

The main problem I see with this is that multiple people would be racing towards the next answer. Allowing people to still post answers they worked on would cause clutter, and if people sign up to be the next answerer, we could be waiting forever for one to post. You could possibly have another question for answers that were too slow.

I would also need a rule against posting extraneous characters in your program that makes it impossible for the next one.

  • \$\begingroup\$ Would repeating languages be allowed? Would there be an answer time limit for users? Is Unicode allowed? You could limit answers to 40 distinct chars instead of forbidding extraneous characters, which is very subjective. \$\endgroup\$ Oct 30, 2014 at 23:20
  • \$\begingroup\$ @Calvin'sHobbies I like the 40 distinct character limit idea! Repeating languages is not allowed, and I don't know what would be a good time limit for users. I think allowing Unicoding makes sense, unless that could be abused badly or gets boring. Thanks for the feedback! Did 8 hours feel too long or too short or just right on your Hello World question? \$\endgroup\$
    – hmatt1
    Oct 30, 2014 at 23:26
  • \$\begingroup\$ I think it should be at least 2 hours. Though 8 or higher is better if you're scoring by number of answers, just so people only have to post a couple times a day to be a contender. One issue with this is that even with 40 unique chars it could continue on practically forever (as long as people find new languages), so I'd suggest more restrictions. Maybe something like the first language has to start with "A" the second with "B", the 26th with "Z" the 27th with "A" again.... \$\endgroup\$ Oct 30, 2014 at 23:38

Elevator Controller

Sandbox Note

  • I would love some feedback about whether you think this has enough room for algorithmic finesse to stick with or whether it should be .
  • Any kind of early questions or ideas are welcome, too.


Every day on my way to work I have to take one of two neighboring elevators – and often, they are not currently on my floor, so I have to press a button and wait for it to stop by. Ever so often, I get the feeling the software behind these elevators was written by an army of monkeys who finally managed to type some program that would compile.

But it makes me think: isn't there a more clever way to manage elevators? Maybe you can help me make my way to work less annoying by implementing a new controller software!

The Challenge

You must write a complete program that takes input from stdin (or similar) and print to stdout (or similar). Your program will receive the following arguments:

  • The first line consists of two space-separated numbers:
    • The number N of neighboring elevators your software will have to manage.
    • One integer H specifying the number of the top floor level for the building (the ground floor level is marked 0, so H = 5 means there are six stories).
  • All subsequent lines of input are a space-separated list of two numbers in the range [0, H] with the following meaning:
    • The first integer specifies the level on which a passenger is requesting an elevator.
    • The second integer specifies the level this passenger would like to get to.

During each time tick, your program must print (to stdout or similar) one line with N characters wherein each character specifies what an elevator does (from left to right = first to last elevator). The following commands are available:

  • D for "Move elevator one level down."
  • U for "Move elevator one level up."
  • S for "Stop the elevator on this level." This command allows any number of passengers to enter or exit the elevator on this level. This will happen automatically and people will only exit the elevator on the level they want to get to.

Furthermore, all elevators are rather small and have a maximum capacity of 2 people. So no elevator can take more than two people. Since people are generally nice, they apply a first come, first serve pattern. Passengers who are "too many" will just wait the next turn.

If two (or more) elevators happen to stop on the same level with people waiting to enter, they will start filling up the elevators from left to right.

All N elevators will start on the ground level – 0 – upon start of the program.

As always, standard loopholes apply. No cheating, no networking etc. If possible, please submit your answer with a link to an online interpreter or instructions on how to run it.



2 3
2 0
3 1

Possible Output:


Here are more examples, but to keep the post short, newlines are represented as | and input/output is separated by #:

2 3|0 1|0 2|0 3 # SS|UU|SU|UU|SS|US|SS

1 2|0 1|1 2|1 0|1 0 # S|U|S|U|S|D|S|D|S


This is a . There will be an unknown test case which I will only reveal after having accepted the winning answer (so you can make sure I didn't make scores up), but not before as to prevent answers optimizing for that test case only.

The score will be the number of steps your submission prints (= number of lines of your program's output). The lowest score wins with votes as a tiebreaker.


You may use the following snippet to verify your submission:

TODO (I will write this once I plan on publishing this question)


The Invincible Rock Paper Scissors

Make a bot that plays Rock Paper Scissors with the player. The bot should prompt the user for input (either rock, paper, or scissors) and then output the result. The result should include the user's hand, the bot's hand, and who won. An example of an acceptable result output would thus be:

I played rock! You played scissors! I won!

Another acceptable output:

The bot's rock beat the player's scissors.

This is the underhanded part: the bot should always win. However, the player has access to the source code of the program, so you should try and make the part of the code that causes the bot to always win as inconspicious as possible.

Here is an example in Python 2.x. If it were posted, it would not get many upvotes because it is extremely obvious that the bot will always win. A better answer would appear to be fair to the player, but in fact still causes the bot to win every time.

user_choice = raw_input("Pick a hand (rock, paper, or scissors)...")
if user_choice == "rock":
    print "I played paper! You played rock! I won!"
elif user_choice == "paper":
    print "I played scissors! You played paper! I won!"
elif user_choice == "scissors":
    print "I played rock! You played scissors! I won!"


My main concern with this challenge is that it may be a close duplicate of random script that isn't actually random. I am not sure if the requirement for having a different output for the user's input (while maintaining the illusion of randomness) is enough to differentiate this challenge from the original underhanded random challenge. Feedback on this issue is appreciated.

  • 1
    \$\begingroup\$ In my opinion, "underhanded" does not imply "always win." I think there are many more options for underhanded behaviors. For example, someone could write a RPS program with a weakness to be exploited by those with "insider info." That can help this challenge avoid being a duplicate. \$\endgroup\$
    – PhiNotPi
    Nov 8, 2014 at 17:47

Calculate the Delacorte Number of a square - posted

  • \$\begingroup\$ Please help me improve this and add it to the directory (I can't). How to get syntax highlighting here? Please vote if you think it is a good idea and should be posted. \$\endgroup\$
    – maf-soft
    Oct 24, 2014 at 10:57
  • \$\begingroup\$ I think you should include all relevant definitions in sufficient detail so that the challenge is self-contained and people don't need to follow the links to understand the challenge. \$\endgroup\$ Oct 24, 2014 at 12:35
  • \$\begingroup\$ Thanks for the comment, I was also thinking about it. My current short explanation is a little golfed itself :) - but I have an explanation, I have an example and the expected result (just added, please refresh). What is your suggestion I should add from the linked page? I think it is not necessary to have the same detail. \$\endgroup\$
    – maf-soft
    Oct 24, 2014 at 13:23
  • \$\begingroup\$ It's more readable to put the short explanation first and then the link to a more detailed explanation. I don't think that a more detailed explanation is necessary, though, as long as you clear up the ambiguity about which metric you're using for "distance²". It would be good to have a test case which is a bit less structured. It would be very good to have a brief statement of motivation (which would seem to be that there's a contest to maximise and minimise Delacorte numbers for a given side length). \$\endgroup\$ Oct 24, 2014 at 17:05
  • 1
    \$\begingroup\$ Finally, if the space dedicated to explaining your scoring system is 4 or 5 times as much as the space dedicated to explaining the problem, you've probably over-complicated it. What's wrong with asking for a function which takes the square as an array or string, optionally with a second argument giving the side length? \$\endgroup\$ Oct 24, 2014 at 17:09
  • \$\begingroup\$ Ok, I improved it, what do you think now? Regarding the over-complicated rules: I am pretty new here, and from the code-golf-challenges I have seen, I got the feeling that this detail is necessary. I would prefer the same fixed rules (or a set I can choose from) for all challenges, so it would not be necessary to post them here. Asking for a function sounds wrong because some languages have a different concept. With my code examples I just wanted to give a feeling about the intentions, but I cannot do that for all languages... Side length should not be given as input, only the square. \$\endgroup\$
    – maf-soft
    Oct 24, 2014 at 19:29
  • \$\begingroup\$ Thanks for adding this to the directory. I will post this soon if I don't get any more comments. Is the Title ok? Any hints? It's my first one. \$\endgroup\$
    – maf-soft
    Oct 31, 2014 at 14:43
  • \$\begingroup\$ If you want a specific person to see a comment, you should use an @ tag: e.g. @maf-soft. The reason you were notified about Martin's and my comments was that they're in reply to your answer: I've only just seen that you replied to me because I came looking for the question to ask how you're getting on in the actual contest. I still think it would benefit from saying that you're measuring Euclidean distance (as opposed to e.g. Manhattan distance). \$\endgroup\$ Nov 3, 2014 at 23:27
  • \$\begingroup\$ As for the scoring: code-golf implies a set of rules, and there are some currently active discussions in meta.codegolf about default assumptions on program vs function and forms of I/O. \$\endgroup\$ Nov 3, 2014 at 23:28
  • \$\begingroup\$ @PeterTaylor, thanks. Is that you in the highscore list? :) I currently don't have the time to work on it, but i will. It's fun! Of course you are right, that it's not immediately clear what distance is meant. But I think, due to the examples, it is clear enough. I think it's ok and intended, when contestants have to think a bit :) \$\endgroup\$
    – maf-soft
    Nov 4, 2014 at 9:49
  • \$\begingroup\$ Yes, that's me. I'm quite pleased with how well I've managed to do already with fairly basic techniques. \$\endgroup\$ Nov 4, 2014 at 10:09
  • \$\begingroup\$ @PeterTaylor, yes, reaching a score of 24.5 of the maximum 25 doesn't require very clever-clever effort :) but you will see, getting under the top ten is really hard and you need a lot of free time, I don't have. Two months left! \$\endgroup\$
    – maf-soft
    Nov 5, 2014 at 10:22
  • \$\begingroup\$ It's posted now (did I do it right?), can anyone remove it from the dictionary? \$\endgroup\$
    – maf-soft
    Nov 10, 2014 at 15:58
  • \$\begingroup\$ @maf-soft I removed it from the directory. The next step is deleting this sandbox answer to clear up space. \$\endgroup\$
    – PhiNotPi
    Nov 10, 2014 at 17:04

Lua Variables From Arguments?

In this question I challenge you to get variables from function arguments in Lua. The least amount of characters wins.

Basically I'm asking for you to create a function that takes an argument, and prints out the variable as a string.

Please note it has to work in a standalone Lua console.

  • 2
    \$\begingroup\$ I don't know Lua, but I have no idea what this is asking. Do we need to extract the names of the arguments? Their values? You will probably benefit from including an example input/output for this program/function... \$\endgroup\$ Nov 14, 2014 at 22:17
  • \$\begingroup\$ @Fry The variable, for example function hello(m) print(m) end m is an argument, the variable is m. \$\endgroup\$
    – warspyking
    Nov 14, 2014 at 22:26
  • 1
    \$\begingroup\$ @warspyking This definitely needs a proper spec. I do know a little Lua, but I'm still not sure what you're asking for. Please provide examples. Also, I should warn you that language-specific challenges are usually frowned upon, unless there are some reasons why the challenge only makes sense in that particular language (which I can't tell yet). \$\endgroup\$ Nov 14, 2014 at 23:28
  • \$\begingroup\$ OK, so that is still quite ambiguous: do you mean for us to get a reference to the variable? You need to tell us precisely where we get the information from (STDIN, file, etc) and precisely where and how to output it in the question. As it stands, this would be closed as unclear if posted. \$\endgroup\$ Nov 15, 2014 at 0:03
  • \$\begingroup\$ @Martin Why is language specific questions frowned upon? \$\endgroup\$
    – warspyking
    Nov 15, 2014 at 0:11
  • \$\begingroup\$ @Fry I added a little more detail in. \$\endgroup\$
    – warspyking
    Nov 15, 2014 at 0:12
  • \$\begingroup\$ @warspyking Because most of the time, there's no good reason to exclude people from your challenge you don't happen to know the same programming language as you (and quite often, language-specific challenges are a good indicator that someone's trying to use PPCG to outsource their homework, although that's probably not the case here). So if this challenge makes sense in other languages, you should try to be inclusive. And you should really add an example to show us what exactly you're asking. \$\endgroup\$ Nov 15, 2014 at 0:33
  • \$\begingroup\$ @Martin I don't know any other language to be able to confirm the answer. \$\endgroup\$
    – warspyking
    Nov 15, 2014 at 0:45
  • \$\begingroup\$ @warspyking If you added an example, some people might be able to tell you. ;) \$\endgroup\$ Nov 15, 2014 at 0:46
  • \$\begingroup\$ If I understand the refined question correctly, the goal is to retrieve the parameter names for the parameters of a function from inside the function itself, using reflection-style capabilities. With some help, I think that could be turned into something language-agnostic (though it'd need some good way of disallowing hardcoded results). \$\endgroup\$
    – FireFly
    Nov 15, 2014 at 0:50
  • \$\begingroup\$ @FireFly Yep, you've understood it correctly. \$\endgroup\$
    – warspyking
    Nov 15, 2014 at 0:55

Number Datasheets

Write a program that accepts an integer n where 1 < n < 10000 and prints some facts about it. Each fact must be on a separate line, and in the order shown here.

  • even or odd
  • prime or composite
  • deficient, perfect, or abundant
  • square if it's a perfect square
  • cube if it's a perfect third power
  • fourth power if it's a perfect fourth power
  • fifth power, sixth power, etc. as appropriate (each on a separate line)
  • square-free if it has no factors that are perfect squares (except 1)
  • triangular if it's a triangular number
  • pentagonal if it's a pentagonal number
  • hexagonal, heptagonal, octagonal, nonagonal, decagonal as appropriat
  • 11-gonal, 12-gonal ... k-gonal. However, these should only be printed if k is less than n or if k is less than 10. In any event, each of these term is to be on a separate line.
  • x totatives where x is the count of the numbers between 0 and n that are coprime to n
  • lucky if it's a lucky number
  • Fibonacci if it's a Fibonacci number
  • Lucas if it's a Lucas number
  • Leonardo if it's a Leonardo number
  • repdigit in base b if it's a repdigit in base b, where 1 < b < n-1
    • If it's a repdigit in multiple such bases, instead print repdigit in base b, c, d
  • strictly non-palindromic if it's not a palindrome in any base b where 1 < b < n-1

Any feedback would be appreciated.

  • 5
    \$\begingroup\$ Needs more links. I'd remove the polygonal numbers - that's a lot of hard-coded names to effectively duplicate your earlier question. \$\endgroup\$ Nov 18, 2014 at 7:42
  • \$\begingroup\$ How many powers do we need to support? And are empty lines in the output allowed? \$\endgroup\$ Nov 18, 2014 at 10:12
  • 5
    \$\begingroup\$ I think you're asking for too many things. I wouldn't want to code all those different properties. Maybe cut down to about 5? \$\endgroup\$
    – xnor
    Nov 19, 2014 at 8:35
  • \$\begingroup\$ I agree with xnor that there's too many things here. Regarding @MartinBüttner's comment, the first thing I would change is limit the powers to no more than cube, and polygonal numbers to no more than triangular. You need to clearly define all the different types of number too. There's a difference between polygonal numbers and centred polygonal numbers that would need to be clarified. Off the top of my head I have no idea what lucas and leonardo numbers are \$\endgroup\$ Nov 27, 2014 at 20:38

Math golf

This challenge is about writing code that outputs the smallest formula possible for a sequence of position integers.


I will choose 10 from the following test sequences of positive integers. However, please do not hardcode these into your answers. If I suspect this has happened, I reserve the right to change the test sequences without notice.

Your code should accept standard in with one list of comma separated sequences per line.

1, 2, 7

12, 9, 7, 5

40, 25, 16, 10, 7

2240, 1225, 679, 373, 213, 149, 141, 133

8064, 3969, 1969, 974, 494, 254, 164, 134, 119

118272, 53361, 24196, 10958, 5027, 2399, 1271, 863, 746, 695, 668, 665

1, 4, 36, 400, 4900

96, 1280, 17920, 258048, 3784704, 56229888, 843448320

72, 800, 9800, 127008, 1707552, 23557248, 331273800

40, 224, 1064, 3808, 21280, 59200, 322600

2240, 832, 240, 72, 20, 6, 3

53760, 17152, 4480, 1248, 384, 104, 44, 22, 11

329472, 86656, 20800, 5536, 1536, 440, 124, 44, 19, 8, 4

32800768, 6856704, 1536000, 394752, 103936, 27136, 7936, 2080, 656, 264, 132, 66, 33

206389248, 33216512, 7029760, 1743360, 448000, 112640, 30144, 8288, 2096, 688, 284, 102, 46, 18, 9

20956446720, 2527756288, 510181376, 122363904, 30720000, 7643136, 1972224, 508416, 136192, 35456, 10816, 3296, 1360, 632, 292, 146, 73


A math formula per input line which maps an index n starting at 1 to the relevant value.

A formula can be made up as follows. It can consist of the sequence variable n, integer constants, *, /, -, +, !, (, ), ^ or (m,k). These are to be interpreted in their normal mathematical sense with (m,k) to be read as binomial(m,k). The formula has to be well formed with, for example, parentheses matching and the order of precedence of operators will be the usual mathematical ordering.

A special rule applies to the factorial function ! which requires parentheses if the ^ or ! operators are to be applied to the result of the factorial. I.e. it is (n!)^2 and not n!^2. Note that the !! is never allowed. Unary - also requires brackets if any further operator is applied to the result on the left hand side or if the result is to be raised to a power. For example it is n*(-1) and not n*-1.


I will test your code on a number of sequences of integers that I make.

The score is the sum of the number of characters in all your outputs.

Example output

For the sequence that starts 96, 1280 above, the output 4^(n+1)*(2*(n+1))!/((n+1)!)^2 gives a score of 29.

  • 3
    \$\begingroup\$ It's an interesting idea, but it sounds brutally hard in the absence of gimmicks. There is, generally speaking, no systematic or efficient procedure for turning a sequence of numbers into a formula. \$\endgroup\$
    – COTO
    Nov 21, 2014 at 1:22
  • \$\begingroup\$ There's always the polynomial of degree length-1... which is the only realistic option if you write something longer than 10 characters. One could try to golf the polynomial a bit but anyway it wouldn't be a great challenge. \$\endgroup\$
    – feersum
    Nov 21, 2014 at 2:19
  • \$\begingroup\$ @feersum and COTO , The challenge is interesting, I hope, if many of the test cases come from sequences which do have short formulae. You are right that if the sequences are genuinely chosen at random it is perhaps not so interesting. \$\endgroup\$
    – user9206
    Nov 21, 2014 at 15:22

Generalized Array Indexing

Most programming languages provide an array datatype (which might be called a list or a vector) that supports indexing. Given an array and a nonnegative integer, we can fetch the element of the array at that position: [a,b,c][0] = a. Some languages, like Python, support a more general indexing system, where passing a negative index counts the position from the end: [a,b,c][-1] = c. But why stop there?

In this challenge, your task is to provide another generalization of this operation. In other words, you must provide a function that takes in an array and a number, and returns something, up to the following restrictions:

  1. If a nonnegative integer is passed to the function, it must return the element of the array at that position. In other words, it must be an extension of the array indexing operation.
  2. It must support more indices than just nonnegative integers, like negative integers, fractions, complex numbers, or even strings. In other words, it must be a proper extension.

If necessary, you may restrict the types of elements your arrays may contain, so you may choose to only handle arrays of, say, floating-point numbers, or other arrays. This is a popularity contest, so the answer with the most upvotes wins.

  • 4
    \$\begingroup\$ I'm sure people would come up with some fun ideas, but I believe this is currently a bit too broad as it stands (the telltale sign being a "something" in italics in your spec). \$\endgroup\$ Nov 25, 2014 at 17:37
  • \$\begingroup\$ That was my fear too. I don't know whether this can be turned into a good challenge without changing the idea completely, but I'll leave it here for now. \$\endgroup\$
    – Zgarb
    Nov 27, 2014 at 16:43

Play Chopsticks

Disclaimer: Please fix the question and the scoring if they are not satisfactory. I am probably not qualified to run and score entries because I am not entirely familiar with the logistics of running two programs against one another, and, as such, I will not be posting this question to the main page myself. So, if anyone wants to take this off my hands, feel free. I just really like this idea and want to see it happen.

Chopsticks Wikipedia article

Your challenge is to write a program that, given the current position of the game as input (how many fingers on each hand), outputs the next move it chose to take.

Rules of the game

(Normal rules, no variations)

  1. When a hand's finger-count becomes >= 5, it's finger-count becomes 0.
  2. Splitting/transferring is allowed. You CAN bring a dead hand back by transferring some fingers from your other hand.
  3. However, splitting/transferring is not allowed if the move only results in you having swapped your hands. (eg. no prolonging the game by "doing nothing")
  4. A player loses if both their hands are dead.


You will receive as input the number of fingers on each of your and your opponents hands.

Input will be given in the following format:

#_on_your_LH #_on_your_RH #_on_opponent_LH #_on_opponent_RH


1 1 1 1


4 0 3 2


Your program will output your move base on the input.


First number:
  0 (your LH)
  1 (your RH)
  2 (transfer from your LH to your RH)
  3 (transfer from your RH to your LH)

Second number:
  If first number was 0 or 1:
    0 (opponent's LH)
    1 (opponent's RH)
  If first number was 2 or 3:
    1-3 (# of fingers to transfer)


0 0 (tap opponent's RH with your LH)
0 1 (tap opponent's LH with your LH)
1 0 (tap opponent's RH with your RH)
1 1 (tap opponent's LH with your RH)
2 1 (transfer 1 finger from your LH to your RH)
3 2 (transfer 2 fingers from your RH to your LH)


Each entry will be made to play a game against every other entry.
If a game does not end after 100 rounds (?), it will be declared a tie.

Two points will be awarded for every win and one point will be awarded for every tie.
Entry with the most points is the king of the chopstick-hill.

  • \$\begingroup\$ This sounds so familiar, I feel like it has been posted before, either on main or in the sandbox (or maybe it was just discussed in chat), but the game has so many names that it's hard to find right now. (Looks like it was the sandbox and died off right away: chat.stackexchange.com/transcript/message/17654246#17654246) \$\endgroup\$ Nov 29, 2014 at 23:01
  • \$\begingroup\$ @MartinBüttner I still think that this should be done. Perhaps it could be made more interesting by allowing the programs to see the whole game, not just on a turn-by-turn basis, and they then could adapt to their opponents. Though I believe that would require networking / competing on a server, of which I know little. Well, in any case, like I said, I just thought this was a good idea and wanted to see it happen, though I don't feel up to taking the responsibility to do it myself. If this dies off too... oh well. \$\endgroup\$
    – kukac67
    Nov 29, 2014 at 23:23
  • \$\begingroup\$ I'm not sure if I remembered right, but I thought Chopsticks was a solved game for the second player? \$\endgroup\$
    – Sp3000
    Nov 30, 2014 at 3:27
  • \$\begingroup\$ @Sp3000 Dang it. I think you're right. I wonder if any of the variations to the game change it enough for it to require more strategy and not be a solved game. \$\endgroup\$
    – kukac67
    Nov 30, 2014 at 20:12

N-gon Naming


Given the word name of a polygon n, you must output the number of sides polygon n.


Input:  triangle
Output: 3

Input:  dodecagon
Output: 12

Input:  megagon
Output: 1000000

Input:  hexahexagon
Output: 66


The shortest code wins.

The list of shape names can be found here with instructions on how shape names are constructed. Use the alkane naming system.

  • \$\begingroup\$ In case you aren't aware, there's a pretty simple formula to find these numbers. \$\endgroup\$
    – Geobits
    Nov 13, 2014 at 19:58
  • \$\begingroup\$ @Geobits This is more parsing of the shape name \$\endgroup\$
    – Beta Decay
    Nov 13, 2014 at 19:59
  • \$\begingroup\$ For some reason I thought that part was a dupe, but it turns out I can't find anything except going the other way (3->tri). \$\endgroup\$
    – Geobits
    Nov 13, 2014 at 20:02
  • \$\begingroup\$ You'll probably need to define an upper limit, like this question did \$\endgroup\$ Nov 13, 2014 at 20:46
  • 1
    \$\begingroup\$ If the challenge is really about parsing the shape name, then just have that be the question. \$\endgroup\$
    – xnor
    Nov 14, 2014 at 10:12
  • \$\begingroup\$ It might be a good idea to point out if we need to support Tetracontadigon, as well as 42-gon. \$\endgroup\$ Nov 19, 2014 at 15:30
  • \$\begingroup\$ The rules on that new link are confusing. What is a hexahectogon? 6100? 600? \$\endgroup\$ Nov 20, 2014 at 19:13
  • \$\begingroup\$ Can we really trust a site that says Is there actually a name for a 27 sided pentagon? Yes there is.? \$\endgroup\$
    – feersum
    Nov 20, 2014 at 21:56
  • \$\begingroup\$ @feersum Yeah... I was hoping to find a long list of every shape from 3 to n... That's the best I could do ATM \$\endgroup\$
    – Beta Decay
    Nov 21, 2014 at 7:03
  • \$\begingroup\$ en.wikipedia.org/wiki/Polygon has a better list with more rules than the site you linked. Anyway, both sites offer various alternative names and you should specify which are required, and the maximum number of sides to be supported. It is very, very unclear how a polygon with more than 1999 sides should be named. \$\endgroup\$ Nov 30, 2014 at 12:40
  • \$\begingroup\$ @steveverrill A polygon with more than 1999 sides -> circle ;) \$\endgroup\$ Dec 1, 2014 at 17:34

Help Bob the Builder survive the communists, and fast!

The communists have taken over the world and you are the last remaining tower builder. In order to surive you must show that you are able to build towers and fast!

The challenge

Bob is given a set of building blocks b, and a number n of towers to build. Since we are in communist land the towers should have as equal of an height as possible. The catch is that you are only given 180 seconds to build the towers. The goal is to minimize the std of the tower height. In addition you have to build towers at three different sites. Which means three different sets of building blocks and three different set of towers.

Input & Output

blocks = [1,2,3,4,5,6,7,8,9]
towers = 3

The ouput should be on the form

7 6 2
8 5 4
1 9 5

std = 0

Here the towers are built vertically. The std is calculated as follows

std = sqrt[(mean - tower1)^2 + (mean - tower2)^2 + ...]

where tower1 represents the height of that tower and mean is the average of the heights.

mean = (tower1 + tower2 + ... + towern)/towers

Example 2


blocks = [1,2,3,4,5,6,7,8,9]
towers = 2


5 3 2 4 1
9 6 7 9 0

std = 0.7071

Since mean = (23+22)/2 = 22.5 and std = [(22.5-23)^2+(22-23)^2]^(1/2) = [1/4+1/4]^(1/2) = (1/2)^1/2.

These two are examples of optimal outputs. Since the problem is NP hard an optimal solution within a reasonable time is impossible.


The blocks for the three building sizes are given below. The sum of these three tests judge your performance. Lowest score wins. Eg

 score = 100*std(1) + 50*std(2) + std(3)

Where std stands for the standard deviation obtained at building site n. Do not try to cheat and make a code that runs longer than 300 seconds. The KGB (Eg me) performs regurarly controls.

Question for meta

1) Is the problem clear enough? Eg use the three vectors and distribute them equally

2) Is the scoring now fair? Must have a run time beneath 3 minutes, lowest score wins.

Building site 1: 2 towers

Building site 2: 3 towers

Building site 3: 23 towers

  • \$\begingroup\$ How is this different to your previous question? \$\endgroup\$ Dec 14, 2014 at 17:48
  • \$\begingroup\$ In previous question the number of elements in each tower were fixed, here only the number of towers are fixed. There is now a logical time constraint as well as a fair score system. Plus slightly more creative vectors. Is that enough? \$\endgroup\$ Dec 14, 2014 at 18:07

Quine is love, quine is life (well, almost)

Yes, another Life challenge. Inspired by this.


Write a program (the generator) that, when given a representation of a Game of Life board on STDIN (or in a file if you like), outputs a program which contains a string representation of a Game of Life board in its source code.

The representation will be in the following format:

 h w x1 y1 x2 y2 x3 y3 . . . xw yh


  • h = height of the grid
  • w = width of the grid
  • xi yi = coordinates of a live cell

When run, the new program should output its own source code - with a catch: the string in the output must represent the generation following the one previously encoded. (We shall call this program the replicator.)

Other stuff

  • All live cells will be provided as input, so all other cells may be assumed to be dead.

  • 0,0 is at the bottom left.

  • Both programs (the generator and the replicator) need not be in the same language.

  • There may be a width-one border around the string representation for a -10% bonus in score.


Your score on a particular input will be defined as the length of the generator plus the average length of the first 100 generations of the replicator.

Your final score will be the average of your scores on all the test cases. The lowest score wins!


Should we impose a format for the string representation, like maybe

* * * * * * * * * * * * * * * * * * *
*                                   *
*                                   *
*                 *                 *
*               *                   *
*               * * *               *
*                                   *
*                                   *
*                                   *
* * * * * * * * * * * * * * * * * * *

or should we let the GolfScripters and CJammers of PPCG use their unprintable black magic? :D

  • \$\begingroup\$ Just to check, the scoring formula is generator_length + sum(replicator_lengths)/100? The bolding is a tad misleading: it seems to imply that the division is performed also on the generator length (which would be very odd). \$\endgroup\$ Dec 22, 2014 at 3:33
  • \$\begingroup\$ That is indeed what I meant, but you're right; it is a bit odd. Fixing. \$\endgroup\$ Dec 22, 2014 at 4:27
  • \$\begingroup\$ The scoring formula is generator_length + sum(lengths of first 100 replicators)/100. \$\endgroup\$ Dec 22, 2014 at 4:30
  • 1
    \$\begingroup\$ This looks like a less interesting version of this Life quine question. If you do decide to allow flexibility in the representation, you'll need to be careful to avoiding being too close a duplicate. Other than that, I don't understand what h and w are (is there an unspoken assumption of boundary conditions?) nor what you mean about 0,0 being the bottom left (since the output doesn't care which directions the axes run) or about having a border around the string representation. \$\endgroup\$ Dec 24, 2014 at 11:06

Query the icosahedral graph

You've been sent back in time to 1973 to change history by remaking a clone of Hunt the Wumpus. You need to code a network of rooms in the game that forms an icosahedral graph, whose vertices correspond to the 12 vertices of the icosahedron connected by edges, unlike the dodecahedral graph used in the original game. Each room connects to five others.

Your goal is to write a program or function that takes the ID numbers of two of the twelve rooms, and returns one value if the rooms are adjacent, and a different value if not. Due to space constraints, you code needs to use as few bytes as possible.

You can choose what ID's to label the 12 rooms, but due to hardware constraints, they must be numbers from 0 to 255. Specifying the ID's doesn't count for the code length.


Two distinct ID numbers from 0 to 255 out of 20 of your choice. You can't restrict which order two numbers appear in.


A consistent value for pairs of numbers that correspond to adjacent rooms in your ID scheme, and a different consistent value for non-adjacent pairs.

Your code may not use any built-ins that represent the dodecahdral graph or related structures.

  • \$\begingroup\$ I haven't actually given much thought to how to do this and how hard or easy this easy. Looking for feedback on this half-baked idea. \$\endgroup\$
    – xnor
    Jan 3, 2015 at 18:24
  • \$\begingroup\$ Well, Hunt the Wumpus has been done. Not sure how much more room for variation this subchallenge gives other than ripping out the relevant parts from the answers of the previous challenge. \$\endgroup\$ Jan 3, 2015 at 18:37
  • \$\begingroup\$ @MartinBüttner Fair point, I'll switch to a different graph. \$\endgroup\$
    – xnor
    Jan 3, 2015 at 18:48
  • \$\begingroup\$ I'm not sure at the moment which graph the question is trying to talk about, but IIRC both dodecahedron and icosahedron have been done. In fact, you did a dodecahedron graph structure question already. \$\endgroup\$ Jan 3, 2015 at 19:12
  • \$\begingroup\$ @PeterTaylor I guess I'm not conveying my idea well. The core idea is to make a two-input function whose truth table is isomorphic to some specific graph, with you getting to choose the input labels and the isomorphism. So, it's a question of how to represent the required graph as much as how to code it. For example, if I asked to make a 16-vertex hypercube graph, you could label vertices by the four-bits numbers 0 to 16 the natural way, and check for an edge by whether the xor of the two labels is a power of 2. \$\endgroup\$
    – xnor
    Jan 3, 2015 at 23:21
  • \$\begingroup\$ I understood that. How do you feel about switching to the Petersen graph? It's comparable in size and complexity, but it's definitely not treading on the toes of the previous questions. \$\endgroup\$ Jan 4, 2015 at 9:16
  • \$\begingroup\$ @PeterTaylor The Petersen graph happens to have a compact and elegant solution that's surely optimal. Got any other graphs to suggest? \$\endgroup\$
    – xnor
    Jan 5, 2015 at 3:16
  • \$\begingroup\$ Fair point. How about the McGee graph? It's not vertex-transitive, so I think that probably forces a different approach to the group representational approach which was used on the earlier questions. Other interesting options might be the Pappus graph and the Coxeter graph, but they have more symmetry. \$\endgroup\$ Jan 5, 2015 at 20:01

Reverse Polish Notation-ing!

Your challenge is simply to write a function which converts a given arithmetical expression into it's Reverse Polish Notation form.


Your function will be passed in an arithmetical expression, as a string, which may contain any of +-*/^() or a space. For example:

1+1 34 * 7^6 3 * (78 + 7)


Your function should return the Reverse Polish Notation form of the input with a space between each number. The above inputs would output:

1 1 + 7 6 ^ 34 * 78 7 + 3 *


This is so shortest code wins. Bonuses are as follows:

  • -15 for supporting brackets in the input (as in: ())
  • -5 for supporting exponents (as in: ^)
  • -10 for supporting floating point (decimal) numbers (formatted with a dot: 12.56)

You should support, at minimum, +, -, * and / operations.

Good luck!

To the sandbox:

  • Should I give more examples or is 3 enough?
  • Do you think the deductions are a fair amount off? Too much? Too little?
  • Am I missing something really obvious? (I usually am!)
  • \$\begingroup\$ I would call the inputs arithmetical expressions instead of sums, since there can be other operations than addition. \$\endgroup\$
    – Zgarb
    Jan 3, 2015 at 19:55
  • \$\begingroup\$ Thanks, I couldn't think of a better word! Edited :) \$\endgroup\$
    – JamJar00
    Jan 3, 2015 at 19:57
  • \$\begingroup\$ Looks like it's a duplicate. \$\endgroup\$ Jan 3, 2015 at 20:24
  • \$\begingroup\$ Gah! Thanks, Nevermind then :( \$\endgroup\$
    – JamJar00
    Jan 3, 2015 at 20:25

Print the Twelve Days of Christmas with twelve programming languages

Use twelve programming or scripting languages to write twelve programs, embedded within each other, to print the lyrics for Twelve Days of Christmas.

Each program will write the next program to file, compile if needed, and execute it. The parent processes will not exit until the last has executed. When they exit, they will print the final verse, program by program. You may only have one file to start with. You may also, optionally, have a text file with each line of the song in it.

You must specifiy any dependencies needed to run the programs. For example, if you need a compiler, such as GCC, or PHP or the Java compiler/Java, put them in a list of dependencies.

For example:

echo "On the first day of Christmas, my true love gave to me:\nA partridge in a pear tree!\n";
$code = <<<EOD
public static void main(String [ ] args) {

String nextCode = new String;
System.out.println("On the second day of Christmas, my true love sent to me:");
System.out.print("Two Turtle Doves\nand a Partridge in a Pear Tree\n");
nextCode = "(Next code to be written is in here)";
PrintWriter writer = new PrintWriter("thirdDay.c", "UTF-8");
* and write the next program, in this case, thirdDay.c to file and so on....
file_put_contents("secondDay.java", $code);
exec("javac secondDay.java");
echo exec("java secondDay");
echo "and a Partridge in a pear tree"; // runs after the other twelve have run

Apologies for my rusty Java.

To reiterate:

  1. The program is started
  2. The program prints the appropriate verse
  3. The program writes the source code for the next program to file, which in turn contains the code for the rest, and so on.
  4. The program compiles (if needed) the next program, and runs it.

The final program will only print the line for Day 12. It will then exit, returning to its parent program, which will print the second line - Day 11, exit, and so on. In my example, this line will run last:

echo "and a Partridge in a pear tree"; // runs after the other twelve have run

Have fun with those quote marks. I started with PHP and Heredoc for a reason ;)

Assume that this will be run in a Linux/Unix terminal. Windows is okay if you can pull it off.

This is a popularity contest. Assuming that you can get everything escaped properly ;)

Merry Christmas!

  • 1
    \$\begingroup\$ My comments on self-contradiction from the original question still stand. \$\endgroup\$ Jan 6, 2015 at 21:43
  • \$\begingroup\$ I'll edit it later, but since it's past Christmas, it's got lower priority now. Can you provide an example of self-contradiction? Perhaps I can remove the offending part to clear it up. (While the first 11 print the full song until day x, number twelve only prints its first line (Partridge) and then exits, sub-program number eleven then prints Turtle doves, exits, and so on until the original program.) \$\endgroup\$ Jan 7, 2015 at 0:29
  • 1
    \$\begingroup\$ "It's not clear whether the final output should be the full lyrics of the song (one verse per program) or just the last verse (one line per program); or whether each program in the chain should print then execute (as per example code and numbered breakdown) or execute and then print (as per "*It will then exit, returning to its parent program, which will print Day 11, exit, and so on")*" \$\endgroup\$ Jan 7, 2015 at 23:31

A natural divisor

Expressiveness, natural language elements and readability, these are just a few of the awesome features/ideologies modern high-level languages promise us. But how "readable" and "natural" are these languages really? Can you really read them as they were english? In this challenge you have to prove how (un)natural your preferred language really is.


You're to write a program that accepts a list/string of numbers from the STDIN, and outputs their greatest common divisor to the STDOUT. However you also need to write a complete description of your program, an english explanation of your entire program. The challenge is to make your program resemble the description as much as possible. As in a perfect natural programming language there would be no difference, your score will be the Levenshtein distance between your program and your description.


  • Your description can only contain correct english sentences. The sentences must be at least six words long.
  • The description must contain the full and correct process of your program. Nothing more or less. An example can be found below. As a general rule: a programmer that doesn't understand your language should completely understand your description and should be able to recreate the exact algorithm.
  • Your program cannot contain both comments or strings.
  • Your program should use the universal accepted definition to calculate the greatest common divisor. If the input only contains 0's, you have to output 0.


This is a fibonacci function to illustrate how a description should look like:

def F(n):
    if n == 0: return 0
    elif n == 1: return 1
    else: return F(n-1)+F(n-2)

Define a function F with input n. If n equals 0, return 0. 
Else, if n equals 1, return 1. 
Else, return the output of F with input n minus 1, 
plus the output of F with input n minus 2.


As mentioned earlier, your score is the levenshtein distance between your description and your program. You can calculate your levenshtein distance with the following snippet (thanks doorknob):

var f=document.getElementById("f"),g=document.getElementById("s"); function h(){var a=f.value,e=g.value;if(128<a.length)a="<span style='color:red'>First program is too long!</span>";else if(128<e.length)a="<span style='color:red'>Second program is too long!</span>";else{if(0===a.length)a=e.length;else if(0===e.length)a=a.length;else{var d=[],b;for(b=0;b<=e.length;b++)d[b]=[b];var c;for(c=0;c<=a.length;c++)d[0][c]=c;for(b=1;b<=e.length;b++)for(c=1;c<=a.length;c++)d[b][c]=e.charAt(b-1)===a.charAt(c-1)?d[b-1][c-1]:Math.min(d[b-1][c-1]+1,Math.min(d[b][c-1]+1,d[b-1][c]+ 1));a=d[e.length][a.length]}a="Distance = <strong>"+a+"</strong>"}document.getElementById("d").innerHTML=a}f.onkeyup=h;g.onkeyup=h;
<h3 id=ft>program</h3>
<textarea id=f rows=7 cols=80 style="width:100%"></textarea>
<h3 id=st>description</h3>
<textarea id=s rows=7 cols=80 style="width:100%"></textarea>
<p id=d></p>

Sandbox questions/notes:

  • The question was just crazy idea for the most part. Do you think this question would work?
  • Are there any languages that would get an unfair advantage? Are there more things I should ban?
  • I know the description of the program description is somewhat subjective, so the answers would mostly involve being creative with their description. Are their any additional rules that could restrain this?
  • 2
    \$\begingroup\$ The six word restriction seems pretty arbitrary. I might want to write If so, return 0. which seems like a perfectly normal sentence in a program description to me. The main trouble will be determining if a description is "good enough". You could do so by defining a vote threshold an answer needs to be eligible, but it's not a perfect solution either. As for the Levenshtein distance, I'm sure Doorknob won't mind you reusing his Stack Snippet. \$\endgroup\$ Jan 10, 2015 at 13:27
  • 1
    \$\begingroup\$ @MartinBüttner I added the six words restriction to avoid one word verbs as a sentence, and force some more verbose description. But I might delete/lower it... A vote threshold is not that bad of an idea actually... \$\endgroup\$
    – Def
    Jan 10, 2015 at 15:11

Final Exam Grade Calculator

So, it's around time for finals, and many students want to know what grade they need on their final exam to achieve an A, B, or sometimes a passing grade. There are many factors here - the weight of the final, two quarters having weight, what grade the students want - but it is still a simple task.


Write a program that will take three integers and output the grade they need to receive on the final.


Three integers. The first two will be from 0 to 100, and the last will be from 1 to 100. They represent the current score in the class, the desired score, and the weight of the final, respectively. A working example can be found here.

Any input outside the expected ranges can have undefined behavior.


The score the student needs to receive on the final exam. This score could be above 100 (every once in a while, students have unrealistic expectations), but if it is a negative number, it is automatically 0. The formula for score is as follows.

(desired - (current score * (1 - weight*.01))) * 100/weight

The output may not be an integer. In this case, round to the nearest hundredth (round up for .##5).


Input: 100 90 20    

Input: 65 60 30

Input: 54 100 25


This is a challenge, so the shortest code wins.


  • -10% if your code can take either 3 or 4 integers as input. If four integers are taken, then the first two are averaged to give what would normally be the first integer. Each of the first two integers here represents a quarter grade.

What other bonuses should I add? I can't think of many right now, but even one or two more would be helpful.

  • \$\begingroup\$ Maybe it's British vs American English, but I find that this question uses some words rather strangely. When the output talks about finding a score, that's the word I expect to see in almost every instance of grade; I would understand grade to mean the letter A, B, etc. That aside, there are some small changes which I think are improvements on either side of the pond: change expected to desired, and specify with the rounding which way to round ##.##5. It would probably also be useful to state explicitly that scores are always out of 100. \$\endgroup\$ Jan 14, 2015 at 8:36
  • \$\begingroup\$ Oh, corner cases. Input 80 80 0 is apparently legal, but gives NaN; I would change the spec to say that the weight ranges from 1 to 100. Input 90 80 1 will give a negative number from your formula, but IMO the spec should ask it to be clipped to 0. You could make that a bonus, but I'd make it a core requirement. \$\endgroup\$ Jan 14, 2015 at 8:40
  • \$\begingroup\$ @PeterTaylor Right on everything there. Edge cases will have to be specified. I didn't realize that there were so many. About the wording, I will see what I can do to make it more logical. \$\endgroup\$
    – mdc32
    Jan 14, 2015 at 13:45

Possible resistances from resistors

Meta: Note this is far from done; just putting this idea out so that I can continue working on it. IE way work in progress. I need to specify a lot more of this and I'm putting this here because I know I won't end up working on this if it isn't here.

Given a set of resistors, output all the possible resistances that can be formed with them.

Thoughts so far:


Input will be a comma-separated or space-separated list of natural numbers such as

1 4 3 2 4 3 5 999


Output will be all the possible formable resistances, sorted, on its own lines, plus the number of ways to form each resistance.

(no example yet)

  • \$\begingroup\$ Sounds like a complicated combinatorial problem wrapped around codegolf.stackexchange.com/q/12483/194 . I wouldn't be surprised if you get a few wrong answers and zero correct ones. \$\endgroup\$ Jan 16, 2015 at 8:45

Implement the Henkin quantifier

Your goal is to implement the Henkin quantifier Q_H, a generalized (branching) quantifier on four variables x1,x2,y1,y2 and a Boolean function f. It expresses the idea that for every choice of the x's, there's a choice of the y's so that the four variables satisfy f, so that each y depends only on the corresponding x and not the other one.

The parallelness of the choice of is sometimes represented by stacking the paired quantifiers like this:

enter image description here

This quantfier cannot be expressed in first-order logic.

The parallel choices for the y's are like prisoners being interrogated in separated rooms. They are each asked the respective questions x1 or x2 and must give respective answers y1 and y2 without knowing what the other one was asked, so they are liable to be trapped in inconsistent claims. The guards then evaluate the validity of their responses ointly by some function f that depends on both questions and answers. If the prisoners can always win this game, then f satisfied the Henkin quantifer Q_H.

Formally, the Henkin quantifier Q_H takes in a Boolean function f of four inputs (x1,x2,y1,y2), and evaluates whether the following statement is True:

For every x1 there exists a y1, and for every x2 there exists a y2, so that f(x1,x2,y1,y2) is True, and the choice of y1 depends only on x1 and the choice of y2 depends only on x2.

Alternatively stated in Skolem normal form

There exists functions g1 and g2 so that for every x1 and x2, the function f(x1,x2,g1(x1),g2(x2)) is True.

For this challenge, the domain of discourse will be natural numbers from 0 to 9.


A function f that takes in four numbers x1,x2,y1,y2, each between 0 and 9 and produces a Boolean output.


A consistent Truthy value if f satisfies the Henkin quantifier Q_H, and a Falsey value if it does not.

Questions for Sandbox:

  1. Does this challenge make any sense?

  2. What should the input format be? Not every language can take in functions. What about nested lists? Subsets of four-digit numbers?

  • \$\begingroup\$ Let me see if I can interpret it. Does it mean that there exist two functions g and h such that f(x1, x2, g(x1), h(x2)) is true for all x1,x2? \$\endgroup\$
    – feersum
    Jan 21, 2015 at 16:43
  • \$\begingroup\$ @feersum Yes, that's right. \$\endgroup\$
    – xnor
    Jan 21, 2015 at 22:27
  • \$\begingroup\$ The obvious input formats for non-functional languages would seem to be a 4D truth table array boolean[][][][] or a 2D "accepted" array int[][4]. \$\endgroup\$ Jan 25, 2015 at 23:22

The Great, White, North! - POSTED

  • 1
    \$\begingroup\$ 1. What are the bounds on the relative proportions? 2. What are the RGB codes of the colours? 3. What are the minimum dimensions? 4. What's to stop me using a font which is so different that only I can read it? 5. Does "saves an image" include "writes an image on stdout"? \$\endgroup\$ Jan 8, 2015 at 9:31
  • \$\begingroup\$ Since there is no clear consensus on this yet you might want to mention explicitly whether you will allow golfed/compressed raw image files as submissions. \$\endgroup\$ Jan 8, 2015 at 11:35
  • \$\begingroup\$ In-universe note: You should probably just save a highly compressed image instead of a program to produce the image. You might then be able to squeeze another syrup recipe on there (or a script to curl the latest hockey scores). \$\endgroup\$
    – Geobits
    Jan 12, 2015 at 2:33
  • \$\begingroup\$ @PeterTaylor Been almost two weeks but I finally revamped it. Thoughts? \$\endgroup\$
    – globby
    Jan 21, 2015 at 2:41
  • \$\begingroup\$ Sorry, I was travelling. Looks like you sorted all the issues I raised, though. \$\endgroup\$ Jan 25, 2015 at 23:18

Solve a LaserTank level (optimally?) [WIP]

LazerTank is more than just a computer game, it is a blast from the past. In this game, the player controls a tank that shoots lasers and navigates through a series of puzzles. The goal of this challenge is to write a program that solve game levels.

TODO: Actually explain how LaserTank works. There is an instructions page on the website.

Input will be an ASCII representation of the game map. TODO: determine which characters stand for what stuff.

Output will be the list of actions required. There are four possible actions for each step in the solution, "move forward," "turn left," "turn right," and "shoot".


Counting k-mers

The task is to count the number of distinct substrings of length k, for k = 1,2,3,4,.....


Your score is the highest k you can get to on my computer in under 1 minute.

You should use http://hgdownload.cse.ucsc.edu/goldenPath/hg38/chromosomes/chr2.fa.gz as your input and ignore new lines.

You should ignore all newlines. You can preprocess the input to decompress it before starting.

The following code outputs a histogram of all the 4-mers. You can then count how many there are with wc.

awk -v substr_length=4 '(len=length($0))>=substr_length{for (i=1; (i-substr_length)<len; i++) substrs[substr($0,i,substr_length)]++}; END{for (i in substrs) print substrs[i], i}' file.txt

(This question is not finished yet.)

  • \$\begingroup\$ As pointed out by Geobits on chat, there's a simple approach which takes O(kn) to count distinct substrings of every length up to k. \$\endgroup\$ Jan 30, 2015 at 20:18
  • \$\begingroup\$ @peter But can you do faster? It might be possible to optimise in the common cases. If every k-infix is unique, then you know the number of n-infixes for every n>k. A BWT might be a viable approach as well - not sure how long that would take. \$\endgroup\$ Jan 30, 2015 at 20:49
  • \$\begingroup\$ @PeterTaylor I was also thinking of adding a space restriction but I haven't worked out those details yet. \$\endgroup\$
    – user9206
    Jan 30, 2015 at 21:18

Elevator Control [WIP]

The controller is still a WIP, but I have a decent idea of how it'll work.

You have been hired as a Vertical Integration Specialist (programmer) at Ascension Incorporated to write advanced elevator controller software. (backstory wip)

Elevators are Cool

The current setup is that there will be ten floors and three elevators. This is 100% subject to change. I'm not exactly sure how the game will be judged, below is an idea.

As people begin queue up, your elevators will be responsible for making sure that they get where they want to go. Each game tick, there is a certain % chance that a person will queue up at a given floor with a random destination. You goal is to transport 1000 people in the least time possible.


Your submission will be the the form of a Java class. This class must contain at least two methods: the constructor mySubmission(Elevator[] elevators, Floor[] floors) and update(Elevator[] elevators, Floor[] floors). The constructor class will be called once, and update after every game tick.

Elevator Class:

  • int location gives the current floor location of the elevator. (Read-only)
  • int dest gives the destination of the elevator. All elevators have a destination, even an idle elevator, in which case the destination is the current floor. (readOnly)
  • String status is idle or busy. Elevators which are idle are not moving and have no floors in queue. (read-only)
  • boolean[] buttons tells which buttons have been pushed, signifying that a person in the elevator wants to go to that floor.
  • ArrayList<Integer> destQueue gives the list of destinations for this elevator. An idle elevator with something in destQueue will become busy and have a new destination. (writable)
  • goToFloor(int i) adds that floor to the queue if it is not already in it.
  • clearQueue() clears the queue. Simple as that.

Floor Class

  • boolean waiting means that somebody is at that floor.
  • boolean up means that somebody on that floor wants to go up.
  • boolean down means that somebody on that floor wants to do down.

Random distribution in array with exact number of occurences and max size

Write a program or a function, that takes 3 inputs x y z, where :

x is an integer representing the max size of each output array.
y is an integer representing the exact number of occurence of each z value.
z is a set of n integers to distribute

and outputs a set of arrays containing z values randomly distributed (each array must be unique, different ordered array are not the same).


  • Each value of z can only appear once in each output array
  • x value is between 2 and 10
  • y value is between 1 and 10
  • n is between 2 and 50
  • z's n values are between 0 and 50
  • If and only if n * y isn't divisible by x you can output one array with less than x elements
  • "Random" means that every possible output must be produced with finite probability (barring the finite length of the PRNG's cycle)
  • You can assume valid inputs, and there will always be at least 1 possible solution


Input :

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

Output :

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


4 5 [0 1 2 3 4]


[[0 3 2 1][0 3 2 4][3 2 1 4][2 0 1 3][1 0 3 4][4 2 0 1][4]]

Winning Criterion

This is code-golf so the shortest answer wins.


This is actually based on SO question that I asked, and you can find a Java implementation here : https://stackoverflow.com/questions/28544808/random-distribution-of-items-in-list-with-exact-number-of-occurences


Definition of random : Should I accept output that contain same "subset" array ordered differently? Output format : How can I better define the output expected?

  • \$\begingroup\$ I don't see why you posted this question here if you were to post it to main in an hour without any feedback. \$\endgroup\$
    – Optimizer
    Feb 19, 2015 at 10:09
  • \$\begingroup\$ What next question ? The last sandbox post was 9 hours ago. That one was just lucky that the right people were awake. \$\endgroup\$
    – Optimizer
    Feb 19, 2015 at 10:12
  • \$\begingroup\$ Is the choice of the word "set" deliberate? I.e. must all arrays in the output be unique? \$\endgroup\$ Feb 19, 2015 at 11:02
  • \$\begingroup\$ As for randomness, if you want something decent you should specify that every possible output must be produced with finite probability (barring the finite length of the PRNG's cycle). \$\endgroup\$ Feb 19, 2015 at 11:02
  • \$\begingroup\$ The rules seem to allow me to output a set of one-element arrays, reducing the problem to shuffling y copies of z. \$\endgroup\$ Feb 19, 2015 at 12:19
  • \$\begingroup\$ @MartinBüttner I updated my question with your suggestions. I also specified that differently ordered arrays are not considered the same. \$\endgroup\$
    – Thrax
    Feb 19, 2015 at 12:38
  • \$\begingroup\$ @PeterTaylor You can only output arrays of size different than x in the case n * y is not divisible by x \$\endgroup\$
    – Thrax
    Feb 19, 2015 at 12:39
  • \$\begingroup\$ You should be aware that at some point (probably already) it will be shorter to just generate random outputs and then check for validity (and regenerate as long as it isn't). \$\endgroup\$ Feb 19, 2015 at 12:50
  • \$\begingroup\$ @MartinBüttner You provided a 8 byte CJam implementation, I find that more than satisfying. \$\endgroup\$
    – Thrax
    Feb 19, 2015 at 13:29
  • \$\begingroup\$ @Thrax That isn't valid by the updated rules, as it doesn't produce every possible output and doesn't ensure uniqueness of the arrays. \$\endgroup\$ Feb 19, 2015 at 13:42
  • \$\begingroup\$ @MartinBüttner I could put those 2 (hard) rules as bonus, maybe? \$\endgroup\$
    – Thrax
    Feb 19, 2015 at 13:45
  • \$\begingroup\$ @Thrax That's up to you. I think they change the challenge quite substantially, so I'm not sure if they are suitable for being a bonus, but I don't know. \$\endgroup\$ Feb 19, 2015 at 13:46
  • \$\begingroup\$ @MartinBüttner Java implementation (non-golfed) is 1600 bytes. I don't find that particularily excessive. With an appropriate language, it should be reduced to no more than 300 I think. \$\endgroup\$
    – Thrax
    Feb 19, 2015 at 13:49

Can you reach this chess position?

This is currently a stub. If it makes sense I will write it out.

You should write a program which given a chess position outputs a list of moves (white and black alternating) with which the given position can be reached from the standard starting position. Your goal is to minimize the number of moves.

Input details:

will be in following the format (but of course not the staring position):

  • Inputs will be chosen from random positions of random low-level games (~1200 Elo).
  • You only have to reach the given position with legal moves. You don't have to care if any castling or en-passant was available in the input.
  • You can choose whose turn it is.

Output details:

  • Is a list of [a-f][1-8] [a-f][1-8][qrbn]? ([qrbn]? is for promotion, if there is a standard notation for it, that will be used).

Other details:

  • Running time of your program should not take more than one minute on your computer.
  • Program shouldn't be longer than 50Kb. (this is against hardcoding databases thought that might wouldn't help that much)
  • Standard loopholes are disallowed.


  • Sum of the moves (half-moves) for the 20 provided inputs. If hardcoding happens those are subject to change. If a program can't reach a given input in 1 minute it's score is 300 for that testcase.

Sandbox notes:

A validator would be useful. I can't do a JS snippet but maybe I can hack together a python3 one.

(You don't have to implement castling, en-passant, promotion if you don't want to and still can get a great entry.)

  • \$\begingroup\$ One-minute limit? Is that for arbitrary positions? If so, beware that there are fiendish retrograde analysis problems that would stand up to search strategies. \$\endgroup\$
    – xnor
    Feb 25, 2015 at 1:20
  • \$\begingroup\$ @xnor You don't have to be able to solve 100% of the positions. If you can't solve one you receive 300 points for that one. \$\endgroup\$
    – randomra
    Feb 25, 2015 at 3:52
  • \$\begingroup\$ "one minute on your computer" seems to be a problem - giving an advantage to faster computers. \$\endgroup\$ Feb 25, 2015 at 12:39
  • \$\begingroup\$ I'm contemplating a challenge which will require termination within 30 seconds on any computer, but that requires the code to measure its own runtime. The actually scoring will still all be done on my machine for fairness. \$\endgroup\$ Jun 26, 2015 at 23:14

Find the Point of Maximum Light

Inspired by this program, this challenge is about finding the point where the mouse should be placed, given an input in a form which will be specified later, in order to color the most pixels yellow.

The above link will bring you to a program with a hexagon, a triangle, and a line. When the mouse is moved over the shapes, light rays shine from the mouse and the various shapes absorb the light.

Input is given in this format: [250,200,150,100 250,200,300,120 150,100,300,120] [250,350,350,250] (Compare to the lines array in the aforementioned program). Your program is to assume the perimeter ([0,0,400,0 0,0,0,400 400,0,400,400 0,400,400,400]) is always present.

This is code-golf, so the shortest code wins.

NOTE: please tell me if I can clarify my question.

  • 2
    \$\begingroup\$ I would suggest you make the challenge self-contained... it's nice to have the link as a reference to the inspiration for your challenge, but people should be able to understand how exactly the program is supposed to work without having to follow the link. \$\endgroup\$ Feb 28, 2015 at 16:44
  • \$\begingroup\$ on the link, where does one click in order to run the program? \$\endgroup\$
    – feersum
    Feb 28, 2015 at 16:44
  • \$\begingroup\$ When the link is clicked, you should see a (mostly) black 400 by 400 square on the right. Try mousing over the square. \$\endgroup\$ Feb 28, 2015 at 16:45
  • \$\begingroup\$ Since this is inspired by a mouse pointer based game, I take it the output should be integer, even if half way between two pixels would give greater coverage? \$\endgroup\$ Jun 26, 2015 at 23:25
  • \$\begingroup\$ @trichoplax Yes, the output should be an integer (or rather, two integers). \$\endgroup\$ Jun 28, 2015 at 12:56
  • \$\begingroup\$ I assumed that would be the case, I was just asking so you could clarify the question by editing in a specific output format (or choice of formats). \$\endgroup\$ Jun 29, 2015 at 1:44

Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

I'm not sure how or if this can even work in any language, but I figured I'd toss the idea up here for someone else to flesh out in case it's actually viable.

"Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" is a grammatically correct American English sentence. This is possible because there are three different meanings of the word "buffalo" (or "Buffalo") used in the sentence, and some other words and punctuation are implied rather than explicitly included.

I think this would be a great code challenge to issue, if it is at all possible. It may not be proper for , but that would put an interesting spin on it as well.

The objective would be to create a script or program which is made up only of a single command, or sequence of commands, which is identically repeated throughout the source. No other code is permitted to fill or wrap the repeated piece. Within the script or program, those commands must do something in at least three different ways (or do three totally different somethings) despite being written exactly the same (perhaps with some allowance for deviations in capitalization, such as in the actual sentence) for every iteration.

A fictitious (and obviously invalid) PowerShell example is below.


echo 'buffalo';echo 'buffalo';echo 'buffalo';



(Note: The Output could be easily achieved by simply modifying the capitalization of "buffalo" within the script, but that would be in violation of the spirit of the challenge - such deviations, if permitted at all, should not be allowed in string literals.)

  • 1
    \$\begingroup\$ Have you heard of the language Ook? \$\endgroup\$ Mar 5, 2015 at 16:58

Regex vs HTML

As the Stack Overflowers have been defeated, it is up to the Programming Puzzlers and Code Golfers to fight this final battle against the regex-resisting HTML-hordes. Pick up your flavour of choice and join the melee, with the shortest regex you can achieve (no, not like this)!


Write a regex which takes a html tag, and splits it into tag name, attributes and body. For example, <img src="something.jpg">caption</img> is converted to img, src="something.jpg" and caption. Your regex will be run by the controller against a list of tests. Any regex flavour can be used, as long as there is a driver available (or you want to write your own).


  • The regex should contain at least 4 groups, one each for tag name, tag attributes, tag body (contents) and a group for the html tag matched, which may be group 0 (which will not add to your regex length).
  • Your regex does not need to handle all the test cases, but the more handled, the higher your score.
  • The scoring formula is (100 - log(self.length) * 40) * ((passes - total) / total + 1), but this will be handled by the scoring program. This formula might change, based on how the challenge progresses. A higher score is better.
  • For your regex, you must specify the driver you use (the name in square brackets), any flags and the group names or numbers that hold the split bits. Flags do not contribute towards regex length.


  • Your program will be run over 30 tests (more may be added) by the scoring program, and the number of passes counted.
  • Length is in bytes.
  • Your score then is (100 - log(length) * 40) * ((passes - total) / total + 1), but this will be handled by the scoring program. This formula might change, based on how the challenge progresses.
  • Types of html that you can score points on (remember not all need to be handled):

    • Paired html tags - <a>b</a>
    • Tags with the self-closing syntax - <br/>
    • Quoted attributes (using either single or double quotes) - <a href='mysite.com'>b</a>
    • Unquoted attributes - <b strength=1>msg</b>
    • Empty or boolean attributes - <input disabled/>
    • Comments (tag name is !--, attrs is empty, body is the text of the comment) - <!-- Something important -->
    • DOCTYPE sections (tag name is !DOCTYPE, body is the following text) - <!DOCTYPE html>
    • CDATA sections (tags inside ignored) - <![CDATA[<br/>]]>
  • Example tests (one on each line, full list of tests and answers):

    <a href='mysite.com'>b</a>
    <a href='mysite.com' color="blue" height=1>b</a>
    <quote href="http://somewhere.com">"he said this"</quote>
    <div class="quote">The answer is <div id='the-answer'>42</div></div>
    <input text='Your name:' focused/>
  • Answers to examples (one on each line):

    Name   Attrs                                    Body                                         Matched
    a                                               b                                            <a>b</a>
    a      href='mysite.com'                        b                                            <a href='mysite.com'>b</a>
    a      href='mysite.com' color="blue" height=1  b                                            <a href='mysite.com' color="blue" height=1>b</a>
    quote  href="http://somewhere.com"              "he said this"                               <quote href="http://somewhere.com">"he said this"</quote>
    div    class="quote"                            The answer is <div id='the-answer'>42</div>  <div class="quote">The answer is <div id='the-answer'>42</div></div>
    b                                               x                                            <b>x</b>
    input  text='Your name:' focused                                                             <input text='Your name:' focused/>
  • There is a timeout for the regex matching (currently 5 seconds, but this may change depending on the number of submissions), so if you are making a bit / computationally expensive regex, use a fast driver. The tests will be run on a 2013 MacBook Air, most likely single threaded (although 4 cores are available).


Contributions of drivers is much appreciated. See the instructions on github.com.


Name                          Length    Score     Passes    Fails     Timeouts  Errors    
Naive                         68        10.6799   12        18        0         0         


Sandbox Questions

  • Is the scoring formula fair?
  • Is this too easy / hard?
  • Would abstracting the controller a bit more allow the controller and drivers be useful for scoring other challenges? Would anybody want to use it?
  • There is currently a python and a perl driver. Are there any other major regex flavours that should be supported, or should I wait and see until after the sandbox?
  • Is there any parts of the challenge that are a bit clunky and need rewriting?
  • Could someone add this to the listing at the top?
  • Anything I've missed?
  • \$\begingroup\$ I think this needs the full HTML spec for what a tag can look like. Because you'd be surprised... Also, I'm not a fan of the restriction to a single regex flavour. That's like a language restriction in any other challenge, and usually not a good idea. \$\endgroup\$ Jan 17, 2015 at 15:27
  • \$\begingroup\$ In particular (afaik) it doesn't cover the interesting ones, like recursion and balancing group. But mainly, I just think it's gonna put off people who don't know the flavour (even if it's similar to theirs), because they'll have to look it up. \$\endgroup\$ Jan 17, 2015 at 15:36
  • 1
    \$\begingroup\$ When you say "HTML", what do you mean? IMO this would be a much more reasonable challenge if you restrict it to XHTML and thus remove the need to handle auto-closing <li>, <p>, etc. tags. I agree with @MartinBüttner that some formal spec would be useful, because although the example he links to is invalid, the fact that Optimizer got away with claiming that it was valid suggests that other people may try similar nonsense. \$\endgroup\$ Jan 17, 2015 at 15:45
  • 2
    \$\begingroup\$ I have nowhere in my answer mentioned that my answer is following proper HTML W3C spec. Instead, my answer was more on using the loose behavior of browsers parsing an HTML page. \$\endgroup\$
    – Optimizer
    Jan 17, 2015 at 17:20
  • \$\begingroup\$ The edits still don't address the biggest problem with this question, which is a failure to state which HTML spec to follow. Adding a set of test cases doesn't really finesse that, especially since you say that you may add test cases later. \$\endgroup\$ Feb 27, 2015 at 18:12
  • \$\begingroup\$ @PeterTaylor Is that better? \$\endgroup\$
    – matsjoyce
    Feb 28, 2015 at 12:19
  • \$\begingroup\$ The note to self indicates that you're specifically after HTML5 syntax. If you state that explicitly in the question itself then I will be perfectly satisfied. \$\endgroup\$ Mar 2, 2015 at 12:17
  • \$\begingroup\$ @PeterTaylor Well, it's HTML 5 syntax without the optional tags section. I listed those under the testing section. \$\endgroup\$
    – matsjoyce
    Mar 2, 2015 at 13:34
90 91
93 94

You must log in to answer this question.

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