20
\$\begingroup\$

Last month's community-challenge spawned a lot of Calculators. April is history and the success of last month definitely asks for a new challenge.

What should we do this time? Feel free to resubmit non-winning ideas from previous rounds, although new ideas are usually more successful.

  • Post an answer to this question with your challenge
  • Vote for those answers which interest you
  • At the end-of-day on Friday, May 8th, the most-voted post will become the next .

Once the challenge topic is decided, you can post questions on the main-site related to the challenge. The idea is to run the challenge all the way through May... although nothing stops you from posting an "entry" later than that :)

Disclaimer: Most of this text is borrowed from Mat's Mug.

\$\endgroup\$
  • \$\begingroup\$ If someone posts an interesting challenge but it does not win, will other people be upset if that someone posts the code for the challenge they found interesting, and not code for the challenge that won? \$\endgroup\$ – SirPython May 6 '15 at 20:09
  • 2
    \$\begingroup\$ @SirPython No. Feel free to use whatever ideas are posted to write fascinating code. \$\endgroup\$ – Mast May 6 '15 at 20:41
  • 1
    \$\begingroup\$ @SirPython You can write whatever, but I don't think you can tag it CC. \$\endgroup\$ – Hosch250 May 6 '15 at 20:42
  • \$\begingroup\$ I believe I created a perfect example of ugliest code ever, would it be suitable to be considered for the challenge ? codereview.stackexchange.com/questions/90371/… \$\endgroup\$ – Mathematics May 11 '15 at 9:56
22
\$\begingroup\$

BattleShip!

Resubmission from weekend-challenge #3; simple and fun :-)

Everyone has played Battleship. Let's implement the logic that sinks one.

  • Ship has multiple "hit points" located at contiguous (x,y) coordinates, horizontally or vertically.
  • Ship is sunken when all "hit points" are hit.

Challenge entries

\$\endgroup\$
  • 9
    \$\begingroup\$ We could combine the server idea with this one and have an online tournament with Battleship bots playing each other. :) \$\endgroup\$ – Edward May 1 '15 at 16:13
  • 2
    \$\begingroup\$ @Edward That is something I would like to see very much. \$\endgroup\$ – Simon Forsberg May 1 '15 at 18:20
23
\$\begingroup\$

StackSTV

Stack Exchange uses an STV-based system for holding elections. They use the software OpenSTV to host it.

That software is no longer being maintained, and the system is being rebranded as OpaVote, and will no longer be free.

This month's challenge:

Build an implementation of the same STV algorithm used for Stack Exchange moderator elections, that consumes data in the same format that Stack Exchange provides, and produces the same results.

Algorithm

The actual algorithm use is linked in this Meta.StackExchange question/answer: How are moderator election votes counted, in plain English?

Specifically, using the "Meek STV" algirithm here - in Wikipedia.

Inputs

For examples of input data, see: Stack Overflow Elections

Typical data looks something like:

10 3
1 1 2 3 0
1 4 5 6 0
1 6 7 2 0
1 3 6 1 0
1 6 8 4 0
1 6 3 2 0
1 4 1 9 0
1 8 9 3 0
1 8 7 3 0
....
1 8 2 1 0
1 9 4 6 0
1 4 8 3 0
1 3 4 8 0
1 4 5 10 0
0
"meagar"
"Raghav Sood"
"Bohemian"
"0x7fffffff"
"Undo"
"bluefeet"
"Matt"
"Jon Clements"
"Siddharth Rout"
"Doorknob"

