- Hey all!

Tom Lake posted the following on alt.lang.basic and I want to

encourage any interested parties to go and participate, representing

Liberty BASIC! ;-) He's already posted the first challenge!

---post begins

Would anyone be interested in posting BASIC solutions to programming

challenges in this newsgroup? I'd post a challenge and people could

post their solutions. We could all learn a lot by seeing different

approaches to a problem. Before you ask, I am NOT a student looking

to get my homework done for me! :-) I've been programming in BASIC

since 1970 (Before Microsoft!) and am a professional Microcomputer

Programmer. (Or so my title says!) I'll wait a few days and see what

the general opinion is. If a lot of you are interested, I'll post

the first problem then.

Tom Lake - --- In libertybasic@y..., carlg@l... wrote:
> Hey all!

representing

>

> Tom Lake posted the following on alt.lang.basic and I want to

> encourage any interested parties to go and participate,

> Liberty BASIC! ;-) He's already posted the first challenge!

Yes!! I'm hoping to get a lot of examples so people can compare and

contrast various programming techniques and how easy (or difficult)

they are to implement in various BASICs. My challenges will be of a

more logical nature rather than mathematical. As you view the

entries, please submit entries of your own to teach newbies by good

example rather than criticize their programs; we don't want to

discourage them! Thanks for the plug. Get entries in and let LB

shine! :-)

Tom Lake - --- In libertybasic@y..., carlg@l... wrote:
> Hey all!

Jay Shrimplin here,

>

> Tom Lake posted the following on alt.lang.basic and I want to

> encourage any interested parties to go and participate,representing

> Liberty BASIC! ;-) He's already posted the first challenge!

Took the challenge to write a program to convert from Roman numerals

to Arabic and vise versa.

My basics are Liberty Basic, Quick Basic 4.5, and Visual basic.

Decided since previous examples were in Quick Basic 4.5 to write the

program in that format and Liberty basic.

Thought it might be a challenge to write a program that will run on

each with no changes. This was tough as I would write a solution on

one basic and even though the same commands are availible in the

other the way they handle data would differ. So would write

something that works in one then try on the other.

Liberty basic 2.02 does not have the MOD function or the use of

SELECT CASE. You also do not have a EXIT FOR command so I was

limited to that. Decided since I was going to do multiple checking

for example XXX contains 3 Xs that the WHILE / WEND would work for me.

Got to notice that I was doing a lot of WHILE / WEND statements and

then decided to challege myself further.

This program has no (1) SELECT CASE (2) IF THEN (3) FOR NEXT

(4) DO LOOP (5) ON ... GOTO (6) ON ... GOSUB (7) functions

The only loop I used was the WHILE / WEND. Has a lot of while wend

loops.

The program accepts at the input Arabic numbers or Roman numerals or

a <Return> to exit. It will check to see if the value is 1 to 399999

as there is no zero in Roman and 4000000 exceeds the rule to use m

four times in a row. The program will accept both the newer method

of no character used more than four times in a row.

Example is 30 = XXX and 40 = XL and not XXXX.

Or you can enter the XXXX and 40 will pop out.

Enter XXXXXIIIII and 55 will pop out, but program will convert back

to the LV or new method on the conversion to Roman.

Enjoy,

Jay Shrimplin

Progam follows...

'Arabic to Roman to Arabic <jshrimp@r...> Jul 30, 01

CLS

PRINT "Roman I V X L C D M v x l c d m"

PRINT "Arabic 1 5 10 50 100 500 1K 5K 10K 50K 100K 500K 1M"

PRINT " JUST PRESS <ENTER> TO QUIT"

a$ = " "

WHILE LEN(a$) <> 0

PRINT

PRINT "Enter Roman or Arabic number ";

INPUT a$

WHILE INSTR("123456789", LEFT$(a$, 1)) > 0 _

AND VAL(a$) < 4000000 AND LEN(a$)<> 0

