Computer Science Canada

i was wondering if...

Author:  uberwalla [ Fri Nov 24, 2006 8:24 pm ]
Post subject:  i was wondering if...

ok so i was wondering if it is possible to kinda "clean" a sentence in turing.
like im not talking encoding//decoding but... is there a way to take out all symbols and numbers etc from writing.

example:
u input something like "%h&i!Per^$son
and then it outputs "hiperson"

is that possible to do at all. i am interested cuz i want to make a game where the program inputs random letters, symbols, etc type thing and you have to decode type thing. it seems very lame, and yes it is but i want to do this for a start then id build on it after.

help would be very appreciated Very Happy! thx.

Author:  jamonathin [ Fri Nov 24, 2006 8:57 pm ]
Post subject: 

Very possible. You are going to want to refer to ASCII codes. Basically ASCII links a value to each letter.

hit F10 in turing, search for "run window character set" and it will bring up a list of each value of each symbol/letter (character).

You will notice that the capital letters range from 65-90 and lower case letters range from 97-122.

Also look up chr and ord in turing help. You will also need string manipulation - help can be found in the Turing Walkthrough.

If you need help with it, post your code and we can help you out (without giving the answer Wink)

Author:  uberwalla [ Fri Nov 24, 2006 9:25 pm ]
Post subject: 

ok thx a bunch. i already new about the letter/number thing but im kinda wondering if its possible to do like.

if char not= x-x then
...

can x be the letters designated chr number? and have it asign that way then have it somehow remove the numbers?

Author:  jamonathin [ Wed Nov 29, 2006 11:42 pm ]
Post subject: 

uberwalla wrote:
can x be the letters designated chr number? and have it asign that way then have it somehow remove the numbers?


Im not shure I fully understand what you're asking. The first question (before the and) makes me think your asking if you can reassign the value of the character to the value of 'x' - which is no. And then i dont know what you mean by 'removing the numbers'. Confused

Author:  jamonathin [ Wed Nov 29, 2006 11:43 pm ]
Post subject: 

Also if you could clarify what this means
Quote:

if char not= x-x then


if char not= 0?

Author:  Cervantes [ Thu Nov 30, 2006 1:02 am ]
Post subject: 

I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.

The answer is no.

uberwalla, you've already got a thread for this problem. Please explain why this extra topic was necessary, and how this topic is different (wasn't the question answered fully in your first topic?).

Author:  uberwalla [ Thu Nov 30, 2006 8:28 am ]
Post subject: 

o sry that was a later post when i half solved the problem then u helped meh Razz thx though guys

Author:  ZeroPaladn [ Thu Nov 30, 2006 9:06 am ]
Post subject: 

Cervantes wrote:
I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.

The awnser is no.

The awnser is YES!

[code]for i : x .. y %just an example
if letter ~= i then
%put whatever happens here
end if
end for

Author:  Clayton [ Thu Nov 30, 2006 11:20 am ]
Post subject: 

err no, if letter is a string, that code wont even run, but what Cervantes was saying that :

Cervantes wrote:

I think he's asking if he can do a check in that form


in which you cant.

Author:  Cervantes [ Thu Nov 30, 2006 1:13 pm ]
Post subject: 

ZeroPaladn wrote:
Cervantes wrote:
I think he's asking if he can do a check in that form to test whether char is within the range x to y, where x and y are his x and... x.

The awnser is no.

The awnser is YES!

code:
for i : x .. y %just an example
    if letter ~= i then
        %put whatever happens here
    end if
end for


The answer is no, because of the restriction on form.

Now, you need to understand something about your code. It won't work anywhere close to the way it was designed to. Try tracing it, to see why.

Here's what happens. You start with i as x. If letter not= i, then we perform our action, A. Then i = x+1. If letter not= i+1, we do A. See where this is going? We are very likely going to perform A many times, even if letter does happen to be in the range x to y.

To code this properly, we use inequalities:
code:

if letter < x or letter > y then
    A
end if

Author:  NikG [ Thu Nov 30, 2006 2:45 pm ]
Post subject: 

There's an even easier solution than what everyone has talked about so far.

1. Create a string with all the letters (a-z, A-Z)
2. Create a for loop going through each character in the text where the symbols will be removed
3. Check whether each character is in the string (I believe the index function)
3. If the character is found, add it to a new string.

No need to mess with ascii tables or anything.

Author:  Clayton [ Thu Nov 30, 2006 3:41 pm ]
Post subject: 

yes, but then you are using up extra memory by creating that string variable to hold all of the acceptable characters, not something you want to do.

Author:  uberwalla [ Thu Nov 30, 2006 3:48 pm ]
Post subject: 

code:

%The "Palindrome" Program
%By: Mike Lanthier
%Monday, November 28, 2006
function clean (x : string) : string
    var CleanedWord := ""
    for i : 1 .. length (x)
        if x (i) >= chr (97) and x (i) <= chr (122) or x (i) >= chr (65) and x (i) <= chr (90) then
            CleanedWord += x (i)
        end if
    end for
    result CleanedWord
end clean

var word : string
var YesOrNo : string
var winID := Window.Open ("nobuttonbar")
loop
    put "Enter a Word and I Will Remove Anything That Isn't A Letter."
    get word
    put clean (word)
    put "\nTest Another Word? (Yes (y) Or No (n)?)"
    get YesOrNo
    exit when YesOrNo = "n"
    cls
end loop
Window.Close (winID)

Author:  zylum [ Thu Nov 30, 2006 4:01 pm ]
Post subject: 

you can simplify
code:
if x (i) >= chr (97) and x (i) <= chr (122) or x (i) >= chr (65) and x (i) <= chr (90) then


to
code:
if x (i) >= 'a' and x (i) <= 'z' or x (i) >= 'A' and x (i) <= 'Z' then


oh, and why is it the 'Palindrome' program?

Author:  Clayton [ Thu Nov 30, 2006 4:22 pm ]
Post subject: 

actually, you can simplify that even further, because all characters are sequential in ASCII values, it can be:

code:

if x(i) >= 'a' and x(i) <= 'Z' then

Author:  uberwalla [ Thu Nov 30, 2006 4:30 pm ]
Post subject: 

its palindrome program cuz im forgetful and didnt change it. (i just copy and paste that shit Razz)

Author:  Cervantes [ Thu Nov 30, 2006 5:12 pm ]
Post subject: 

Freakman wrote:
actually, you can simplify that even further, because all characters are sequential in ASCII values, it can be:

code:

if x(i) >= 'a' and x(i) <= 'Z' then

No, you can't do that. Look at an ASCII table. You've got two problems. First, 'a' is 97, and 'Z' is 90. So you're looking for a number that's >= 97 but <= 90. Such numbers don't exist. What you want is
code:

if x(i) >= 'A' and x(i) <= 'z' then


But this still doesn't work, because there's some junk between 'Z' and 'a'.
ASCII table wrote:

090 - Z
091 - [ (left/opening bracket)
092 - \ (back slash)
093 - ] (right/closing bracket)
094 - ^ (caret/circumflex)
095 - _ (underscore)
096 - `
097 - a

Author:  Clayton [ Thu Nov 30, 2006 10:02 pm ]
Post subject: 

oops, I was just trying to do it from memory and I thought that Capital letters, then lower case letters were sequential Embarassed


: