
Post by tenochtitlanuk on May 30, 2020 10:27:40 GMT 5
Nice 'playing with your mind' trick, isn't it! Here's another catenary family graphic coloured chain between two fixed points..



Post by tenochtitlanuk on May 27, 2020 10:29:59 GMT 5
Thanks for the problems and attempts to see some value in my attempts on them! In my teacher days I'd have scribbled 'RTQ' on my early try Read The Question!!
I spent too long misinterpreting what was wanted. I was thinking of the sets of numbers as samples from a possible parent. Sorry it wasted our time but I learned some new tricks that were fun but not needed.
I also realised something I'd not noticed before when I used the debugger on code with arrays that were sorted, the code worked but the debugger did not display the rearranged terms... just the original values. ( CARL??)



Post by tenochtitlanuk on May 22, 2020 6:07:06 GMT 5
Getting addicted...



Post by tenochtitlanuk on May 21, 2020 15:55:49 GMT 5
And 5 minutes to present the beautifully named 'Sextic' of Cayley..



Post by tenochtitlanuk on May 21, 2020 15:34:16 GMT 5
I'm still unhappy that if numbers for a test are random samples, Occam's Razor implies that the smaller ratio that works would be chosen. ?? So my version gives 2 as the ratio for data set '2 8 128 512' rather than 4. Hey ho!! Otherwise happy on all tests so far..



Post by tenochtitlanuk on May 21, 2020 6:45:14 GMT 5
I was at a loss for an idea to kill half an hour I had free to play with LB.
With slightly relaxed Covid lockdown I'd just been for a walk 5km away further than I can get from home. Lovely Spring colours, cuckoo calling, very young foals with the wild ponies.. and felt rather tired!
Looked for a curve I'd not seen before and found the Trifolium.
The beauty of LB's easy graphics meant I'd coded it in minutes, so started playing. Sizes, colours, fills, rotations. Typical results..
I'll put a page with code on my site but it's pretty trivial. just finished, for me, a joyful day!!
Stay safe, everyone..



Post by tenochtitlanuk on May 20, 2020 8:41:53 GMT 5
EDIT Sorryposted wrong version.. And just realised 'If there can be more than one possible common ratio, print the highest one.'. I'd assumed the smallest was appropriate.
My current version. Test results.. 3 data items, being 128 8 512 Ratio = 2 8 16 32 64 128 256 512 1024 2048
4 data items, being 1500 300 37500 12 Ratio = 5 12 60 300 1500 7500 37500 187500 937500 4687500
3 data items, being 1 32 4 Ratio = 2 1 2 4 8 16 32 64 128 256
3 data items, being 1 216 6 Ratio = 6 1 6 36 216 1296 7776 46656 279936 1679616
3 data items, being 28 7 224 Ratio = 2 7 14 28 56 112 224 448 896 1792
3 data items, being 7168 112 7 Ratio = 2 7 14 28 56 112 224 448 896 1792
4 data items, being 1500 300 37500 12 Ratio = 5 12 60 300 1500 7500 37500 187500 937500 4687500
open "challenge3_data.txt" for output as #fOut #fOut "7" ' ie seven sets follow with number of terms specified by first number in data line.
#fOut "3 128 8 512" ' these example numbers are in the desired set but in no particular order #fOut "4 1500 300 37500 12" ' this second set with 4 example numbers is a set with a different ratio. #fOut "3 1 32 4" #fOut "3 1 216 6" #fOut "3 28 7 224" #fOut "3 7168 112 7" #fOut "4 1500 300 37500 12" close #fOut
open "challenge3_data.txt" for input as #fIn line input #fIn, c$
for j =0 to val( c$) 1 ' each new test case line input #fIn, d$ ' data for this case N =val( word$( d$, 1, " ")) sample$ =mid$( d$, 1 +instr( d$, " ")) print N; " data items, being "; sample$
R =val( word$( HCF$( sample$, N), 2, " ")) start =val( word$( HCF$( sample$, N), 1, " ")) print " Ratio = "; R
for q =0 to 8 term = start *R^q print using( "###########", term); next q
print "": print ""
next j
close #fIn
end
function HCF$( i$, nTerms) ' given eg "128 8 512" and 3 returns HCF$ ie 6 ( start) and ratio ( 4) .. or 2 if preferred Occam solution) HCF =1E20 smallest =1E20
for m =1 to nTerms 1 ' eg if three terms, m runs from 1 to 2 for n =m +1 to nTerms ' and n from m +1 to 3 a =val( word$( i$, m, " ")) if smallest >a then smallest =a b =val( word$( i$, n, " ")) HCF =min( HCF, max( b, a) /min( b, a)) next n next m
a =val( word$( i$, nTerms, " ")) if smallest >a then smallest =a
[o] if HCF^0.5 =int( HCF^0.5) then HCF =HCF^0.5: goto [o]
HCF$ =str$( smallest) +" " +str$( HCF) end function