GOSUB 1000

PRINT roman$ + " - ";

a$ = roman$

GOSUB 2000

PRINT value

WEND

WHILE INSTR("IVXLCDMvxlcdm", LEFT$(a$, 1)) > 0 AND LEN(a$) <> 0

GOSUB 2000

b$ = a$

WHILE a$ = " "

PRINT value;

a$ = STR$(value)

GOSUB 1000

PRINT " - " + roman$

WEND

a$ = b$

WEND

WHILE a$ <> " " AND LEN(a$) > 0

PRINT

PRINT "Not a Roman or Arabic Number of 1 to 3999999"

PRINT "Please re-enter"

a$ = " "

WEND

WEND

PRINT

PRINT "end"

END

'-------------------------Conversions to follow--------------------

'------------------------------------------------------------------

'------------------------------------------------------------------

1000 'Convert to Roman

value = VAL(a$)

roman$ = ""

value2 = 1000000

value3 = 900000

value4 = 500000

value5 = 400000

label$ = "mcmdcdcxclxlxMxvMvMCMDCDCXCLXLXIXVIV"

position = 1

WHILE value2 >= 10

WHILE value >= value2

value = value - value2

roman$ = roman$ + MID$(label$, position, 1)

WEND

WHILE value >= value3

value = value - value3

roman$ = roman$ + MID$(label$, position + 1, 2)

WEND

WHILE value >= value4

value = value - value4

roman$ = roman$ + MID$(label$, position + 3, 1)

WEND

WHILE value >= value5

value = value - value5

roman$ = roman$ + MID$(label$, position + 4, 2)

WEND

position = position + 6

value2 = value2 / 10

value3 = value3 / 10

value4 = value4 / 10

value5 = value5 / 10

WEND

WHILE value >= 2

value = value - 2

roman$ = roman$ + "II"

WEND

WHILE value >= 1

value = value - 1

roman$ = roman$ + "I"

WEND

RETURN

'------------------------------------------------------------------

'------------------------------------------------------------------

2000 'Convert from Roman

a$ = " " + a$

value = 0

'Double digits

value2 = 900000

value3 = 400000

label$ = "cmcdxcxlMxDvCMCDXCXLIXIV"

position = 1

WHILE value2 >= 1

WHILE INSTR(a$, MID$(label$, position, 2))

temp = INSTR(a$, MID$(label$, position, 2))

a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp - 1)

value = value + value2

WEND

WHILE INSTR(a$, MID$(label$, position + 2, 2))

temp = INSTR(a$, MID$(label$, position + 2, 2))

a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp - 1)

value = value + value3

WEND

position = position + 4

value2 = value2 / 10

value3 = value3 / 10

WEND

'single digits

value2 = 1000000

label$ = "mdclxvMDCLXVI"

position = 1

WHILE value2 >= 1

WHILE INSTR(a$, MID$(label$, position, 1))

temp = INSTR(a$, MID$(label$, position, 1))

a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp)

value = value + value2

WEND

flag = 0

position = position + 1

WHILE INSTR(STR$(value2), "1") <> 0

value2 = INT(value2 / 2)

flag = 1

WEND

WHILE INSTR(STR$(value2), "5") <> 0 AND flag = 0 AND value2 >= 1

value2 = INT(value2 / 5)

WEND

WEND

RETURN - I tried your roman/arabic translator.

The results for these inputs appear to be incorrect:

VM, XM, LM, DM

r.m.

-----Original Message-----

From: jshrimp@... <jshrimp@...>

To: libertybasic@yahoogroups.com <libertybasic@yahoogroups.com>

Date: Tuesday, July 31, 2001 4:55 AM

Subject: [libertybasic] Re: BASIC Challenges

>--- In libertybasic@y..., carlg@l... wrote:

>> Hey all!

>>

>> Tom Lake posted the following on alt.lang.basic and I want to

>> encourage any interested parties to go and participate,representing

