
-----------------------------------
Flikerator
Thu May 26, 2005 7:24 am

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.

var word : string := "hel3lOE1asa5d"
var neword : string := ""

for i : 1 .. length (word)
    if ord (word (i)) < 65 and ord (word (i)) > 90 and ord (word (i)) < 97 and ord (word (i)) > 122 then
        neword += word (i)
        put ord (word (i))
    end if
end for

put neword

25 bits if I get the answer before I leave

-----------------------------------
MysticVegeta
Thu May 26, 2005 7:39 am


-----------------------------------
What do you mean removes all the letters?

-----------------------------------
MysticVegeta
Thu May 26, 2005 7:43 am


-----------------------------------
var word : string := "hel3lOE1asa5d"
var neword : string := ""

for i : 1 .. length (word)
    if (ord (word (i)) > 65 and ord (word (i)) < 90) or (ord (word (i)) > 97 and ord (word (i)) < 122) then
        neword += word (i)
        put ord (word (i))
    end if
end for

put neword


you mean this?

-----------------------------------
cornputer
Thu May 26, 2005 9:55 am


-----------------------------------
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

-----------------------------------
Flikerator
Thu May 26, 2005 12:52 pm


-----------------------------------
Im back, came second I think :P

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

-----------------------------------
MysticVegeta
Thu May 26, 2005 3:34 pm


-----------------------------------
var word : string := "ASDasdaASI/././D123JsE"
var ne : string := ""
for s : 1 .. length (word)
    if (word (s) >= "A" and word (s) = "a" and word (s)  64 and ord (word (i)) < 91 or ord (word (i)) > 96 and ord (word (i)) < 122 then

    else
        neword += word (i)
    end if

end for

put neword


You had the right idea, just a little off

-----------------------------------
Cervantes
Thu May 26, 2005 5:51 pm


-----------------------------------
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:

word := word (1 .. i - 1) + word (i + 1 .. *)


But that brings me to a question:

var word : string := "hel3lOE1asa5d"
for i : 1 .. length (word)
    if ord (word (i)) > 64 and ord (word (i)) < 91 or ord (word (i)) > 96 and ord (word (i)) < 122 then
    else
        word := word (1 .. i - 1) + word (i + 1 .. *)
    end if
end for
put word

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.  :eh:)  Does turing highlight the if statement?  It seems to me that if there is an error it should be at the word := word (1  etc.
I get the same error when I rearrange the if statement so we don't have that hanging "else" there:

var word : string := "hel3lOE1asa5d"

for i : 1 .. length (word)
    %if the character, word (i), is not a letter.
    if ord (word (i)) < 65 or ord (word (i)) > 122 or ord (word (i)) > 90 and ord (word (i)) < 97 then
            word := word (1 .. i - 1) + word (i + 1 .. *)
    end if
end for
put word


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?

-----------------------------------
Token
Thu May 26, 2005 8:07 pm


-----------------------------------
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.

-----------------------------------
MysticVegeta
Fri May 27, 2005 11:19 am


-----------------------------------
var word : string := "hel3lOE1asa5d"
var neword : string := ""

for i : 1 .. length (word)

    if ord (word (i)) > 64 and ord (word (i)) < 91 or ord (word (i)) > 96 and ord (word (i)) < 122 then

    else
        neword += word (i)
    end if

end for

put neword


You had the right idea, just a little off

eh? so he needs to use (ord)? because this works too :think: :?

-----------------------------------
Token
Fri May 27, 2005 2:23 pm


-----------------------------------
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.

-----------------------------------
MysticVegeta
Fri May 27, 2005 3:26 pm


-----------------------------------
:P why make it so confusing using ord? :lol:

-----------------------------------
Cervantes
Fri May 27, 2005 3:36 pm


-----------------------------------
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  64 and ord (word (i)) < 91 or ord (word (i)) > 96 and ord (word (i)) < 122 then
    else
        word := word (1 .. i - 1) + word (i + 1 .. *)
    end if
end for
put word

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

-----------------------------------
Cervantes
Sat May 28, 2005 11:40 am


-----------------------------------
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.  :wink:

:wall:

-----------------------------------
Bacchus
Sat May 28, 2005 12:06 pm


-----------------------------------
lol , yes of course I do. It was my first post! lol
