Quantcast

Maximum PC

It is currently Fri Aug 22, 2014 4:18 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: The string cheese challenge
PostPosted: Mon Aug 02, 2004 2:04 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Do you have a favorite language for manipulating strings? How about cheese? Good, try this... and post your code and results*. No copying other people's code either! After everyone has submitted, awards will be handed out.... :)

Given an input string, do the following operations in order:
  • If a word starts with "x", replace the "x" with a "z".
  • Change all remaining "x"s to "ks"s.
  • Change all "y"s to "i"s.
  • If a "c" is directly followed by an "e" or "i", change the "c" to an "s".
  • If a "c" is directly followed by a "k", remove the "c". Keep applying this rule as necessary (Example: "cck" becomes "k".)
  • If a word starts with "sch", change the "sch" to a "sk".
  • If a "ch" is directly followed by an "r", change the "ch" to a "k".
  • After applying the above rules, change all "c"s that are not directly followed by an "h", to a "k". (This includes all "c"s that are the last letter of a word.)
  • If a word starts with "kn" change the "kn" to an "n".
  • Change all double consonants of the same letter to a single consonant. A consonant is any letter that is not one of "a, e, i, o, u." (Example: "apple" becomes "aple"). Keep applying this rule as necessary (Example: "zzz" becomes "z".)

All input is in lower case.

Code:
Example: "sch kn x xschrx cknnchc cyck xxceci"
Returns: "sk n z zskrks nchk sik zksesi"

Example: "  pac  man  roccccccks  "
Returns: "  pak  man  roks "


Make sure you pass the two test cases above and then post your code and results with the following:

"i love string cheese!"
"please, I want need some cheese"
"did you know that Macy's is running a cheese sale?"
"xtemex cheedar chexx is for serious cheese snackers"


Award Categories:
Best Readability: Code Poet
Most Concise: What do you think about size now?!
Most unique language: What the hell is that?
Fastest: Dude, I wrote the whole thing in asm

Comedy Awards:
Most bloated: Miss Piggy missed her bloat
Worst readability: Hmm... looks like Perl
Best Failures: Hey, what's a test case again?
Interesting use of libs: Whad'ya mean I can't use < to tokenize a string?
Slowest: Driving Miss Daisy

*This is a 'reworked' TC problem. It should take the regular coders anywhere from 10 to 15 minutes and the noobs about a half-hour. A word of advice to the newbs - test each operation in isolation!


Top
  Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 2:23 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
You had to post this so late in the day didn't you?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 2:57 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24222
Location: Granite Heaven
Woo! I've been exploring Vancouver with my sis, who was in town for the weekend, but I'll do that ASAP. :D


Top
  Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:08 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DaBrain wrote:
You had to post this so late in the day didn't you?

Sorry... I actually had to do some work this morning. :)

You shouldn't be complaining.... I figure a PHP pro can crank it out in about 3 minutes. Of course, it won't be correct either. :P


Top
  Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:09 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Jipstyle wrote:
Woo! I've been exploring Vancouver with my sis, who was in town for the weekend, but I'll do that ASAP. :D