The format is essentially:

  • The number of candidates, and seats on the first line - 10, and 3 represent there are 10 candidates, and 3 positions.
  • a list of any candidates that have withdrawn preceded with a negative number - one per line (Stack Exchange won't have these, likely).
  • a count of people with a specific combination of votes For example, in the first line: 1 1 2 3 0 that means that one person voted with the combination first-choice candidate 1, second choice candidate 2, third choice candidate 3. The 0 represents the end of that line. Note that combinations can be duplicated, potentially.
  • a zero on a line by itself represents the end of the vote section.
  • following that, is the names of the candidates, in the order of the choices.

Feel free to implement it in the language of your choice, and to embellish it with GUI, graphs, charts, etc.

\$\endgroup\$
  • 1
    \$\begingroup\$ And how exactly does the STV algorithm work? I guess we are pretty limited with regards to this here. \$\endgroup\$ – Simon Forsberg May 7 '15 at 15:44
  • 1
    \$\begingroup\$ @SimonAndréForsberg Start here: en.wikipedia.org/wiki/Single_transferable_vote \$\endgroup\$ – Chris Jester-Young May 7 '15 at 15:46
  • 1
    \$\begingroup\$ @SimonAndréForsberg We use Meek STV, specifically: dia.govt.nz/DIAWebsite.nsf/0/…. There's a link to a paper describing the algorithm there. \$\endgroup\$ – Adam Lear May 7 '15 at 15:47
  • \$\begingroup\$ If the user requirements can be made more clear (MoSCoW anyone), I'll definitely support this for the next challenge. \$\endgroup\$ – Mast May 7 '15 at 15:48
  • \$\begingroup\$ Note: this is a neat idea for a challenge, but it's not dire and required for our moderator elections. OpaVote has been OpaVote for a while now (a couple years?), and we are licensed to continue distributing the old free version of the OpenSTV software which works just fine. :) \$\endgroup\$ – Adam Lear May 7 '15 at 15:52
  • 1
    \$\begingroup\$ @AnnaLear - that may be true, but as individuals it is also nice that we can have our own way of processing, and reprocessing the data. \$\endgroup\$ – rolfl May 7 '15 at 15:53
  • 3
    \$\begingroup\$ @rolfl Definitely. I just don't want anyone to have a false sense of urgency here. \$\endgroup\$ – Adam Lear May 7 '15 at 15:54
  • \$\begingroup\$ Oh, this will definitely spawn some code. Perhaps even usable code :) \$\endgroup\$ – Mast May 7 '15 at 15:58
  • 2
    \$\begingroup\$ Why would you develop new software? Why not contribute to the maintenance of OpenSTV? \$\endgroup\$ – Gilles May 7 '15 at 15:59
  • 3
    \$\begingroup\$ @gilles because that is what these challenges are about \$\endgroup\$ – rolfl May 7 '15 at 16:02
  • 2
    \$\begingroup\$ @AnnaLear will voting for this challenge make our own elections happen any faster? ;-) \$\endgroup\$ – Mathieu Guindon May 8 '15 at 18:57
  • 6
    \$\begingroup\$ @Mat'sMug Not my department. ;) \$\endgroup\$ – Adam Lear May 8 '15 at 18:58
  • 3
    \$\begingroup\$ How it comes that an internet site gets a much fairer and more sensible voting system than most democracies? \$\endgroup\$ – maaartinus May 15 '15 at 20:26
  • 1
    \$\begingroup\$ @maaartinus - I was thinking that for future community challenges we should use the STV system to vote for them ;-) \$\endgroup\$ – rolfl May 15 '15 at 20:27
15
\$\begingroup\$

Write an automated code reviewer

Long time reviewers of code here often see the same problems and make the same comments on code in various different languages. Write a program to create a review for code in and for the language of your choice. For example, you might want to write a Python script that looks at C# code for common problems and creates a plausible (if incomplete) code review.

Note that this wouldn't need to be anything more complicated than looking for one or two specific possible problems without duplicating an entire language parser. For example, one could write a very simple script to look for the keyword const in a C or C++ program. Failure to find even one instance might trigger automated output something like this:

No instances of const were found in the program. It's good practice to mark variables and member functions as const to tell both the compiler and the human reader of your code that the item will not be altered.

We will always benefit from a human reviewer, but software that examines other software has a long history.

\$\endgroup\$
  • 13
    \$\begingroup\$ This is a huge problem to tackle for a community challenge, don't you think? I've been working on a project that has this as one of it's core features. We're almost 1000 commits in and it's just now returning consistent results. \$\endgroup\$ – RubberDuck May 1 '15 at 14:56
  • 1
    \$\begingroup\$ It depends on the approach. Obviously, if you're going to rewrite the entirety of lint, it's a huge problem, but it's relatively simple to look for certain things, such as unreferenced variables or missing includes. I'm proposing something much more like the latter than the former. \$\endgroup\$ – Edward May 1 '15 at 14:59
  • 1
    \$\begingroup\$ Maybe it depends a bit on the language and it's scoping rules, but finding unused variables isn't as simple as it seems at first glance. Regardless, this challenge gets my vote just because it's so very much in the spirit of what we do here. \$\endgroup\$ – RubberDuck May 1 '15 at 15:01
  • 5
    \$\begingroup\$ This would be incredibly helpful, but is also incredibly difficult to get "right" and useful. In one way, the strength of Code Review is the humans behind it. \$\endgroup\$ – Simon Forsberg May 1 '15 at 18:20
  • \$\begingroup\$ It is not so hard IMO, I wrote one very simply codereview.stackexchange.com/questions/73554/… \$\endgroup\$ – Caridorc May 4 '15 at 17:39
