Page 1 of 2

I need help with these programs.....

Posted: Fri Oct 28, 2005 3:33 pm
by Guest
1) I need to write a program that finds all the vampire numbers and outputs it to a text file. Ex: 15 x 93 = 1395


2) I also need to write this prgram: Solve the following cryptogram.....
BP WPVBKPW PBLKE, LKP IKWQPKZ CBFM W XBKC FD FMKBQ DCP BLHQDXKLKPF. PDCWZWNE, LKP IKWQP CBFM W XBKC FD FMK WHHQDJWFBDP DS DFMKQE.

PLEASE PLEASE help me!!! IF youo know how to write these programs please tell me or if you know anything, im desperate.

Posted: Fri Oct 28, 2005 4:12 pm
by {Nathan}
do your homework yourself.

ask your teacher. show us you made some effert and we will help, but we wont do your homework for you.

Posted: Fri Oct 28, 2005 4:20 pm
by shibby
I dont want you to do it for me. I just need some tips, like where to start or an outline. Maybe what loop to use....anything.

Posted: Fri Oct 28, 2005 6:00 pm
by Z!re
Your teacher is there to help you.

First one is accomplished the easiest way with string conversion functions..

Second one is impossible without knowing the algorithm used to encrypt..

Posted: Sat Oct 29, 2005 9:10 am
by Guest
My teacher wont help us, she acts like a hard ass. And the tells you nothing. and whats a string conversion function?

Posted: Sat Oct 29, 2005 9:46 am
by Z!re
If the teacher is bad, go to the principal and explain the situation. if the teacher is as bad as you claim others feel the same so you should have no problems in either getting the teacher a warning or making her epxlain stuff.

String conversion functions are functions that work on strings and convert them in one way or another.. such as: STR$(), LEFT$(), RIGHT$(), MID$(), VAL()

Posted: Sat Oct 29, 2005 11:20 am
by Zamaster
Hey, wait a sec! It is possible to decifer cryptograms w/o knowing the original crypting algorithm. It wouldnt be easy though. You first need a list of all the words in the english language. Then you have the program solve it just the way you would. I dont feel like explaining the logic. And as for the wompire numbes... It ain't THAT hard. Think about what your doing. Go through 2 sets of numbers, multiply em,' check to see if they create a number contating the characters in the original 2.

Posted: Sat Oct 29, 2005 11:38 am
by Guest
For the vampire numbers what loop would i need to do? DO while....Do until.....For/Next statement.......Im sorry im not good at programming it's my first year and i have a C in it.

Posted: Sat Oct 29, 2005 12:09 pm
by The Awakened
Zamaster: I just realized... your signature has backslashes (//), they should be regular slashes (\\) if you want it to be like DOS's filesystem.

And to the original poster: think about the problem you're trying to solve. Do you know how many times you're going to have to run the loop? If so, you'll want to use a For...Next loop. If you don't know, or you want to run it indefinately, use a do loop.

Posted: Sat Oct 29, 2005 12:29 pm
by {Nathan}
This is a thing that my old programming book said:

1>Does it run a certain amount of times? t = for loop f = 2
2>Does it need to run at least once? t = do loop f = while loop

I think thats it, I couldnt find it...

Posted: Sat Oct 29, 2005 1:11 pm
by Guest
Here's is what the problem says: THE CHALLENGE...Write a program,as short as possible, that finds every vampire number and outputs it toa text file.


-OK! I think i got it tell me if i do.... here is what i wrote

CLS : FOR q = 10 TO 99
FOR p = 10 TO 99

c$ = LTRIM$(RTRIM$(STR$(q * p))) 'candidate product in string

' "parse"
u$ = LEFT$(LTRIM$(RTRIM$(STR$(q))), 1) 'factor 1 byte 1
d$ = RIGHT$(LTRIM$(RTRIM$(STR$(q))), 1) 'factor 1 byte 2
t$ = LEFT$(LTRIM$(RTRIM$(STR$(p))), 1) 'factor 2 byte 1
q$ = RIGHT$(LTRIM$(RTRIM$(STR$(p))), 1) 'factor 2 byte 2

bc$ = ""

IF q$ + t$ + d$ + u$ = c$ OR q$ + t$ + u$ + d$ = c$ OR q$ + d$ + t$ + u$ = c$ THEN bc$ = c$
IF q$ + d$ + u$ + t$ = c$ OR q$ + u$ + t$ + d$ = c$ OR q$ + u$ + d$ + t$ = c$ THEN bc$ = c$
IF t$ + q$ + d$ + u$ = c$ OR t$ + q$ + u$ + d$ = c$ OR t$ + d$ + q$ + u$ = c$ THEN bc$ = c$
IF t$ + d$ + u$ + q$ = c$ OR t$ + u$ + q$ + d$ = c$ OR t$ + u$ + d$ + q$ = c$ THEN bc$ = c$
IF d$ + q$ + t$ + u$ = c$ OR d$ + q$ + u$ + t$ = c$ OR d$ + t$ + q$ + u$ = c$ THEN bc$ = c$
IF d$ + t$ + u$ + q$ = c$ OR d$ + u$ + q$ + t$ = c$ OR d$ + u$ + t$ + q$ = c$ THEN bc$ = c$
IF u$ + q$ + t$ + d$ = c$ OR u$ + q$ + d$ + t$ = c$ OR u$ + t$ + q$ + d$ = c$ THEN bc$ = c$
IF u$ + t$ + d$ + q$ = c$ OR u$ + d$ + q$ + t$ = c$ OR u$ + d$ + t$ + q$ = c$ THEN bc$ = c$

IF bc$ <> "" AND INSTR(dupe$, bc$) = 0 THEN dupe$ = dupe$ + bc$ + SPACE$(1): PRINT q; "x"; p; "= "; bc$

NEXT p
NEXT q

Posted: Sat Oct 29, 2005 4:45 pm
by Kyle
The awakened: \\ are backslashes, // are forward slashes :D

Posted: Sat Oct 29, 2005 4:55 pm
by {Nathan}
I did not understand your code completly (as in, I know it but it could be better). How about telling us what each var is? Because I think I know a way that INSTR can help you out here... thats a good little function there it is...

Posted: Sat Oct 29, 2005 5:03 pm
by The Awakened
Kylemc wrote:The awakened: \\ are backslashes, // are forward slashes :D
Well, whatever. :)