Sounds good.... Java, C++ or what?


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 7:51 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
Code:
<?php
function stringcheese($string) {
  echo "Original:<br>".$string."<br>";
  $string = preg_replace("/^x/", "z", $string);
  $string = preg_replace("/ x/", " z", $string);
  $string = str_replace("x", "ks", $string);
  $string = str_replace("y", "i", $string);
  $string = str_replace("ce", "se", $string);
  $string = str_replace("ci", "si", $string);
while(preg_match("/c+k/", $string)) {
  $string = preg_replace("/c+k/", "k", $string);}
  $string = preg_replace("/^sch/", "sk", $string);
  $string = preg_replace("/ sch/", " sk", $string);
  $string = preg_replace("/chr/", "kr", $string);
  $string = preg_replace("/c[a-gi-z]/", "k", $string);
  $string = preg_replace("/c /", "k ", $string);
  $string = preg_replace("/^kn/", "n", $string);
  $string = preg_replace("/ kn/", " n", $string);
while(preg_match("/([b-df-hj-np-tv-z])(\\1)+/", $string)) {
  $string = preg_replace("/([b-df-hj-np-tv-z])(\\1)+/", "\${1}", $string);}
  echo "Result:<br>"$string"<br><br>";

$ex1 = "sch kn x xschrx cknnchc cyck xxceci";
$ex2 = "  pac  man  roccccccks  ";
$string1 = "i love string cheese!";
$string2 = "please, I want need some cheese";
$string3 = "did you know that Macy's is running a cheese sale?";
$string4 = "xtemex cheedar chexx is for serious cheese snackers";
stringcheese($ex1);
stringcheese($ex2);
stringcheese($string1);
stringcheese($string2);
stringcheese($string3);
stringcheese($string4);
?>


Output wrote:
Original:
"sch kn x xschrx cknnchc cyck xxceci"
Result:
"sk n z zskrks nchk sik zksesi"

Original:
" pac man roccccccks "
Result:
" pak man roks "

Original:
"i love string cheese!"
Result:
"i love string cheese!"

Original:
"please, I want need some cheese"
Result:
"please, I want need some cheese"

Original:
"did you know that Macy's is running a cheese sale?"
Result:
"did iou now that Masi's is runing a cheese sale?"

Original:
"xtemex cheedar chexx is for serious cheese snackers"
Result:
"ztemeks cheedar cheksks is for serious cheese snakers"


Quick and dirty. I went on the assumption that the strings were all lowercase so it would need to be modified for both cases to work.
http://www.snackbar-games.com/cone/code ... efinal.php


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:14 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Looks pretty good - I'll have some nasty test cases for you later. It'll be the 'secret test part' so double check things. One thing though....

Code:
while(preg_match("/([b-df-hj-np-tv-z])(\\1)+/", $string)) {
  $string = preg_replace("/([b-df-hj-np-tv-z])(\\1)+/", "\${1}", $string);}

What is the (\\1) doing? Does that mean repeat the first regex?

The code block looks ok to me - but you ate up the extra white space in the pac man example. There should be extra spaces in there, but I'm not certain whether you or the program removed them.

Here's a tip - may help a little. To prevent having to use two slightly different regexs for the first/last character special cases (you have three examples of this - here is one of them)...

$string = preg_replace("/^x/", "z", $string);
$string = preg_replace("/ x/", " z", $string);

You can often add an extra space to the front and end of the string, do the single regex's, then remove the extra space at the end. YMMV.

Does preg stand for perl regular expression? I hope. :)

Overall, I think this is a pretty solid solution. One function, only a couple of different library calls to do everything, and fairly easy to follow even if you don't know php. Having to enclose a regex in both a "" and // seems bit redundant, but no big deal either. My only complaint, and this just may be the way php folks do things and I'm not used to it, is that the while statements seem to be 'unindented' (?) a space and the ending } is not on a seperate line. I had to hunt a bit to find the end of each while loop. At this point, I think you're strong contender for most concise, might have a shot at best readability (although my money is on Manta at this point), and possibly slowest... :P

Feedback....
Was that problem too easy? I wanted to make our first little contest problem / language comparison fairly easy, but I'm not too sure if it was too easy, or maybe, a bit too hard for some of the newer folks around here.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 1:25 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
Gadget wrote:
Code:
while(preg_match("/([b-df-hj-np-tv-z])(\\1)+/", $string)) {
  $string = preg_replace("/([b-df-hj-np-tv-z])(\\1)+/", "\${1}", $string);}

What is the (\\1) doing? Does that mean repeat the first regex?


Yeah, it's a match for the same character as the previous regex. If you omitted it and just repeated the range it could match any 2 consonants and a + would do that as well. I found that the \\1 was necesarry. The need for the \\ is to escape the \.

Gadget wrote:
Here's a tip - may help a little. To prevent having to use two slightly different regexs for the first/last character special cases (you have three examples of this - here is one of them)...