>> Liberty BASIC! ;-) He's already posted the first challenge!

>

>Jay Shrimplin here,

>

>Took the challenge to write a program to convert from Roman numerals

>to Arabic and vise versa.

>

>My basics are Liberty Basic, Quick Basic 4.5, and Visual basic.

>

>Decided since previous examples were in Quick Basic 4.5 to write the

>program in that format and Liberty basic.

>Thought it might be a challenge to write a program that will run on

>each with no changes. This was tough as I would write a solution on

>one basic and even though the same commands are availible in the

>other the way they handle data would differ. So would write

>something that works in one then try on the other.

>

>Liberty basic 2.02 does not have the MOD function or the use of

>SELECT CASE. You also do not have a EXIT FOR command so I was

>limited to that. Decided since I was going to do multiple checking

>for example XXX contains 3 Xs that the WHILE / WEND would work for me.

>

>Got to notice that I was doing a lot of WHILE / WEND statements and

>then decided to challege myself further.

>This program has no (1) SELECT CASE (2) IF THEN (3) FOR NEXT

>(4) DO LOOP (5) ON ... GOTO (6) ON ... GOSUB (7) functions

>The only loop I used was the WHILE / WEND. Has a lot of while wend

>loops.

>

>The program accepts at the input Arabic numbers or Roman numerals or

>a <Return> to exit. It will check to see if the value is 1 to 399999

>as there is no zero in Roman and 4000000 exceeds the rule to use m

>four times in a row. The program will accept both the newer method

>of no character used more than four times in a row.

>Example is 30 = XXX and 40 = XL and not XXXX.

>Or you can enter the XXXX and 40 will pop out.

>Enter XXXXXIIIII and 55 will pop out, but program will convert back

>to the LV or new method on the conversion to Roman.

>

> Enjoy,

>

> Jay Shrimplin

>

>Progam follows...

>

>'Arabic to Roman to Arabic <jshrimp@...> Jul 30, 01

>CLS

>PRINT "Roman I V X L C D M v x l c d m"

>PRINT "Arabic 1 5 10 50 100 500 1K 5K 10K 50K 100K 500K 1M"

>PRINT " JUST PRESS <ENTER> TO QUIT"

>a$ = " "

>WHILE LEN(a$) <> 0

>PRINT

>PRINT "Enter Roman or Arabic number ";

>INPUT a$

>

>WHILE INSTR("123456789", LEFT$(a$, 1)) > 0 _

>AND VAL(a$) < 4000000 AND LEN(a$)<> 0

>GOSUB 1000

>PRINT roman$ + " - ";

>a$ = roman$

>GOSUB 2000

>PRINT value

>WEND

>

>WHILE INSTR("IVXLCDMvxlcdm", LEFT$(a$, 1)) > 0 AND LEN(a$) <> 0

>GOSUB 2000

>b$ = a$

>WHILE a$ = " "

>PRINT value;

>a$ = STR$(value)

>GOSUB 1000

>PRINT " - " + roman$

>WEND

>a$ = b$

>WEND

>

>WHILE a$ <> " " AND LEN(a$) > 0

>PRINT

>PRINT "Not a Roman or Arabic Number of 1 to 3999999"

>PRINT "Please re-enter"

>a$ = " "

>WEND

>WEND

>PRINT

>PRINT "end"

>END

>'-------------------------Conversions to follow--------------------

>'------------------------------------------------------------------

>'------------------------------------------------------------------

>1000 'Convert to Roman

>value = VAL(a$)

>roman$ = ""

>value2 = 1000000

>value3 = 900000

>value4 = 500000

>value5 = 400000

>label$ = "mcmdcdcxclxlxMxvMvMCMDCDCXCLXLXIXVIV"

>position = 1

>WHILE value2 >= 10

>WHILE value >= value2

> value = value - value2

> roman$ = roman$ + MID$(label$, position, 1)

>WEND

