Rosetta's A+B

Post Reply
User avatar
Dutchman
Posts: 860
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Rosetta's A+B

Post by Dutchman »

sarossell introduced smart Basic into "Rosetta".
See viewtopic.php?f=20&t=1664 and http://rosettacode.org/wiki/Category:Smart_BASIC
For me was that website really a revelation. I did not know its existence. Thanks Scott :D
For the task 'A+B' the following code was given:

Code: Select all

INPUT n$
PRINT VAL(LEFT$(n$,(LEN(STR$(VAL(n$))))))+VAL(RIGHT$(n$,(LEN(n$)-LEN(STR$(VAL(n$)))-1)))
END
However, it appears that the code contains links to a website on Qbasic rather than Smart Basic.
Can that be changed to the HTML-page of the SB-manual http://nittersat.ru/BASIC_manual/en.pad ... asics.html :?:

Furthermore sarossell added the following note to his code:
NOTE: This is a horribly forced way of doing this. smart BASIC has commands to SPLIT strings. Surely someone can provide better code than what I've written here. ;@)
I took the chance to try it:

Code: Select all

INPUT n$
SPLIT n$ TO m$,n WITH " "
PRINT m$(0),m$(1),m$(0)+m$(1)
This code gives the desired result.
Last edited by Dutchman on Thu Jan 19, 2023 3:31 pm, edited 1 time in total.

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Rosetta's A+B

Post by sarossell »

YES! That's what I'm talking about! Awesome. I knew somebody would step up and fix that horrible mess. Well done.

As for the qbasic reference, that's a standard descriptor to get Rosetta to recognize BASIC code for context coloring, nothing more. If you can find or create one just for smart BASIC, that would be great. I'm not even sure if it's possible though.

You can always add notes to the entries or comments in the code you feel add to the value of the entry. Please do. :)
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Rosetta's A+B

Post by sarossell »

Please feel free to sign up on Rosetta Code and edit the entry for smart BASIC to add your code and any notes. I would prefer leaving existing entries as well to show a progression of improvement. Some people like to call better code solutions "optimized". :)

And spread the word! I think people can really learn a lot about BASIC programming with Rosetta, especially with smart BASIC.
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Rosetta's A+B

Post by sarossell »

As a former ZX81 programmer with just 1K of RAM back in the early 80s, I picked up the habit of always looking for optimizations in code.

I love the fact that you illustrated perfectly smart BASIC's behavior in treating strings as numeric values when necessary.

A further optimization of your code is to leave out the optional ",n" after the m$ on the SPLIT command making the array size implied by the amount of data provided.

Code: Select all

INPUT n$
SPLIT n$ TO m$ WITH " "
PRINT m$(0),m$(1),m$(0)+m$(1)
P.S.: I went ahead and posted your original code (with proper credit of course) on Rosetta. I've found it to be an excellent learning and teaching web site and look forward to having my future crappy code scrutinized.
smart BASIC Rocks!

- Scott : San Diego, California

Post Reply