$string = preg_replace("/^x/", "z", $string);
$string = preg_replace("/ x/", " z", $string);

You can often add an extra space to the front and end of the string, do the single regex's, then remove the extra space at the end. YMMV.


I could have simplified it into:
$string = preg_replace("/(^| )x/", "z", $string);

But I didn't have time to test it so I left it as 2 lines.


Gadget wrote:
Does preg stand for perl regular expression? I hope. :)


Sure does.

Gadget wrote:
My only complaint, and this just may be the way php folks do things and I'm not used to it, is that the while statements seem to be 'unindented' (?) a space and the ending } is not on a seperate line. I had to hunt a bit to find the end of each while loop. At this point, I think you're strong contender for most concise, might have a shot at best readability (although my money is on Manta at this point), and possibly slowest... :P


Nah, I just didn't clean up the indentions. Normally I do, but I was in a rush as I had to head to a client's office today.

Gadget wrote:
Feedback....
Was that problem too easy? I wanted to make our first little contest problem / language comparison fairly easy, but I'm not too sure if it was too easy, or maybe, a bit too hard for some of the newer folks around here.


I think it was fun. The double consonant regex gave me a little trouble since my regex is a little rusty. Made me feel like I was back in school and I enjoyed it.

P.S. I accidentally removed the white space from the pac man line before feeding it into the program. Here is cleaned up code:

Code:
<?php
function stringcheese($string) {
  echo "Original:<br>".$string."<br>";
  $string = preg_replace("/^x/", "z", $string);
  $string = preg_replace("/ x/", " z", $string);
  $string = str_replace("x", "ks", $string);
  $string = str_replace("y", "i", $string);
  $string = str_replace("ce", "se", $string);
  $string = str_replace("ci", "si", $string);
  while(preg_match("/c+k/", $string)) {
   $string = preg_replace("/c+k/", "k", $string);
  }
  $string = preg_replace("/^sch/", "sk", $string);
  $string = preg_replace("/ sch/", " sk", $string);
  $string = preg_replace("/chr/", "kr", $string);
  $string = preg_replace("/c[a-gi-z]/", "k", $string);
  $string = preg_replace("/c /", "k ", $string);
  $string = preg_replace("/^kn/", "n", $string);
  $string = preg_replace("/ kn/", " n", $string);
  while(preg_match("/([b-df-hj-np-tv-z])(\\1)+/", $string)) {
   $string = preg_replace("/([b-df-hj-np-tv-z])(\\1)+/", "\${1}", $string);
  }
  echo "Result:<br>"$string"<br><br>";
}
$ex1 = "sch kn x xschrx cknnchc cyck xxceci";
$ex2 = "  pac  man  roccccccks  ";
$string1 = "i love string cheese!";
$string2 = "please, I want need some cheese";
$string3 = "did you know that Macy's is running a cheese sale?";
$string4 = "xtemex cheedar chexx is for serious cheese snackers";
stringcheese($ex1);
stringcheese($ex2);
stringcheese($string1);
stringcheese($string2);
stringcheese($string3);
stringcheese($string4);
?>


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 7:44 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DaBrain wrote:
I could have simplified it into:
$string = preg_replace("/(^| )x/", "z", $string);

But I didn't have time to test it so I left it as 2 lines.

Does the ? regex work? something like "/[ ]?x/".
One or no spaces follewed by an x is how I would normally do it. Still, I'm not too sure that you would want to do that because... "xtreme xmas" would become "ztremezmas", no?

Well, if Jip of DJ doesn't post a Java solution soon, I'll put that up. I'll hope into chat and try and convince Colby or JT to post a painful solution (err, perl). And where are all the basic programmers now? A little problem and they scurry away like a buncha cockaroaches. :)


Top
  Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 8:56 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
Gadget wrote:
DaBrain wrote:
I could have simplified it into:
$string = preg_replace("/(^| )x/", "z", $string);


preg_replace is a regex parser for PHP which functions similarly to the PERL version.