>WHILE value >= value3

> value = value - value3

> roman$ = roman$ + MID$(label$, position + 1, 2)

>WEND

>WHILE value >= value4

> value = value - value4

> roman$ = roman$ + MID$(label$, position + 3, 1)

>WEND

>WHILE value >= value5

> value = value - value5

> roman$ = roman$ + MID$(label$, position + 4, 2)

>WEND

>position = position + 6

>value2 = value2 / 10

>value3 = value3 / 10

>value4 = value4 / 10

>value5 = value5 / 10

>WEND

>WHILE value >= 2

> value = value - 2

> roman$ = roman$ + "II"

>WEND

>WHILE value >= 1

> value = value - 1

> roman$ = roman$ + "I"

>WEND

>RETURN

>'------------------------------------------------------------------

>'------------------------------------------------------------------

>2000 'Convert to Roman

>a$ = " " + a$

>value = 0

>'Double digits

>value2 = 900000

>value3 = 400000

>label$ = "cmcdxcxlMxDvCMCDXCXLIXIV"

>position = 1

>WHILE value2 >= 1

>WHILE INSTR(a$, MID$(label$, position, 2))

>temp = INSTR(a$, MID$(label$, position, 2))

>a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp - 1)

>value = value + value2

>WEND

>WHILE INSTR(a$, MID$(label$, position + 2, 2))

>temp = INSTR(a$, MID$(label$, position + 2, 2))

>a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp - 1)

>value = value + value3

>WEND

>position = position + 4

>value2 = value2 / 10

>value3 = value3 / 10

>WEND

>'single digits

>value2 = 1000000

>label$ = "mdclxvMDCLXVI"

>position = 1

>WHILE value2 >= 1

>WHILE INSTR(a$, MID$(label$, position, 1))

>temp = INSTR(a$, MID$(label$, position, 1))

>a$ = LEFT$(a$, temp - 1) + RIGHT$(a$, LEN(a$) - temp)

>value = value + value2

>WEND

>flag = 0

>position = position + 1

>WHILE INSTR(STR$(value2), "1") <> 0

>value2 = INT(value2 / 2)

>flag = 1

>WEND

>WHILE INSTR(STR$(value2), "5") <> 0 AND flag = 0 AND value2 >= 1

>value2 = INT(value2 / 5)

>WEND

>WEND

>RETURN

>

>

>

>

>To unsubscribe from this group, send an email to:

>libertybasic-unsubscribe@egroups.com

>

>

>

>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

> - --- In libertybasic@y..., "Richard Miller" <richard.miller@h...>

wrote:> I tried your roman/arabic translator.

Roman I V X L C D M v x l c d m

> The results for these inputs appear to be incorrect:

> VM, XM, LM, DM

>

> r.m.

>

Arabic 1 5 10 50 100 500 1K 5K 10K 50K 100K 500K 1M

V is 5 and M is 1000 so you get 1005 and will be normally MV.

X is 10 and M is 1000 so you get 1010 and will be normally MX.

L is 50 and M =1000 so you get 1050 and will normally be ML.

D is 500 and M =1000 so you get 1500 and will normally be MD.

4 and 9 and 40 and 90 and so on are usually the only values lowered

by placing a 1 or 10 or ect. in front of a 10 or 100 or ect., or in

front of a 5 or 50 ect. value before it. Otherwise they begin with

high values and work thier way down. Such as the VM is 5+1000 and is

normally MV 1000+5. Their may be other standards but I took the two

sites below and several others to get my standard.

Check out this site and it has a calculator and it will comfirm and

explain the rules of Roman Numerals. It also gets the same values as

program sent.

http://www.novaroma.org/via_romana/numbers.html

Site #2 also converts and will not accept VM, XM, LM, DM and says

these are not standard roman numbers, but does accept MV, MX, ML, MD

http://www.guernsey.net/~sgibbs/roman.html

Jay Shrimplin