13
\$\begingroup\$

Write any kind of server.

Examples are:

Implementing servers and network communication is a very important programming skill. You are likely to sooner or later be faced with concurrency issues, compatibility issues (old clients connecting to a new server after a protocol change) and the always famous issues.

Requirements:

  • It needs to be able to handle multiple clients simultaneously.
  • It needs to listen on at least one port
  • It preferably should be able to handle at least a few different kinds of messages/requests from clients (such as "Make move", "Start game", "Get file", "Get a list of XYZ"...)
\$\endgroup\$
  • \$\begingroup\$ Probably need to refine the requirements a little bit more... will we accept entries using an embedded third-party web server (e.g. Jetty), write some simple request/reply APIs on it and call it a day? Since you mentioned 'protocol', will the protocol specification be part of the challenge too? \$\endgroup\$ – h.j.k. May 2 '15 at 5:56
  • 2
    \$\begingroup\$ @h.j.k. In that case, I would say that Jetty is the server, and that's already written. There is no requirement on the protocol, you can use an existing protocol if you want to or make up your own. \$\endgroup\$ – Simon Forsberg May 2 '15 at 11:12
6
\$\begingroup\$

Blackjack

Yes, the card game. No, hear me out!

As with many classic programming challenges, there's a deck of cards (usually several!) and shuffling and perhaps sorting involved. That's always fun. And there's all the cardshark jargon :)

At its most basic, there's the trickery of an Ace being worth either 1 or 11, so you sometimes need to track two possible scores for a hand.

Then there's the asymmetry in that there are two "players", but one is the dealer who must draw cards until a score of 17 or higher is reached. Perfectly simple rules for a computer to follow.

Now, while Blackjack is basically about getting closest to 21 without going over, there are many other rules that can be respected or ignored as one sees fit (the title above links to Wikipedia's article on Blackjack, where you'll find lots of stuff).

For the more adventurous there's "splitting": A hand of two cards of equal value may be split into two separate hands. And, depending on the hands and the rules you use, you might then split those two hands again. And while face cards are all worth 10, some rulesets do treat them differently when splitting.

Also, the original "blackjack" meant specifically Ace of Spades + a Jack, but nowadays it usually just means Ace + 10. And by the way, a blackjack is worth 21, but still beats non-blackjack hands worth 21, so straight-up numerical comparison isn't quite enough.

And then there's doubling down: Doubling your bet and receiving exactly 1 more card, but no more.

There's also "insurance" which is a side-bet on the dealer having a blackjack. This makes more sense in a real-life game where the dealer draws a hole card, and the player can attempt to "read" the dealer like in poker. Here, the dealer will probably be your inscrutable computer (since it's no fun to play as the dealer), so insurance probably isn't that interesting. Unless your program is counting cards, perhaps?

In terms of overall scope, there are many options:

  • A full game with a dealer and 1 or more positions for the player to play and configurable rules.

  • A game that plays itself, learning the best actions to take for a given hand over time, maybe? Tables for the best strategies for given hands already exist, so you can check your results.

  • A card counting program that plays the game like Rain Man. It can just track the most likely card to come up next, or think several moves ahead, including splits and doubling down, or tricking the dealer into busting. Just don't bring it near a casino if you value your health.

  • A simple game of blackjack against the computer (just hit/stand; no splitting/doubling down etc.).

  • A simple scoring function for two or more cards.

And anything in between.

In all, there's should be meat here for any skill level. The house wins.

