Programming contest at EggHeadCafe…

EggHeadCafe is running a programming contest.

The Swedish Chef is a character from the old Muppet Show that was broadcast in the 1970s. The Chef speaks his own language (an amalgam of Swedish, English, and who knows what else), and your task is to design and implement a class library  to translate English text into the Chef’s language.

Looks interesting, and fairly straighforward to solve. But can you do it elegantly?

Oh, and there’s a cash prize to the winner…

Comments (12)

  1. jond says:

    google has a Swedish Chef language tranlation page:

  2. Rob Windsor says:

    With enough beer in me I sound like the Swedish Chef. It’s a very straightforward solution but no one has ever called it elegant.


  3. Sean Chase says:

    Mine is elegant because it leverages the power of SOA. Just kidding, it’s a nasty hack that I thought you might find amusing. 🙂

    using System;

    using System.Net;

    using System.Text;

    using System.IO;

    class Chef


    public static string Convert(string text)


    WebRequest request = HttpWebRequest.Create("");

    request.Method = "POST";

    string postData="dialect=bork&text=" + text;

    ASCIIEncoding encoding = new ASCIIEncoding();

    byte[] bytes = encoding.GetBytes(postData);


    request.ContentLength = postData.Length;

    Stream requestStream = request.GetRequestStream();

    requestStream.Write(bytes, 0, bytes.Length);


    HttpWebResponse objResponse = (HttpWebResponse) request.GetResponse();

    string result = String.Empty;

    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))


    result = sr.ReadToEnd();



    int start = result.IndexOf("</h2></center><p>") + "</h2></center><p>".Length;

    int end = result.IndexOf("<p><br><hr>", start);

    return result.Substring(start, end – start);



    class App



    static void Main(string[] args)


    string value = Chef.Convert("This is the greatest hack ever!");




  4. The specification for the language conversion is annoying in its ambiguousness. Taking just one example, the word "the", fits several rules, "5. If there is an e at the end of the word, replace it by e-a.", and "7. Replace all occurrences of the by zee.". So while their example shows that "Do you know the way to San Jose?" translates into "Du yuoo knoo zee vey tu Sun Juse-a? Bork bork bork!" then "zee" should rather have been "zee-a", if we presume all fitting rules are to be applied. I am sure it shouldn’t be too difficult to find other ambiguities if one is fluent in English.

    Furthermore, a slight oversight, most likely, is the fact that they say that all paragraphs or sentences should end with "Bork bork bork." and yet in their examples they write "Bork bork bork!".

    While I do enjoy occasional programming contests, this one seems to have been specified without giving much thought to the actual specification. It rather feels like some of the software projects at work, really.

    Otherwise a solution could elegantly be made using the visitor pattern or the poorly named pattern for those who read the conversations articles by Hyslop and Sutter in the C/C++ User Journal.

    Thanks for the heads-up though, but the hurt of "thees" ambiguousness is too much for my fragile compiler implementor heart. 🙂

  5. Sheeshers says:

    The ambiguities are galore. With multiple rules applying to the same set of characters, what is the sequence in which we apply them?

    I really invested some serious time before I came to the conclusion that I would have to make some real heavy assumptions on the sequencing of the rules, the priorities in case of ties (such as the rules that apply to the character ‘e’) etc.

    I wasn’t trying to do it for the money obviously, but it seemed challenging until I got down to organizing the rule set.

    C’mon guys…define it correctly. Another thing is .. the winner is the first solution that is "correct" .. okay how does one know correct simply by looking at that ambiguous example that itself can have multiple translations.

  6. daveg says:

    I feel the same about the rules.

    And provide some decent examples – like paragraphs. The examples they provide don’t even exercise a lot of their rules.

  7. I’m glad to see some interest in our concept. The key here is not to sweat the small stuff. What we’re looking for is elegance of code, quality OOP oriented principals, and innovation.

    Obviously, a hack to somebody’s elses webservice won’t cut it…

    Thanks, Eric for the mention.