Pentacles

General FreeBASIC programming questions.
Post Reply
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Pentacles

Post by badidea »

dodicat wrote:...
You have given me an idea to cook those hexagons au naturel
...
If you look long enough, you can spot the hidden Easter egg.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

Can the object code that generates an image get a bug ?
https://en.wikipedia.org/wiki/Varroa_de ... _the_world
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Pentacles

Post by albert »

@Richard

I wrote a dictionary optimizer , to build the smallest possible dictionary , for a given bit size.

You just set the size for how many bits you want in the dictionary..

I got it set to automatically exit, if no more values can be added to the dictionary..

Code: Select all


screen 19

dim as string dict  = ""
dim as longint high 

dim as ubyte size = 16
dict = string( size , "0" )
do
    
    if instr( 1 , dict , ( right( dict , size - 1 ) + "1" ) ) = 0 then dict+= "1"
    if instr( 1 , dict , ( right( dict , size - 1 ) + "0" ) ) = 0 then dict+= "0"
    
    print  len( dict )
    
    if len( dict ) > high then high = len( dict ) : else exit do
    
loop

dim as longint count = 0
dim as string n1
for a as longint = 0 to ( ( 2 ^ size ) - 1 )
    n1 = right( string( size , "0" ) + bin( a ) , size )
    if instr( 1 , dict , n1 ) > 0 then count+= 1
next

print
print "Dictionary size = " ; len( dict ) ; " Bits"
print
print "values in dict = " ; count
print
'print "Dictionary = " ; dict

sleep
end

Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

@albert.
What is a dictionary?
What can I put in it?
How do I add things to the dictionary?
How do I look things up in the dictionary?
How do I sort the dictionary to make it faster to find an entry?

I have almost 7000 English words in a text file, one word per line, about 3.4 Mbyte.
How should I store them so I can find things quicker?
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Pentacles

Post by albert »

@Richard

It just builds the dictionary a bit at a time..
if a 1 or 0 adds a value to the dictionary then it adds a 1 or 0.. else it's done and exits..

So it optimizes the dictionary so that every bit is utilized..

So a 0 to 255 ( 8 bit ) dictionary is only 262 bits.. 7 bits over 255..
So a 0 to 65535 ( 16 bit ) dictionary is only 65550 bits.. 15 bits over 65535..
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pentacles

Post by dodicat »

A file searcher.

Code: Select all


#include "file.bi"

type info
    as long position
    as long linenumber
    end type

Function tally(somestring As String,partstring As String,arr() As info) As info
    Dim As long i,j,ln,lnp,count,ten
    dim as info num
    Dim As boolean filler=false
    ln=Len(somestring)
    lnp=Len(partstring)
    start:
    count=0
    i=-1
    Do
        i+=1
        if somestring[i]=10 and filler=true then ten+=1
        If somestring[i] <> partstring[0] Then Goto skip 
        If somestring[i] = partstring[0] Then
            For j=0 To lnp-1 
                If somestring[j+i]<>partstring[j] Then Goto skip
            Next j
        End If
        count+=1
        If filler = true Then arr(count).position=i+1 :arr(count).linenumber=ten+1
        i=i+lnp-1
        skip:
    Loop Until i>=ln-1 
    If filler = false Then Redim arr(1 to count) 'size is now known, repeat the operation to fil arr()
    num.position=count
    If filler=true Then Goto _return
    filler=true
    Goto start
    _return:
    num.linenumber=ten
    Return num
End Function

