Welcome to MSDN Blogs Sign in | Join | Help

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

Published Wednesday, December 01, 2004 9:04 AM by ericgu
Filed under: ,

Comments

Wednesday, December 01, 2004 9:48 AM by jond

# re: Programming contest at EggHeadCafe...

google has a Swedish Chef language tranlation page: http://www.google.com/intl/xx-bork/
Wednesday, December 01, 2004 10:00 AM by Rob Windsor

# re: Programming contest at EggHeadCafe...

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.

Rob
Wednesday, December 01, 2004 10:45 AM by Sean Chase

# re: Programming contest at EggHeadCafe...

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("http://rinkworks.com/dialect/dialectt.cgi");
request.Method = "POST";
string postData="dialect=bork&text=" + text;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(postData);
request.ContentType="application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

HttpWebResponse objResponse = (HttpWebResponse) request.GetResponse();
string result = String.Empty;
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
sr.Close();
}

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
{
[STAThread]
static void Main(string[] args)
{
string value = Chef.Convert("This is the greatest hack ever!");
Console.WriteLine(value);
}
}
Wednesday, December 01, 2004 2:10 PM by TheChaseMan's Frenetic SoapBox

# Swedish Chef Translation Contest

Wednesday, December 01, 2004 12:15 PM by Henrik Stuart

# re: Programming contest at EggHeadCafe...

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. :)
Wednesday, December 01, 2004 1:34 PM by Sheeshers

# re: Programming contest at EggHeadCafe...

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.
Wednesday, December 01, 2004 3:07 PM by daveg

# re: Programming contest at EggHeadCafe...

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.
Wednesday, December 01, 2004 7:01 PM by Peter Bromberg

# re: Programming contest at EggHeadCafe...

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.
peter
Tuesday, December 07, 2004 11:52 AM by Geek Noise

# Geek Notes 2004-12-07

# Eric Gunnerson s C Compendium Programming contest at EggHeadCafe | Cast Iron Cookware

# Eric Gunnerson s C Compendium Programming contest at EggHeadCafe | Paid Surveys

New Comments to this post are disabled
 
Page view tracker