Gadget wrote:
Well, if Jip of DJ doesn't post a Java solution soon, I'll put that up. I'll hope into chat and try and convince Colby or JT to post a painful solution (err, perl). And where are all the basic programmers now? A little problem and they scurry away like a buncha cockaroaches. :)


I'll see what I can do, I've been very busy lately with other things, and I took out my Windows box since I'm doing a dual boot (Gentoo/Windows).


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 2:42 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Fri Jul 23, 2004 3:44 pm
Posts: 216
First of all, there appears to be a bug in whatever code was originally used to generate the test results.

Example: "sch kn x xschrx cknnchc cyck xxceci"
Returns: "sk n z zskrks nchk sik zksesi"

This is wrong based upon the rules stated, specifically Rule 6

Quote:
If a word starts with "sch", change the "sch" to a "sk".


this is the only rule that would possibly affect the sch in xschrx, but because the word doesn't start with sch it should not be changed. There are a couple possibilities that could cause this to occur;

#1 an instring seach and replace that isn't being limited to the beginning of a word

#2 the sch is being compared after double consonants are removed and "x x" is considered a double consonant, which it isn't.

If I'm mistaken here, please point out the rules that are effecting this change. Beyond this, here's my code, written in Visual Foxpro's programming language.

Code:
PARAMETERS m.instring

? m.instring
? cheese(m.instring)

PROCEDURE cheese
   PARAMETERS m.workvar

   IF SUBSTR(m.workvar,1,1)="x"
      m.workvar="z"+SUBSTR(m.workvar,2,LEN(m.workvar)-1)
   ENDIF
   m.workvar = STRTRAN(m.workvar, " x", " z")
   m.workvar = STRTRAN(m.workvar, "x", "ks")
   m.workvar = STRTRAN(m.workvar, "y", "i")
   m.workvar = STRTRAN(m.workvar, "ce", "se")
   m.workvar = STRTRAN(m.workvar, "ci", "si")

   DO WHILE "ck"$m.workvar
      m.workvar = STRTRAN(m.workvar, "ck", "k")
   ENDDO

   IF SUBSTR(m.workvar,1,3)="sch"
      m.workvar="sk"+SUBSTR(m.workvar,4)
   ENDIF

   m.workvar = STRTRAN(m.workvar, " sch", " sk")

   IF SUBSTR(m.workvar,1,3)="chr"
      m.workvar="kr"+SUBSTR(m.workvar,4)
   ENDIF

   m.workvar = STRTRAN(m.workvar, " chr", " kr")

   FOR x = 97 TO 122
      IF x != 104
         m.workvar = STRTRAN(m.workvar, "c"+CHR(x), "k"+CHR(x))
      ENDIF
   ENDFOR

   m.workvar = STRTRAN(m.workvar, "c ", "k ")

   IF SUBSTR(m.workvar,LEN(m.workvar),1) = "c"
      m.workvar = SUBSTR(m.workvar,1,LEN(m.workvar)-1)+"k"
   ENDIF

   m.workvar = STRTRAN(m.workvar, " kn", " n")

   FOR x = 98 TO 122
      IF x!=101 AND x!=105 AND x!=111 AND x!=117
         m.seek = CHR(x)+CHR(x)
         DO WHILE m.seek$m.workvar
            m.workvar = STRTRAN(m.workvar, m.seek, CHR(x))
         ENDDO
      ENDIF
   ENDFOR

   RETURN m.workvar
ENDPROC



my results are the same as DaBrains, with the exception noted above


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 6:12 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
Gadget wrote:
DaBrain wrote:
I could have simplified it into:
$string = preg_replace("/(^| )x/", "z", $string);

But I didn't have time to test it so I left it as 2 lines.

Does the ? regex work? something like "/[ ]?x/".
One or no spaces follewed by an x is how I would normally do it. Still, I'm not too sure that you would want to do that because... "xtreme xmas" would become "ztremezmas", no?


Correct. You would have to put something in the replacement string in case the space was matched, you don't want to replace the space and character with a single letter.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 6:53 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
dargon wrote:
First of all, there appears to be a bug in whatever code was originally used to generate the test results.