\$\endgroup\$
  • \$\begingroup\$ The house wins. We all win. With such a varying skill cap, everyone can play. \$\endgroup\$ – Mast May 4 '15 at 7:00
  • 1
    \$\begingroup\$ I like this. I haven't built a blackjack game since I was first really learning to code. We should definitely resubmit this next month. \$\endgroup\$ – RubberDuck May 7 '15 at 11:09
  • 1
    \$\begingroup\$ @RubberDuck Yeah, that's the thing. It works as a simple programming exercise, but there are a bunch of bells and whistles you can add to it. Especially if you want to analyze the game too. Card games in general provide fertile ground for challenges, I think. \$\endgroup\$ – Flambino May 8 '15 at 18:13
  • \$\begingroup\$ Agreed. You should definitely re-submit this. \$\endgroup\$ – RubberDuck May 8 '15 at 18:14
5
\$\begingroup\$

The 1-2-3 solitaire

For beginners:

Given a deck of Napoletan cards (ignoring suits), you

  • Take away the first one and say 'one', if the value of the card is one you lose
  • Take away the second one and say 'two', if the value of the card is two you lose
  • Take away the third one and say 'three', if the value of the card is three you lose
  • Take away the fourth one and say 'one', if the value of the card is one you lose
  • ...

If you end-up the deck you win.

Stretch goal

  • Allow support for 1-to-n solitaires
  • Run a big number of simulations for different solitaires and see how often you win and which solitaire numbers are easier/harder than which.
\$\endgroup\$
  • \$\begingroup\$ This sounds quite easy. Sounds almost like a programming-challenge \$\endgroup\$ – Simon Forsberg May 4 '15 at 19:47
  • 1
    \$\begingroup\$ @SimonAndréForsberg but it is not, in fact my cousin taught me this solitaire, also I think we should encourage novice programmers posting \$\endgroup\$ – Caridorc May 4 '15 at 19:51
  • 3
    \$\begingroup\$ @Caridorc We should encourage novice programmers to post decent, re-viewable questions. I think this fits the bill, since it's basically a more complex version of fizzbuzz \$\endgroup\$ – Mast May 6 '15 at 8:04
4
\$\begingroup\$

Resurrect the Stack Eggs!

If you missed them:

stack egg

  • User must make a selection each round before a 20 second timer finishes
  • The site has three stages: private beta, public beta, and launched
  • Private beta has the options to Ask and Answer
  • Public beta has the options to Ask, Answer, Upvote, and Downvote
  • Launched has the options to Ask, Answer, Upvote, Downvote, and Close
  • All levels have the option to do Nothing and to Restart
  • All levels except private beta can Flag to set all stats lower than 1 to 1
  • Flag can only be used once each level
  • Ask and Answer improve the Questions, Answers, and Users stats by 1, 1, and .5
  • Upvote improves the Users stat by 1
  • Downvote lowers the Users stat and improves the Quality stat by 1 each
  • Close lowers the Users stat and improves the Quality stat by 2 each
  • The number of people playing influences the number of votes needed each round (optional for this challenge?)
  • Once all the stats reach level 100, the game advances to the next level.
  • You can view the original source here and make it as similar as you like.

I modified it somewhat, feel free to simplify for the challenge/correct any mistakes.

\$\endgroup\$
  • 8
    \$\begingroup\$ How about we combine Cookie Clicker, Minecraft, and StackEgg into one standalone application and then wave goodbye to life? \$\endgroup\$ – Rainbolt May 1 '15 at 18:59
  • 1
    \$\begingroup\$ @Rainbolt Well, why not? \$\endgroup\$ – Hosch250 May 1 '15 at 19:22
  • 2
    \$\begingroup\$ Where are my unicorns? \$\endgroup\$ – Morwenn May 4 '15 at 14:37
2
\$\begingroup\$

Write your own web server.

Lightweight or all powerful? Easily deployable or extra security versus DDoS attacks? Give it the features you want!

What qualifies as a web server? Any script or program which can do the following:

  • Listen on at least one port
  • Handle the basic errors
  • Handle at least GET, POST, PUT and DELETE
  • Output a confirmation in some form indicating a request has been properly handled

All web servers should be able to be tested locally and have a list of every required dependencies (if applicable).

Of-course, you can make your server as small or as heavy as you want. This is Code Review, you know how it works.

\$\endgroup\$
  • 2
    \$\begingroup\$ Oh dear... this seems.... big. How about writing any kind of server? Be it a chat server, web server, or a Tic Tac Toe Game Server ? \$\endgroup\$ – Simon Forsberg May 1 '15 at 12:13

You must log in to answer this question.

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