Jump to content

contest


Guest zeyad etman
 Share

Recommended Posts

Here's one. Given a string that contains a book or movie title, rewrite it using the normal American capitalization rules for titles. Here are the rules:1. Only the first letter of a word can be uppercased, unless it is a name that has a unique format (like St. James as a family name).2. The first and last words of a title must have the first letter uppercased. This rule always applies.3. Articles (a, an, the) must not be uppercased unless rule 2 applies.4. Prepositions (on, by, under, through, etc. -- it's a big list) must not be uppercased unless rule 2 applies.5. Coordinating conjunctions (and, but, or, nor, for, so, yet -- that is the complete list) must not be uppercased unless rule 2 applies.6. The second part of a hyphenated word (like U-Boat) must be uppercased unless rule 3, 4, or 5 applies.7. A word following a colon ( : ) must be uppercased. This rule always applies.Example: Transform into the mind of a killer: the life and times of william st. jurmain to Into the Mind of a Killer: The Life and Times of William St. JurmainThe entry that works correctly and uses the fewest JavaScript statements wins. (So 3 statements on one line count as 3 statements.) If the procedure is a function, the function declartion does not count as a statement. A statement using a single ternary operator ( ? : ) counts as 3 statements. (My puzzle, my rules.)Entries must be submitted by Monday 00:00GMT (ie, Sunday midnight in London).

Edited by Deirdre's Dad
Link to comment
Share on other sites

The problem with programming contests is that the tasks are usually somewhat isolated. That is to say, with limited practical use. Not exactly the case in the example Deirdre's Dad gave, but it's not easy to constantly come up with different kind of tasks.IT exercises in contests (I've been part of two, so I can tell you from first hand experience) are generally of about a dozen kinds that are repeated every year with some tweaks. So, to take the above example, in year one would be that, while the next year it might be the same, but without rule 4, and/or with rule 2 not being applied always.Still... let's see how long we can keep this up... and how many different people will participate... 'cause let's face it, the regular responders, not counting the moderators, are not that many.

Link to comment
Share on other sites

When I got my first PC I played Nethack for HOURS, everyday. Some of the younger board members might not get how a thing like that could be fun, but it was.
Sometimes the simplest games can be the most entertaining. Like Snake for example. Or Nibbles or one of many other names that it goes by...:)
Link to comment
Share on other sites

Here's a more easier question :)With 2 for loops generate this pattern11212312341234512345612345671234567812345678912345678910...so onLeast amount of statements win. using only PHP(echo) or Javascript(write).
can I just do it in one? :) Edited by thescientist
Link to comment
Share on other sites

Yeah, it's easier with one:

$str = '1';for ($i=2; /*BTW, where does this end?*/; $i++) {echo $str, '\n';$str .= $i;}

OK, with two...

$str = '';for ($i=1;$i=2;$i++) {	$str .= '1';}for ($i=2; /*BTW, where does this end?*/; $i++) {	echo $str, '\n';	$str .= $i;}

[edit]Added the newlines in both samples... thanks DD.[/edit]And that tells you why in actual contents, there's never a style requirement, beyond unambigious stuff like "it must not create warnings" - because you can always alter one algoritm to style requirements, but doing that is just a waste of time, which is especially important if time is short.

Link to comment
Share on other sites

I think I misunderstood the puzzle at first. I transposed the final 1 and 0 in the last line and thought we were going back to 0, not continuing with 10, which seems to be the actual pattern. The following does that. (I stopped at 20.)

for (var i = 0; i <= 20; ++i) {   for (var j = 0; j <= i; ++j) {	  document.write(j + 1);   }   document.write("<br>");}

Link to comment
Share on other sites

I think I misunderstood the puzzle at first. I transposed the final 1 and 0 in the last line and thought we were going back to 0, not continuing with 10, which seems to be the actual pattern. The following does that. (I stopped at 20.)
for (var i = 0; i <= 20; ++i) {   for (var j = 0; j <= i; ++j) {	  document.write(j + 1);   }   document.write("<br>");}

Ah... if there was a memory limit requirement (that's unambiguous for you), then this would be the solution indeed.
Link to comment
Share on other sites

I think I misunderstood the puzzle at first. I transposed the final 1 and 0 in the last line and thought we were going back to 0, not continuing with 10, which seems to be the actual pattern. The following does that. (I stopped at 20.)
for (var i = 0; i <= 20; ++i) {   for (var j = 0; j <= i; ++j) {	  document.write(j + 1);   }   document.write("<br>");}

Well done :) That's exactly what I have except mine is PHP for ($i = 0; $i <= 900; $i++) { for ($j = 1; $j <= $i+1; $j++){ echo $j; } echo "<br />";}Lol 900.
Link to comment
Share on other sites

well, I'm doing it one

for(var i = 1, x = 2, z = ""; i < x; i++){  print( (z += i.toString()) );  x++;};

Edited by thescientist
Link to comment
Share on other sites

Add a memory limit :)
A little too late for this particular instance, wouldn't you say :)If you have a memory limit, it needs to be an actual number or at least a measurable thing, like "not counting the memory of the engine itself, the script must not use up more than additional 1KB, with the script ending at the 1 milionth iteration."... try to pull that off with my solutions, and you'll fail.
Link to comment
Share on other sites