Example: "sch kn x xschrx cknnchc cyck xxceci"
Returns: "sk n z zskrks nchk sik zksesi"

This is wrong based upon the rules stated, specifically Rule 6

Quote:
If a word starts with "sch", change the "sch" to a "sk".


this is the only rule that would possibly affect the sch in xschrx, but because the word doesn't start with sch it should not be changed. There are a couple possibilities that could cause this to occur;

#1 an instring seach and replace that isn't being limited to the beginning of a word

#2 the sch is being compared after double consonants are removed and "x x" is considered a double consonant, which it isn't.

If I'm mistaken here, please point out the rules that are effecting this change.


Here is the tracing of the code applying each rule to it:

Original: "sch kn x xschrx cknnchc cyck xxceci"
Rule 1: "sch kn z zschrx cknnchc cyck zxceci"
Rule 2: "sch kn z zschrks cknnchc cyck zksceci"
Rule 3: "sch kn z zschrks cknnchc cick zksceci"
Rule 4: "sch kn z zschrks cknnchc sick zkssesi"
Rule 5: "sch kn z zschrks knnchc sik zkssesi"
Rule 6: "sk kn z zschrks knnchc sik zkssesi"
Rule 7: "sk kn z zskrks knnchc sik zkssesi"
Rule 8: "sk kn z zskrks knnchk sik zkssesi"
Rule 9: "sk n z zskrks nnchk sik zkssesi"
Rule 10: "sk n z zskrks nchk sik zksesi"

The only changes to teh word "xschrx" occur with rules 1 and 7. Letters that changed in that word have been bolded.

Rule 7:
Quote:
If a "ch" is directly followed by an "r", change the "ch" to a "k".


So do a string match for "chr" and change it to "kr" and there is a match right in the middle of the word.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 7:44 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Fri Jul 23, 2004 3:44 pm
Posts: 216
mental note, coding at 4am with no sleep is never a good idea, I see that now :)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 8:37 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
dargon wrote:
mental note, coding at 4am with no sleep is never a good idea, I see that now :)


:)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 11:42 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Hi Dargon..... I haven't seen you around here before - it is nice seeing some new folks around. Welcome. Hopefully we'll be seeing some more Visual Foxpro in the future.

Well, I'm pretty confident you're the "What the hell is that?" most unique language award winner, and you also take one or two other prizes too - that is pretty long compared to the php submission after all! :)

I like the indention and good use of whitespace lines. I am able to 'read' most of what you wrote, and I have never seen this language before. A good sign. However, I think the language might be a bit too verbose for the code poet prize. It seems straight-forward, but not really all that elegant IMO. It looks like you sort of had to 'force' the issue in some places to get what you want done. We'll see what Brain, Jip, DJ, Colby and some of the others think about it.

Some questions for you..... remember, I don't know this language so bear with me. :)

PARAMETERS m.instring
What is m.instring? Is it just a var? Data type and var? Or what?


? m.instring
? cheese(m.instring)
Not sure about this one either. Declaration of m.instring and then the procedure call? What does the '?' represent? Reminds me of the old basic ?"shortcut for print - use of the ?".

Code:
IF SUBSTR(m.workvar,1,1)="x"
      m.workvar="z"+SUBSTR(m.workvar,2,LEN(m.workvar)-1)
   ENDIF

This is one of those sort of 'forced' areas. Works, sure - pretty, eh, not really. BTW, you could also have benefited from the appending " " to the beginning and end of the string trick eliminating seperate lines for the first and last character of the string special case (see my previous post to brain if you don't know what I'm talking about).

Overall, it is easy to read and follow what you are attempting to do in each section, but a section like this with nested loops, a conditional and the use of ascii codes is not too elegant...
Code:
m.workvar = STRTRAN(m.workvar, " kn", " n")

   FOR x = 98 TO 122
      IF x!=101 AND x!=105 AND x!=111 AND x!=117
         m.seek = CHR(x)+CHR(x)
         DO WHILE m.seek$m.workvar
            m.workvar = STRTRAN(m.workvar, m.seek, CHR(x))
         ENDDO
      ENDIF
   ENDFOR


