|
Post by tenochtitlanuk on Feb 16, 2020 16:50:55 GMT -5
My inclination is to replace Jack Kelly's versions by ones that DO work in LB 4.5. Any comments /better versions?
Array length is a badly described task, and various languages approached it different ways.. with different interpretations.
' Task Array length http://rosettacode.org/wiki/Array_length ' Determine the amount of elements in an array.
' Task is ambiguous- do they want number of elements or the memory space used??
' Using a dimensioned array it's difficult, as may be sparsely filled ' Many of us would use a string variable and word$ for this...
a$ ="apple orange banana"
print "Array <"; a$; "> contains "; numTerms( a$); " terms and occupies about "; lenArray( a$); " bytes."
end
function numTerms( i$) numTerms =1 for j =1 to len( i$) if mid$( i$, j, 1) =" " then numTerms =numTerms +1 next j end function
function lenArray( i$) lenArray =len( i$) end function Babbage task has several incorrect answers in other languages.
' http://rosettacode.org/wiki/Babbage_problem
' Charles Babbage, gave this example: ' What is the smallest positive integer whose square ends in the digits 269,696 ?
' He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.
n = 1
do n = n + 1 loop until right$( str$( n^2), 6) ="269696"
' loop until ( n^2 mod 1000000) = 269696 ' cf BBC BASIC answer should be using mod not div- copied by a Python user??
print "Smallest number whose square ends in ...269696 is "; n print "Its square is "; n^2
|
|
|
Post by tsh73 on Feb 17, 2020 7:54:54 GMT -5
Current implement of Babbage task seems working. Especially if got rid of "," in FORMAT string. As for array length Array in BASIC - DIM thing So I think approach with catching error and returning DIMmed length is right one. But of course it should work with LB Simple version what works in LB, single dimension array maxN=10
N=int(rnd(0)*maxN)+1 print "Len N=";N dim x(N)
print "Now let's deduce N" while tryX(i) print i; " is Ok" i=i+1 if i > maxN+1 then end wend print "Last valid x(i) was X(";i-1;")" end
function tryX(i) 'returns true if x(i) is valid, false (0) on error (out of bounds) on error goto [er] dummy = x(i) tryX =1 exit function [er] tryX=0 end function
Now one that solves mindless problem asked (really, what the ?!#?) N=2 print "Len N=";N
dim x$(2) x$(1)="apples" x$(2)="oranges"
print "Now let's deduce N" while tryX(i) print i; " is Ok" i=i+1 if i > 10 then end wend print "Last valid x(I) was X(";i-1;")" end
function tryX(i) 'returns true if x$(i) is valid, false (0) on error (out of bounds) on error goto [er] dummy$ = x$(i) tryX =1 exit function [er] tryX=0 end function
Using EVAL it could be made working with arbitrary array, string too Supporting more then single dimension here
or making it run faster by using say binary search looks over-engineering for me.
|
|
|
Post by tsh73 on Feb 17, 2020 8:09:43 GMT -5
Now function that might really get useful
'Determine the amount of elements in an array. 'As an example use an array holding the strings 'apple' and 'orange'.
N=2 print "Len N=";N
dim x$(2) x$(1)="apples" x$(2)="oranges"
print "Length of x$() is "; arrLen("x$", 1000)
'now numeric array N=7 print "Len N=";N dim y(N) print "Length of y() is "; arrLen("y", 1000)
print "Length un-dimmed array z() is "; arrLen("z", 1000)
function arrLen(arr$, maxLen) on error goto [er] for i = 1 to maxLen if right$(arr$, 1)="$" then dummy$=eval$(arr$;"(";i;")") else dummy=eval(arr$;"(";i;")") end if next exit function [er] arrLen=i-1 end function
results
Len N=2 Length of x$() is 2 Len N=7 Length of y() is 7 Length un-dimmed zrray z() is 10
|
|
|
Post by tsh73 on Feb 17, 2020 8:13:48 GMT -5
I suggest adding new entry, while renaming old one to "LBB" Because "This program runs only under LB Booster version 3.05 or higher" clearly means that.
|
|
|
Post by honkytonk on Feb 17, 2020 8:32:10 GMT -5
a$ ="apple orange banana split yes" dim b$(1000000) for x=1 to len(a$) b$(x)=word$(a$,x) next x for x=1 to 1000000000000 if b$(x)="" then n=x-1: exit for next x print n
|
|
|
Post by Carl Gundel on Feb 17, 2020 9:23:21 GMT -5
I suggest adding new entry, while renaming old one to "LBB" Because "This program runs only under LB Booster version 3.05 or higher" clearly means that. Sure, but it is only a courtesy to make a new category for LBB in my humble opinion. Of course we do not own the Rosetta Code site, and perhaps the owners of that site would disagree about how to organize and classify such variants.
|
|
|
Post by Brandon Parker on Feb 19, 2020 10:04:36 GMT -5
I vote that anything which does not run under Liberty BASIC (i.e. set to run under LBB) be removed from the Rosetta Code listings for Liberty BASIC. Jack Kelly was an instigator in the past and his posting code under Liberty BASIC that requires LBB is completely foolish on his part since the resulting execution is NOT Liberty BASIC it is BBC Basic in the end. From my experience, Rosetta Code organizers do not police this type of issue on their own; they tend to allow the community to police the site for the most part.
On a different note, while arrays are being mentioned, would anyone be interested in a dedicated place for my Dynamic Array Library and Import Architect to live. I would be up for creating a separate forum on Proboards for them. Let me know if there is a great deal of interest and I will get started making a home for them; PM'ing me is probably best to prevent going too far off-topic on this thread.
{:0)
Brandon Parker
|
|
|
Post by sarossell on Feb 19, 2020 11:09:59 GMT -5
I have had similar experience with the RC site regarding content. I could be wrong, but I got the impression that it was run by a single, very busy, college student with little time to manage details.
:@)
|
|
|
Post by Carl Gundel on Feb 19, 2020 11:13:46 GMT -5
I vote that anything which does not run under Liberty BASIC (i.e. set to run under LBB) be removed from the Rosetta Code listings for Liberty BASIC. Jack Kelly was an instigator in the past and his posting code under Liberty BASIC that requires LBB is completely foolish on his part since the resulting execution is NOT Liberty BASIC it is BBC Basic in the end. From my experience, Rosetta Code organizers do not police this type of issue on their own; they tend to allow the community to police the site for the most part. On a different note, while arrays are being mentioned, would anyone be interested in a dedicated place for my Dynamic Array Library and Import Architect to live. I would be up for creating a separate forum on Proboards for them. Let me know if there is a great deal of interest and I will get started making a home for them; PM'ing me is probably best to prevent going too far off-topic on this thread. {:0) Brandon Parker It's certainly true that we have no obligation to preserve any code which does not run on LB. Moving it to an LBB category would be done only as a courtesy.
|
|
|
Post by Carl Gundel on Feb 19, 2020 11:15:05 GMT -5
I'm not sure we will need a separate category for LB5. You can include more than listing for any solution. If any listing is LB4 or LB5 specific, we simply mark it as such.
|
|
|
Post by Rod on Feb 19, 2020 11:19:58 GMT -5
Remove is too strong a word, tweaking the code to run under Liberty is all that is needed. All posts should run under Liberty. We are where we are, it was not a great experience getting there and we don’t need to open old wounds. All contributions are valued, from wherever they come, they just need to run, as is, on Liberty.
|
|
|
Post by Brandon Parker on Feb 19, 2020 12:31:40 GMT -5
Remove is too strong a word In my opinion, it would not be too strong of a word. Since when did the world become so soft that removing something that is incorrect become offensive? I mean, what would the C++ community do if someone were to post Python code under a C++ task label. It would get removed or "changed" to C++, but either way that's still removing the Python code. I am just a "to the point" type of person. There's no point in beating-around-the-bush to try and be nice; just do what is required and that is it. {:0) Brandon Parker
|
|
|
Post by Rod on Feb 21, 2020 4:20:41 GMT -5
I edited the Liberty BASIC page and set the community link to point here. Whether we need a new board or not is up to admin only they have the power to create it. Personally, just including Rosetta Code in the title and posting to this board is enough for me.
|
|
|
Post by Rod on Feb 21, 2020 4:22:49 GMT -5
An effective aggregator will bring all this together. At the moment we all tend to forget about RC and it surfaces sporadically. I hope someone better skilled than I is working on it.
|
|