Qbasicnews.com
April 06, 2020, 12:10:25 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Palindrone help, please  (Read 3464 times)
NashKat
New Member

Posts: 13


« on: March 04, 2003, 04:30:04 PM »

Trying to get the program to reconize palindrones. Is there a keyword to use or not? Tryed using mixer$ and all that does is reverse the word so I know that don't work. What word would go in its place?

This is what I have so far:

CLS

Start:

INPUT "Type Something Here -  ", word$
word = LEN(word$)

DIM Mixer$(word)

FOR x = 1 TO word
        Mixer$(x) = MID$(word$, x, 1)
NEXT x

PRINT
PRINT

FOR x = word TO 1 STEP -1
        IF Mixer$(x) = UCASE$(Mixer$(x)) THEN
                PRINT LCASE$(Mixer$(x));
        ELSE
                PRINT UCASE$(Mixer$(x));
        END IF
NEXT x

END

As you can see it flips the words around. So my question is how to get the program to recoginize Palindrones, ie...now i won

Any help would be great thanks.
And by the way... I  RTFM thats why I'm here
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: March 04, 2003, 05:20:46 PM »

easy:

A palindrome is spelled the same backwards as it is forwards, right?

So there are two ways. One is to flip the word and then compare each byte to make sure it matches.

The other is to compare each word to make sure it matches starting from both sides:
Code:

CLS
word1$ = "hiih"
fail% = 0
len.word1% = LEN(word1$)
FOR I% = 1 TO len.word1%
J% = len.word1% - I% + 1
IF MID$(word1$, I%, 1) <> MID$(word1$, J%, 1) THEN fail% = 1: EXIT FOR
NEXT I%
PRINT fail%

Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
NashKat
New Member

Posts: 13


« Reply #2 on: March 04, 2003, 05:40:07 PM »

not real familar with the % sign, but I will look it up, so what your saying is to replace mixer$ with word1$ ... is that correct?  

word1$ = whatever someone types in
then if its not a palindrone have it say the word you typed is not a palindrone
 
am I close or am I making it worse?
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #3 on: March 04, 2003, 06:30:12 PM »

Quote
not real familar with the % sign, but I will look it up, so what your saying is to replace mixer$ with word1$ ... is that correct?


Yeah. (edit: no. word1$  = word$)

Quote
word1$ = whatever someone types in
then if its not a palindrone have it say the word you typed is not a palindrone
am I close or am I making it worse?


Yeah, fail%=1 means it's not a palindrome.

% just says that the variable is a signed integer.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Neo
Na_th_an
*****
Posts: 2150



« Reply #4 on: March 05, 2003, 08:07:21 AM »

Btw, you do not have to scan the whole word, because then you're doing twice the same thing.

Just let the for loop go to half of the string's size.

Not that it matters much for the speed, but if you repeat that operation one zillion times, you're going to have a much better time!  Cool
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #5 on: March 05, 2003, 03:40:04 PM »

I *know* that, I just forgot to put it in the code. I WAS going to!!!
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
NashKat
New Member

Posts: 13


« Reply #6 on: March 05, 2003, 04:58:30 PM »

Help me out here, because this don't work  :cry:

CLS

Start:

INPUT "Type Something Here - ", word$
word = LEN(word)

DIM word$(word)

FOR x = 1 to word
   word$(x) = MID$(word$, x, 1)
Next x

PRINT
PRINT

word1$ = "fail"
fail = 0
len.word1 = LEN(word1$)

FOR i = 1 to len.word1
j = len.word - i + 1
IF MID$(word1$, i, 1) <> MID$(word1$, j, 1) THEN fail = 1
EXIT FOR

NEXT i

FOR x = word TO 1 STEP -1
   IF word$(x) = UCASE$(word$(x)) THEN
      PRINT LCASE$(word(x));
   ELSE
      PRINT UCASE$(word$(x));
   END IF
NEXT x

END


it only prints in reverse?
I need it to print wheather or not it is a palindrone
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #7 on: March 05, 2003, 06:12:14 PM »

Just copy my code, and delete yours.

Then add this:

IF fail% = 0 then print "Success" else print "Failure"
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Rouschkateer
New Member

Posts: 7


« Reply #8 on: March 05, 2003, 08:21:46 PM »

Holy undecipherable programming lingo, Batman. I am in the same class as Nash here, and I think (totally no offense, I love you guys here), that you are taking waaaaaaaaay off the beaten track here. This should be a really easy code for us newbies. We "can't" use the % sigh, as we haven't learned it in class. It should be as easy as a MID$ statement and a comparison line. That's all. Here's the comparison:
FOR count=1 TO LEN(quote$) TO 1 STEP-1
IF MID$=(quote$,count,1) <> CHR$(32) THEN
quote1$=quote1$+MID$(quote$,count,1)
END IF
NEXT

easyyyy....but it doesnt work
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #9 on: March 05, 2003, 08:52:51 PM »

Code:

DIM fail as integer, dim i as integer, dim j as integer, dim len.word1 as integer

CLS
INPUT "WHAT DAMN WORD DO YOU WANT TO CHECK???", word1$
word1$ = "MADAMIMADAM"
fail = 0
len.word1 = LEN(word1$)/2
FOR I = 1 TO len.word1
J = len.word1 - I + 1
IF MID$(word1$, I, 1) <> MID$(word1$, J, 1) THEN fail = 1: EXIT FOR
NEXT I
IF FAIL = 0 then PRINT "IT IS" ELSE PRINT "IT ISN'T"
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Lanzaa
Forum Regular
**
Posts: 105



« Reply #10 on: March 11, 2003, 01:19:39 PM »

Why not something simple like this:
Code:
Cls
Input "the word/words"; a$
Mixer$(UCASE$(a$)) = b$
If UCASE$(a$) = b$ Then
Print "Its a palindrome"   'however you spell it
Else Print "Its not a palinmdrome"
end if
end

Uhhh....
Why didnt anyone tell me Mixer$ isn't a real comand?
<---- goes and destroys his code
Logged
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« Reply #11 on: March 11, 2003, 03:21:26 PM »

Quote from: "Rouschkateer"
We "can't" use the % sigh, as we haven't learned it in class.


% is just a variable suffix  that tells QBasic it's an integer

    % integer
    & long integer
    ! single precision
    # double precision
    $ string


example a variable called MyVariable! can store decimal numbers
while AnotherVariable% only can store integers (note the suffixes
and compare to the list above)
Logged

/post]
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!