...really makes you appreciate the power of regular expressions! :)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 12:15 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Fri Jul 23, 2004 3:44 pm
Posts: 216
Gadget wrote:
Hi Dargon..... I haven't seen you around here before - it is nice seeing some new folks around. Welcome. Hopefully we'll be seeing some more Visual Foxpro in the future.


I joined just before MPC moved to Delphi Hell. I never liked the Delphi forums so I stopped visiting. /me is glad for the forum change

Gadget wrote:
Well, I'm pretty confident you're the "What the hell is that?" most unique language award winner, and you also take one or two other prizes too - that is pretty long compared to the php submission after all! :)

I like the indention and good use of whitespace lines. I am able to 'read' most of what you wrote, and I have never seen this language before. A good sign. However, I think the language might be a bit too verbose for the code poet prize. It seems straight-forward, but not really all that elegant IMO. It looks like you sort of had to 'force' the issue in some places to get what you want done. We'll see what Brain, Jip, DJ, Colby and some of the others think about it.


Heh, it is, but it works (except for the bug I missed at 4am :) ). Foxpro was never really mean't to do major string manipulation, more often just minor manipulation for database applications.

Gadget wrote:
Some questions for you..... remember, I don't know this language so bear with me. :)

PARAMETERS m.instring
What is m.instring? Is it just a var? Data type and var? Or what?


m.instring is just a variable, like Javascript, foxpros language is loosely typed meaning in the same procedure I can have m.instring change from a string to a numeric to a logical if I desire. Parameters just tells foxpro that when I run the program it'll have a parameter ( ie DO cheesestring.prg with "the quick brown fox" )

Gadget wrote:
? m.instring
? cheese(m.instring)
Not sure about this one either. Declaration of m.instring and then the procedure call? What does the '?' represent? Reminds me of the old basic ?"shortcut for print - use of the ?".


Heh, that exactly what it's doing, printing out the original text, followed by the converted text

Gadget wrote:
Code:
IF SUBSTR(m.workvar,1,1)="x"
      m.workvar="z"+SUBSTR(m.workvar,2,LEN(m.workvar)-1)
   ENDIF

This is one of those sort of 'forced' areas. Works, sure - pretty, eh, not really. BTW, you could also have benefited from the appending " " to the beginning and end of the string trick eliminating seperate lines for the first and last character of the string special case (see my previous post to brain if you don't know what I'm talking about).


4am, I wasn't going for pretty, just functional :)


Gadget wrote:
Overall, it is easy to read and follow what you are attempting to do in each section, but a section like this with nested loops, a conditional and the use of ascii codes is not too elegant...
Code:
m.workvar = STRTRAN(m.workvar, " kn", " n")

   FOR x = 98 TO 122
      IF x!=101 AND x!=105 AND x!=111 AND x!=117
         m.seek = CHR(x)+CHR(x)
         DO WHILE m.seek$m.workvar
            m.workvar = STRTRAN(m.workvar, m.seek, CHR(x))
         ENDDO
      ENDIF
   ENDFOR


...really makes you appreciate the power of regular expressions! :)



Heh, way more elegant than the 21 item case statement I originally did it with :)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 6:55 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 11:30 am
Posts: 368
Location: San Antonio, TX
I am going to try and do this in Perl now... My perl is VERY rusty.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 9:58 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DaBrain wrote:
I am going to try and do this in Perl now... My perl is VERY rusty.

I hate it when the email notifications stop - this board cannot exist w/o email notices! Manta is in Pasadena on business, so he won't be providing a Python solution for quite a while.

I'll post a Java solution from home later today.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 5:38 pm 
I judge you GUILTY!
I judge you GUILTY!
User avatar

Joined: Tue May 25, 2004 4:38 pm
Posts: 162
Location: New York City
I would try this in C++, but standard C++ has no real useful string manipulation libraries.
Maybe I should invest some time and look at the Boost libraries and try something with that.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group