Post by tenochtitlanuk on May 18, 2020 12:43:03 GMT 5
Sorry, no! There's a bit of a trick to the problem.. anyone else have the answer? ( No online cheating, of course..)



Post by tenochtitlanuk on May 16, 2020 6:58:52 GMT 5
The shape of any freehanging rope suspended from two points not necessarily at the same height. Basically a 'hyperbolic cos'.
Quick bit of fun to create the graphic below.  Code below..
Once I had the cosh( function, I felt ready to tackle Amazon's hanging cable problem... how far apart are the towers?
nomainwin
WindowWidth =600 WindowHeight =600
open "Catenaries" for graphics_nsb as #wg
#wg "trapclose quit" #wg "size 2 ; fill lightgray"
for a =0.4 to 8 step 0.1 #wg "up ; goto 0 0 ; down"
s =int( a /8 *256) col$ =str$( s) +" 50 " +str$( 255 s) #wg "color "; col$
for x =6 to 6 step 0.05 y =a *cosh( x /a) #wg "goto "; 300 +50 *x; " "; 580 50 *y oldX =x oldY =y scan next x
next a
#wg "getbmp scr 0 0 600 600" bmpsave "scr", "catenaryFamily2.bmp"
wait
function cosh( x) cosh =( 1 +exp( 0 2 *x)) /( 2 * exp( 0 x)) end function
sub quit h$ close #wg end end sub



Post by tenochtitlanuk on May 14, 2020 15:09:15 GMT 5
I thought much the same ways. Especially the need to think and optimise... Once I knew it worked for the original two examples, I did a kind of Monte Carlo method generating k and s at random but in range. Immediately showed how slow ten digits could get! It's quite fun to watch for the smaller k values, but for 5 or more digits gets slow.....
EDIT (updated code) Typical grabbed output.. Testing 4 digit numbers, between 1023 and 9876 whose digits sum to 6 1023 is OK for sum = 6 3210 is OK for sum = 6 Found
Testing 2 digit numbers, between 10 and 98 whose digits sum to 20 None
Testing 2 digit numbers, between 10 and 98 whose digits sum to 10 19 is OK for sum = 10 91 is OK for sum = 10 Found
Testing 2 digit numbers, between 10 and 98 whose digits sum to 3 12 is OK for sum = 3 30 is OK for sum = 3 Found
Testing 7 digit numbers, between 1023456 and 9876543 whose digits sum to 38 1256789 is OK for sum = 38 9876530 is OK for sum = 38 Found
Testing 3 digit numbers, between 102 and 987 whose digits sum to 11 128 is OK for sum = 11 920 is OK for sum = 11 Found
Testing 6 digit numbers, between 102345 and 987654 whose digits sum to 15 102345 is OK for sum = 15 543210 is OK for sum = 15 Found
Testing 5 digit numbers, between 10234 and 98765 whose digits sum to 36 None
Testing 5 digit numbers, between 10234 and 98765 whose digits sum to 9 None
As before I append my code lower on this page!
' Weekly Challenge problem #2
' You have two whole numbers k and s ( 1 <= k <= 10, 1 <= s <= 100).
' Find the biggest and the smallest numbers so that: '  each one is made up out of nonrepeating digits '  each one has k digits '  each one doesn't start with a 0 '  the sum of digits is s
' If there are no numbers that satisfy these conditions then output "none" ' k s data 4, 6 'max = 3210, min = 1023 data 2, 20 'none data 2, 10 'max = 91, min = 19 data 2, 3 'max = 30, min = 12 data 7, 38 'max = 9876530, min = 1256789 data 3, 11 'max = 920, min = 128 data 6, 15 'max = 543210, min = 102345 data 5, 36 'none data 5, 9 'none
open "anaysis2.txt" for output as #fOut
global digit$, k, s, finished, result$ digFwd$ ="0123456789" digRev$ ="9876543210" order$ ="1023456789" ' smallest number is sum of leftmost k characters of this.
for d =1 to 9 read k, s result$ ="None"
biggestPoss =val( left$( digRev$, k)) lowestPoss =val( left$( order$, k)) #fOut " Testing "; k; " digit numbers, between ";lowestPoss; " and "; biggestPoss; " whose digits sum to "; s print " Testing "; k; " digit numbers, between ";lowestPoss; " and "; biggestPoss; " whose digits sum to "; s
for n =lowestPoss to biggestPoss call test n if finished =1 then exit for next n
print result$
next d
wait
sub quit h$ close #fOut end sub
sub test n ' testNumber finished =0 n$ =str$( n) available$ =digit$ for p =1 to len( n$) sum =sum +val( mid$( n$, p, 1)) next p if ( sum =s) and digitsDifferent( n$) =1 then #fOut n$; " is OK for sum = "; s: print n$; " is OK for sum = "; s: result$ ="Found"
'if ( sum >10^k) then finished =1': print "None." scan end sub
function digitsDifferent( n$) digitsDifferent =1 for q =1 to len( n$) 1 currentDigit$ =mid$( n$, q, 1) if instr( mid$( n$, q +1), currentDigit$) then digitsDifferent =0 next q end function



Post by tenochtitlanuk on May 10, 2020 16:31:27 GMT 5
Tried again on another machine. Still get Com1 as an invalid handle. One small success managed to get 'cutecom' in Linux on the menu selection to work withoud needing 'sudo cutecom' at terminal as previously. But any comms terminals installed under Wine fail to see the port.. Out of time and ideas. Not a dealbreaker for me, but very annoying! Thanks for your suggestions perhaps you'll think of something which should have'seemed obvious to me!



Post by tenochtitlanuk on May 9, 2020 11:55:16 GMT 5
Thanks for taking the time to give useful suggestions. And further thoughts!
I still can't get it working under Wine. Tried symlink, group access, Registry editing, resetting... I wonder if I did the registry edit wrongly? My setup is the same as yours.. Mint 19.3 Cinnamon, Wine 4.0.5
Very frustrating to see the device steadily streaming the ten channels from a Linux serial terminal, but be unable to access them in LB/Wine



Post by tenochtitlanuk on May 8, 2020 8:49:43 GMT 5
Recently found a USB A2D converter in my electronics glory hole. It streams ten bit values continuously. Intended to try it on LB BUT.. ...I run LB4.5 under Wine and don't know how to access /dev/ttyUSB0 ...I have LB5 running native on Linux, but serial input is not yet available there...
So, do I have to fire up my old one remaining Windows 10 machine?? Thoughts??



Post by tenochtitlanuk on May 5, 2020 9:41:43 GMT 5
Do you only allow each number to appear once? And must they be less than the sum required? I generated 50 random integers including ones which were too high, and got results..
13,26,16,8,5,26,21,10,16,22,4,7,3,21,22,16,15,11,13,28,14,14,7,5,25,8,24,25,24,14,23,29,21,5,26,27,23,2,26,29,24,9,7,17,11,18,6,6,12,1
13 + 4= 17 16 + 1= 17 8 + 9= 17 5 + 12= 17 10 + 7= 17 10 + 7= 17 10 + 7= 17 16 + 1= 17 4 + 13= 17 3 + 14= 17 3 + 14= 17 3 + 14= 17 16 + 1= 17 15 + 2= 17 11 + 6= 17 11 + 6= 17 5 + 12= 17 8 + 9= 17 5 + 12= 17 11 + 6= 17 11 + 6= 17
'Weekly Challenge problem #1 [level: easy]
'You are given a list of numbers and a number k. 'You should print out whether any two numbers from the list add up to k. 'Example: given [10, 15, 3, 7] and k of 17, print "yes" since 10 + 7 is 17. 'Bonus points: can you do this in one pass?
dim num( 100)
'n$ ="10,15,3,7,32,1,243,2,6"
for check =1 to 50 n$ =n$ +str$( int( 30 *rnd( 1))) if check <>50 then n$ =n$ +"," next check
print n$
sum =17
cnt =1
do e$ =word$( n$, cnt, ",") a =val( e$) num( cnt) =a cnt =cnt +1 loop until e$ =""
cnt =cnt 1
for first =1 to cnt 1 if num( first) <sum then for second =first +1 to cnt if num( first) +num( second) =sum then print num( first); " + "; num( second); "= "; sum next second end if next first



Post by tenochtitlanuk on May 2, 2020 14:08:16 GMT 5
I ran
page$=httpget$("https://finance.yahoo.com/quote/VIAC?p=VIAC&.tsrc=finsrchv1")
open "page.txt" for output as #fOut #fOut page$; close #fOut
The saved text included headings and data. Too lazy to write any parsing code, BUT.. searching in a text editor for as an example 'Previous Close' and find this section.. Previous Close</span></td><td class="Ta(end) Fw(600) Lh(14px)" datatest="PREV_CLOSEvalue" datareactid="15"><span class="Trsdu(0.3s) " datareactid="16">17.26</spa.... The data associated with that heading is correctly found. I helped another LB poster do something similar downloading from a webpage and parsing out data in his case to generate barcodes and printing them..
It's MESSY to search like this in LB, but straightforward. Only worth while if you have only one or a few target pages.

