Computer Science Canada Help real quick, I gotta go in 4 mins eep |
Author: | Flikerator [ Thu May 26, 2005 7:24 am ] | ||
Post subject: | Help real quick, I gotta go in 4 mins eep | ||
Im going to a contest soon and I only have a few minutes before I leave I know its chance someone will answer but I can try. Why doesn't this work, it removes all letters.
25 bits if I get the answer before I leave |
Author: | MysticVegeta [ Thu May 26, 2005 7:39 am ] |
Post subject: | |
What do you mean removes all the letters? |
Author: | MysticVegeta [ Thu May 26, 2005 7:43 am ] | ||
Post subject: | |||
you mean this? |
Author: | cornputer [ Thu May 26, 2005 9:55 am ] |
Post subject: | |
because of the and at the second part turing doesnt take the second part as (condition1 +condition2)or (1 + 2 ) it takes condition 1 AND (1 or 2) AND condition 3 not sure if im totally right but ive tried a similar error and i think it was like this |
Author: | Flikerator [ Thu May 26, 2005 12:52 pm ] |
Post subject: | |
Im back, came second I think ![]() There were no questions with that so its all good. I jsut wanted all the uppercase and lowercase to be taken out of the string leaving the rest. If anyone has an answer to it ill give em 10 bits, it has to use ord. if word (i) = "a" then Is something I want to avoid, thats the whole reason for the ord |
Author: | MysticVegeta [ Thu May 26, 2005 3:34 pm ] | ||
Post subject: | |||
This? Offtopic: what contest? |
Author: | Token [ Thu May 26, 2005 4:58 pm ] | ||
Post subject: | |||
You had the right idea, just a little off |
Author: | Cervantes [ Thu May 26, 2005 5:51 pm ] | ||||||
Post subject: | |||||||
It should be noted that, depending on what you intend to do with the program, the second variable may be unnecessary, for one could just do this:
But that brings me to a question:
I'm getting an error: substring index is greater than length of string. Do you guys get the error as well? (Over the years I've sometimes noticed Turing behaving irrationally. I've failed to find anything wrong with my code, so I'm wondering if it's Turing itself. ![]() I get the same error when I rearrange the if statement so we don't have that hanging "else" there:
Even the word assignment line should not be a proble. Assuming i = 1: word (1 .. i - 1) will be word (1 .. 0) which equates to nothing. We are allowed to have the right number one less than the left number. word (i + 1 .. *) will be word (2 .. *), which should be fine. Assuming i = length (word): word (1 .. i - 1) should be fine. word (i + 1 .. *) will be word (* + 1 .. *) which is again a case of the right side being one less than the left side. When that happens (right side 1 less than left) it just skips over it. Anyone have any ideas as to why there's an error? |
Author: | Token [ Thu May 26, 2005 8:07 pm ] |
Post subject: | |
yah man thats probibly turing just being screwy again, it has done that to me before too, i made this calculator program and it kept telling me that the square root of 9 was 2.999999 lol it was messssssssssed up. |
Author: | MysticVegeta [ Fri May 27, 2005 11:19 am ] | ||
Post subject: | |||
Token wrote:
You had the right idea, just a little off eh? so he needs to use (ord)? because this works too ![]() ![]() |
Author: | Token [ Fri May 27, 2005 2:23 pm ] |
Post subject: | |
yah, urs is rite, it works, but he needed to use ord, which is the same thing as what your doing becuase it automatically recognises the ascii value in yours. |
Author: | MysticVegeta [ Fri May 27, 2005 3:26 pm ] |
Post subject: | |
![]() ![]() |
Author: | Cervantes [ Fri May 27, 2005 3:36 pm ] |
Post subject: | |
1.) It wouldn't be confusing if it were commented. 2.) Comparing the ordinal value of each character to a set of numbers (we can use ranges, because of the way the ASCII chart is set up) saves us from having to do 52 (26 * 2) if statements or a case structure with 52 labels or an index comparing the character to a string with 52 characters. It's a lot easier! ![]() EDIT: Hey, whaddya know, you're code would work too. I missed the >= and <= operators and thought you'd only checked for a's and z's. ![]() In any case, when comparing two characters, the computer converts them to their ordinal values and compares those integers. So, essentially it's the same thing. |
Author: | MysticVegeta [ Fri May 27, 2005 4:24 pm ] |
Post subject: | |
Cervantes wrote: when comparing two characters, the computer converts them to their ordinal values and compares those integers. So, essentially it's the same thing.
i win? just kidding ![]() |
Author: | Cervantes [ Fri May 27, 2005 4:43 pm ] |
Post subject: | |
It's a question of how you like to think about it. Personally, I find the ord method easier to understand. It means you have to open up the ascii chart, but it means you don't have to go the extra step of thinking about how the computer compares characters. Plus, since you've already got the ascii chart open, you can look at the range and everything within it. For things other than the alphabet and numbers, you'd have to open it up regardless. So using the ord method is more coding, but, for me at least, it's easier to understand. |
Author: | Flikerator [ Sat May 28, 2005 9:17 am ] |
Post subject: | |
(Contest for Brock University, I was beat by a Chinaman lolz So I took second) Thanks for the help, I know what I did wrong now ![]() ord also helps you learn what they all the characters are on the acsii chart |
Author: | Bacchus [ Sat May 28, 2005 11:28 am ] | ||
Post subject: | |||
Cervantes wrote: But that brings me to a question:
I'm getting an error: substring index is greater than length of string. Do you guys get the error as well? Yep same error, same place. I'm surprised thought that you didn't catch it yourself Cervantes. If your in a for statment to the length of the original word, then start to take letters out of that word making it smaller.... get my drift? Therefore the reason why the error is appearing in the if statment line is because your trying to check the letter of the word [(i)] that is past the length of the new word. Therefore: word(i > length(word)) = bad |
Author: | Cervantes [ Sat May 28, 2005 11:40 am ] |
Post subject: | |
Hooah! What's worse, I spent quite a while working on a solution to that same problem, only with removing elements from a flexible array, as I'm sure you remember. ![]() ![]() |
Author: | Bacchus [ Sat May 28, 2005 12:06 pm ] |
Post subject: | |
lol , yes of course I do. It was my first post! lol |