Function savefile(filename As String,p As String) As String
      Dim As Long n=Freefile
      If Open (filename For Binary Access Write As #n)=0 Then
            Put #n,,p
            Close
      Else
            Print "Unable to save " + filename:Sleep:End
      End If
      Return filename
End Function

Function loadfile(file As String) As String
	If Fileexists(file)=0 Then Print file;" not found":Sleep:End
      Dim As Long  f=Freefile
      Open file For Binary Access Read As #f
      Dim As String text
      If Lof(f) > 0 Then
            text = String(Lof(f), 0)
            Get #f, , text
      End If
      Close #f
      Return text
End Function

 #define range(f,l) Int(Rnd*(((l)+1)-(f))+(f))
 #define Q iif(rnd>.5,range(65,90),range(97,122))
 
 dim as string w(1 to 4)
 
 #macro ww
 w(1)=chr(q,q):w(2)=chr(q,q,q):w(3)=chr(q,q,q,q):w(4)=chr(q,q,q,q,q)
 #endmacro
dim as string s
print "please wait . . ."
for n as long=1 to 2000000
    ww
    s+=w(range(1,4))+chr(10)
next n

savefile("tallystuff.txt",s)
var lf=loadfile("tallystuff.txt")
print "file saved and loaded"
print "file size ";filelen("tallystuff.txt")/1024/1024; "  MB."
print "start of the file:"
print mid(lf,1,60)+" e.t.c.  e.t.c. . . ."
redim as info g()
dim as info x
print
dim as string find="WoG"
dim as double t=timer,t2
x= tally(lf,find,g()) 
t2= timer
print "looking for ";find
print "position in file","line in file"
for n as long=1 to ubound(g)
    print g(n).position,,g(n).linenumber
next
print
print "number of occurriences","number of lines"
print x.position,,x.linenumber
print "time taken for search ";t2-t


kill "tallystuff.txt"
print iif(fileexists("tallystuff.txt"),"delete tallystuff.txt manually","tallystuff.txt has been deleted")
sleep



 
optimized gcc gives silly warnings, completely in disacordance with freebasic.

warning: array subscript -1 is below array bounds of 'FBSTRING[4]' {aka 'struct <anonymous>[4]'} [-Warray-bounds]
*(FBSTRING**)&tmp$8$0 = (FBSTRING*)((uint8*)W$0 + -24ll);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



But -1 is the subscript of a dynamic array yet to be set.
This must surely put off folk just starting freebasic coding!


EDIT.
As MrSwiss points out in another thread, the warnings are from the unofficial gcc builds, gcc 5.2 is without these warnings.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Pentacles

Post by albert »

I wondered upon a website that said ; the U.S. Govt , had discovered how to make synthetic sapphires..

That they were using the technology , to make bullet-proof windows for govt. vehicles..

I tried to find the site again and had no luck..

As a former chef , I'd love to have synthetic sapphire knife blades... They would be forever sharp and never need sharpening..

The commercial potential for synthetic sapphire is endless , billions and billions of dollars...

bearings , armatures , non-stick cookware , knife blades , windows , weed-eater \ lawnmower blades , etc...etc...
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

@albert.
This subject is unrelated to FB. It is widely known and used in industry, and is easily searchable on the web. You can buy ceramic knives in a supermarket.

Sapphire is almost pure aluminium oxide = Al[sub]2[/sub]O[sub]3[/sub].
Like window glass, it is transparent when pure, but tinted by contaminants.
https://en.wikipedia.org/wiki/Sapphire

It is difficult to shape single sapphire crystals, so it is made as a composite powder, compressed in a mould, then baked into a ceramic.

Ceramic Knives and metal cutting tools are made from a composite powder that include zirconia and sapphire.
https://en.wikipedia.org/wiki/Ceramic_knife
Google, eBay, or Amazon 'ceramic kitchen knives'
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pentacles

Post by dodicat »

Nil desperandum carborundum.
https://latin4everyone.wordpress.com/20 ... -you-down/
Your new motto Albert.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Pentacles

Post by albert »

@Richard
@Dodicat

The website said the Govt. was extruding molten sapphire to form clear windows , for vehicles maybe also for space-craft ??
With the use of single atom , nano-motors , you might be able to form diamond ( carbon matrix ) plates . for windows??

But anyways , i got a question..

If i have several variables holding different values, how do i find the smallest variable that's greater than 0???
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

If i have several variables holding different values, how do i find the smallest variable that's greater than 0???
Are the variables in an array, or all in different places ?
How many is several ?
Do you know that there will always be a variable greater than zero ?
What if they are all negative or zero ?

Code: Select all

Dim As Double min_pos
Dim As Integer valid

#Macro find_min_pos( v )
If v > 0 Then
    If valid Then
        If min_pos > v Then min_pos = v
    Else
        min_pos = v
        valid = -1
    End If
End If
#Endmacro

Dim As Double vn = -1, vz = 0, v1 = 1, v3 = 3, v4 = 4

valid = 0
find_min_pos( vn )
find_min_pos( vz )
'find_min_pos( v1 )
'find_min_pos( v3 )
'find_min_pos( v4 )

If valid Then
    Print min_pos
Else
    Print "invalid"
End If
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Pentacles

Post by dodicat »

Talking about spacecraft, 20 minutes is a ridiculous time for signals (electro magnetic radiation) to reach mars, they cannot control or fly the helicopter on Earth in real time.
If I was one of the boffins I would have put a beacon near the helicopter and beamed back signals back to Earth and experimented with the interference between the out going signal and the incoming beacon signal to get information sent on the interference pattern, which exists in space all the way there.
Of course, maybe they are doing something similar as I write.
I do not believe for one minute, never mind 20, that nothing can go faster than the speed of electro magnetic radiation (= light speed).
Your crazy ideas are rubbing off, Albert.
I have got some Lewisian gneiss crystals which are 3,000 million and twenty five years old.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Pentacles

Post by jj2007 »

albert wrote:If i have several variables holding different values, how do i find the smallest variable that's greater than 0???
That's a trivial problem, albert, why don't you simply sit down and try to code it yourself?

Code: Select all

Dim Shared As Double MyVar(100000000), MinVar=1
For ct As Long=0 To 99999999
	MyVar(ct)=Rnd()-0.1
Next
For ct As Long=0 To 99999999
	if MyVar(ct)<MinVar and MyVar(ct)>0 Then MinVar=MyVar(ct)
Next

Print "min=";MinVar
sleep
Last edited by jj2007 on Apr 20, 2021 9:49, edited 1 time in total.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Pentacles

Post by Richard »

dodicat wrote:Your crazy ideas are rubbing off, Albert.
But what will we find underneath?
dodicat wrote:I have got some Lewisian gneiss crystals which are 3,000 million and twenty five years old.
Nice.
If I remember rightly, the Caledonian Orogeny was a music festival held in the summer of 1967. The Lewisian Gniess was formed during an earlier Caledonian orogeny, 490–390 million years ago, when the older sediments ( 3.0 Ga to 1.7 Ga ) were partially melted, so the crystals are not really 3000 million years old, they crystallised 440 ± 50 million years ago; on Tuesday. But the atoms were still made more than 4.5 billion years ago.
Post Reply