Here's one. Given a string that contains a book or movie title, rewrite it using the normal American capitalization rules for titles. Here are the rules:1. Only the first letter of a word can be uppercased, unless it is a name that has a unique format (like St. James as a family name).2. The first and last words of a title must have the first letter uppercased. This rule always applies.3. Articles (a, an, the) must not be uppercased unless rule 2 applies.4. Prepositions (on, by, under, through, etc. -- it's a big list) must not be uppercased unless rule 2 applies.5. Coordinating conjunctions (and, but, or, nor, for, so, yet -- that is the complete list) must not be uppercased unless rule 2 applies.6. The second part of a hyphenated word (like U-Boat) must be uppercased unless rule 3, 4, or 5 applies.7. A word following a colon ( : ) must be uppercased. This rule always applies.Example: Transform into the mind of a killer: the life and times of william st. jurmain to Into the Mind of a Killer: The Life and Times of William St. JurmainThe entry that works correctly and uses the fewest JavaScript statements wins. (So 3 statements on one line count as 3 statements.) If the procedure is a function, the function declartion does not count as a statement. A statement using a single ternary operator ( ? : ) counts as 3 statements. (My puzzle, my rules.)Entries must be submitted by Monday 00:00GMT (ie, Sunday midnight in London).
How 'bout this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Text Transformer</title><script type='text/javascript'>//<![CDATA[window.onload = function() {	document.getElementById("transformBtn").onclick = function() {transform(document.getElementById("inputValue").value)};}function transform(text) {	var exclusions = new Array('a', 'aboard', 'about', 'above', 'absent', 'across', 'after', 'against', 'along', 'alongside', 'an', 'and', 'amid', 'amidst', 'among', 'amongst', 'around', 'as', 'aside', 'astride', 'at', 'athwart', 'atop', 'barring', 'before', 'behind', 'below', 'beneath', 'beside', 'besides', 'between', 'betwixt', 'beyond', 'but', 'by', 'circa', 'concerning', 'despite', 'down', 'during', 'except', 'excluding', 'failing', 'following', 'for', 'from', 'given', 'in', 'including', 'inside', 'into', 'is', 'like', 'mid', 'midst', 'minus', 'near', 'next', 'nor', 'notwithstanding', 'of', 'off', 'on', 'onto', 'opposite', 'or', 'out', 'outside', 'over', 'pace', 'past', 'per', 'plus', 'pro', 'qua', 'regarding', 'round', 'save', 'since', 'so', 'than', 'the', 'through', 'thru', 'throughout', 'thruout', 'to', 'toward', 'towards', 'under', 'underneath', 'unlike', 'until', 'up', 'upon', 'versus', 'vs.', 'via', 'vice', 'with', 'within', 'without', 'worth', 'yet');		text = text.toLowerCase();	var words = text.split(/\s{1,}/);		var newSentence = '';	for (x=0; x<words.length; x++) {		if ((!in_array(words[x], exclusions)) || (x == 0) || (x == words.length)) {			if (words[x].search('-') != -1) {				var tmp = words[x].split('-');				if (!in_array(tmp[1], exclusions)) {					tmp[1] = tmp[1].replace(tmp[1].charAt(0), tmp[1].charAt(0).toUpperCase());				}				words[x] = tmp[0].toUpperCase()+'-'+tmp[1];			} else {				words[x] = words[x].replace(words[x].charAt(0), words[x].charAt(0).toUpperCase());			}		}		if (newSentence != '') {			newSentence += " ";		}		newSentence += words[x];	}		var patt = /(:\s*)([A-z])/g;	var currMatch = patt.exec(newSentence);	while (currMatch) {		newSentence = newSentence.replace(currMatch[0], currMatch[1]+currMatch[2].toUpperCase());		currMatch = patt.exec(newSentence);	}		document.getElementById("outputValue").innerHTML = newSentence;}function in_array(val, arr) {	var blnExists = false;	if (typeof(arr) == 'object') {		for (y in arr) {			if (arr[y] == val) {				blnExists = true;				break;			}		}	}	return blnExists;}//]]></script><style type='text/css'>textarea {	display: block;}textarea, button {	margin-bottom: 15px;}#outputValue {	width: 400px;	height: 40px;	border: 3px inset #CCCCCC;}</style></head><body><div>Input:</div><textarea id='inputValue' rows='3' cols='45'>into the mind of a killer: the life and times of william st. jurmain</textarea><button id='transformBtn'>Transform!</button><div>Output:</div><div id='outputValue'></div></body></html>

Certainly it's not perfect but I think its ok. 'Course someone will probably pop in and blow my entry out of the water, but at least I tried. :)

Edited by ShadowMage
Link to comment
Share on other sites

well, I'm doing it one
for(var i = 1, x = 2, z = ""; i < x; i++){  print( (z += i.toString()) );  x++;};

BTW, scientist, you fail. :)Yours creates an infinite loop of print dialog popups. It should look like this:
for(var i = 1, x = 20, z = ""; i < x; i++){  document.write( (z += i.toString())+"<br />" );};

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...