Guest zeyad etman Posted September 23, 2010 Report Share Posted September 23, 2010 What do you think holding a contest every week to learn programming languages Quote Link to post Share on other sites
jeffman 86 Posted September 23, 2010 Report Share Posted September 23, 2010 Could be fun. Some of the regulars might set up a schedule for posting little puzzles, like how to do X in 6 lines of JavaScript or less. It might fall apart after a few weeks . . . Quote Link to post Share on other sites
jeffman 86 Posted September 23, 2010 Report Share Posted September 23, 2010 (edited) 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 September 23, 2010 by Deirdre's Dad Quote Link to post Share on other sites
boen_robot 107 Posted September 23, 2010 Report Share Posted September 23, 2010 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. Quote Link to post Share on other sites
ShadowMage 94 Posted September 23, 2010 Report Share Posted September 23, 2010 What do we win? Quote Link to post Share on other sites
jeffman 86 Posted September 23, 2010 Report Share Posted September 23, 2010 (edited) The Amulet of Yendor. Edited September 23, 2010 by Deirdre's Dad Quote Link to post Share on other sites
ShadowMage 94 Posted September 23, 2010 Report Share Posted September 23, 2010 The Amulet of Yendor. I'm sure that's a reference to something....I know, I know, it's no longer funny if you have to explain it..... Quote Link to post Share on other sites
thescientist 231 Posted September 23, 2010 Report Share Posted September 23, 2010 http://en.wikipedia.org/wiki/Rogue_%28computer_game%29 Quote Link to post Share on other sites
ShadowMage 94 Posted September 23, 2010 Report Share Posted September 23, 2010 See, I knew it was a reference... Quote Link to post Share on other sites
jeffman 86 Posted September 23, 2010 Report Share Posted September 23, 2010 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. Quote Link to post Share on other sites
ShadowMage 94 Posted September 23, 2010 Report Share Posted September 23, 2010 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... Quote Link to post Share on other sites
ApocalypeX 3 Posted September 24, 2010 Report Share Posted September 24, 2010 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). Quote Link to post Share on other sites
thescientist 231 Posted September 24, 2010 Report Share Posted September 24, 2010 (edited) 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 September 24, 2010 by thescientist Quote Link to post Share on other sites
ApocalypeX 3 Posted September 24, 2010 Report Share Posted September 24, 2010 can I just do it in one?I can pay half of my tax. Don't mean I'm doing it right. Quote Link to post Share on other sites
boen_robot 107 Posted September 24, 2010 Report Share Posted September 24, 2010 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. Quote Link to post Share on other sites
jeffman 86 Posted September 24, 2010 Report Share Posted September 24, 2010 (edited) k Edited September 24, 2010 by Deirdre's Dad Quote Link to post Share on other sites
jeffman 86 Posted September 24, 2010 Report Share Posted September 24, 2010 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>");} Quote Link to post Share on other sites
boen_robot 107 Posted September 24, 2010 Report Share Posted September 24, 2010 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. Quote Link to post Share on other sites
ApocalypeX 3 Posted September 24, 2010 Report Share Posted September 24, 2010 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. Quote Link to post Share on other sites
ApocalypeX 3 Posted September 24, 2010 Report Share Posted September 24, 2010 Ah... if there was a memory limit requirement (that's unambiguous for you), then this would be the solution indeed.Add a memory limit Quote Link to post Share on other sites
thescientist 231 Posted September 24, 2010 Report Share Posted September 24, 2010 (edited) well, I'm doing it one for(var i = 1, x = 2, z = ""; i < x; i++){ print( (z += i.toString()) ); x++;}; Edited September 24, 2010 by thescientist Quote Link to post Share on other sites
boen_robot 107 Posted September 24, 2010 Report Share Posted September 24, 2010 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. Quote Link to post Share on other sites
ShadowMage 94 Posted September 24, 2010 Report Share Posted September 24, 2010 (edited) 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 September 24, 2010 by ShadowMage Quote Link to post Share on other sites
ShadowMage 94 Posted September 24, 2010 Report Share Posted September 24, 2010 well, I'm doing it onefor(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 />" );}; Quote Link to post Share on other sites
jeffman 86 Posted September 24, 2010 Report Share Posted September 24, 2010 Shadow, your entry in the "Title" contest does seem to do the trick. Interesting how my version (not yet complete) takes a very different approach. A lot of your code fixes the hyphen problem, which I have not tackled yet. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.