Posted: Sat Oct 29, 2005 5:08 pm
by Kyle
Well, your code is reasonably ugly, but it seems to work fine.

Posted: Sat Oct 29, 2005 5:23 pm
by Guest
This is BBCode, remove the asterisks to input it.
[*code]Input Code Here[*/code]
The result:

Code: Select all

Input code here
in a code statement, you can also space as much as you want, so your code will also gain legibility

Posted: Sat Oct 29, 2005 6:24 pm
by Guest
Well how could i make my program shorter and more legable???? Remember ima noobie so i wont understand most the stuff you are talking about unless you explain it. By the way thank you for the help.

Posted: Sat Oct 29, 2005 7:14 pm
by Zamaster
Yuck, I lost my appetite when I saw that code, just kidding. But, it could be a bit better.

Code: Select all

DECLARE FUNCTION num$ (nm&)

FOR mul1% = 1 TO 400
FOR mul2% = 1 TO 400

mstr$ = num$(CLNG(mul1%) * CLNG(mul2%))
nstr$ = mstr$
m1$ = num$(CLNG(mul1%)): m2$ = num$(CLNG(mul2%))
f% = 0

FOR i% = 1 TO LEN(m1$)
test% = INSTR(nstr$, MID$(m1$, i%, 1))
IF test% <> 0 THEN
MID$(nstr$, test%, 1) = SPACE$(1)
f% = f% + 1
ELSE
EXIT FOR
END IF
NEXT i%

FOR i% = 1 TO LEN(m2$)
test% = INSTR(nstr$, MID$(m2$, i%, 1))
IF test% <> 0 THEN
MID$(nstr$, test%, 1) = SPACE$(1)
f% = f% + 1
ELSE
EXIT FOR
END IF
NEXT i%

IF f% = LEN(m1$) + LEN(m2$) THEN
PRINT mstr$+","+m1$+","+m2$
END IF

NEXT mul2%
NEXT mul1%

FUNCTION num$ (nm&)
num$ = RIGHT$(STR$(nm&), LEN(STR$(nm&)) - 1)
END FUNCTION
At least I like this code better. Everybody else might say otherwise. :P

Posted: Sat Oct 29, 2005 7:23 pm
by Guest
Anonymous wrote:Well how could i make my program shorter and more legable???? Remember ima noobie so i wont understand most the stuff you are talking about unless you explain it. By the way thank you for the help.
By spacing on do..loops, for..nexts, while..wends, and if..then..end if statements as well as subs and functions. If you were a C programmer at one point, you would know the importance of tabbing & spacing for example:
Which is more readable and understandable?

Code: Select all

CLS
SCREEN 18

DO
    PSET(x, y), RND * 15
    x = x + 1
    y = y + 1
LOOP

Code: Select all

CLS
SCREEN 18

DO
PSET(x,y), rnd * 15
x = x + 1
y = y + 1
LOOP

Posted: Sun Oct 30, 2005 12:52 pm
by {Nathan}
yeah, i do that all the time, even before I started learning C++. it really does help beutify the code.... unless if you used it the way they did in the windows x code... that was HORRIBLE!