Squares

General FreeBASIC programming questions.
Locked
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Squares

Post by jj2007 »

If instr() takes several minutes, then you have a serious design problem. Can you post your code?

Code: Select all

93 ms for finding 195400 occurrences of 'Jesus' in a 777 MB file composed of 200x 'bible.txt'
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Richard

Whats the opposite of the "Big Bang"?
What do they call it , when the universe compresses back to a single star?

That's what i want to call my Data Compressor..
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

I heard a voice in the wind that said the word for the opposite of the "Big Bang" was called the "Singularity" , is that correct??

I kinda like
"Black Hole" compressor
or
"Nemesis" compressor

"Singularity" sounds kinda odd..

I've been calling all my other compressors "Binary Data Compressor" and the output *.BDC files , instead of *.ZIP

I still need to write the output , to see if it compresses or expands the data.
All my other compressors expanded the data. So it might not work.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Post by Richard »

Albert wrote:Whats the opposite of the "Big Bang"?
What do they call it , when the universe compresses back to a single star?
The Big Crunch.
https://en.wikipedia.org/wiki/Big_Crunch
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Post by dodicat »

I think when you compress a fairy tale you get a one liner.
...
So the universe implodes – no matter
...
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

I think I'll stick with "Binary Data Compressor" BDC for short...
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Post by badidea »

The "Big Crunch" is one of the theories, there is also the "Big Rip", the "Big Freeze", the "Big Chill" (sound more comfortable then "Big Freeze"), "Big Bounce", "Big Snap" and more.

To be sure, reserve a table at "The Restaurant at the End of the Universe", or if you don't want to wait so long, maybe the upcoming Marvel movie "Avengers: Endgame" will tell you.

Anyway, a data compression/deflation tool based on the Big Bang / Big Crunch sounds bad. Not much information will survive this cycle, I think.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

While i was playing around with my latest compressor algo.
I went off on a side program to analyze the numbers..

Out of ( 000_000 to 255_255 ) there's only 26 + 30 + 100 unique values.

When you look at those possible combinations ( 0 to 25 ) x ( 0 to 29 ) x ( 0 to 99 ) = 71,775 = 16 bits..
Or 25,29,99 = > 16 bits

I thought maybe you could record the 0 to 99 , and then add 100 for the 0 to 29 and then add 100 for the 0 to 25 .. I'll run some tests to see.
So you could split a number ( maybe 1 byte ) , into 3 ranges , so that one number would hold all 3 values.
Maybe that number would be smaller than 32,768 ??

Code: Select all


screen 19

    
    dim as ulongint vals1(0 to 99)
    dim as ulongint vals2(0 to 99)
    dim as ulongint vals3(0 to 99)
    
    dim as string insa
    dim as string insb
    
    dim as string checka
    dim as string checkb
    dim as string checkc
    
    dim as string outs
    for a as longint = 0 to 255
        
        insa=right("000"+str(a),3)
        
        for b as longint = 0 to 255
            
            insb=right("000"+str(b),3)
            outs=insa+insb
            
            'record digits 1 & 2
            checka = mid(outs,1,2)
            vals1(val(checka)) = 1
            
            'record digits 3 & 4
            checkb = mid(outs,3,2)
            vals2(val(checkb)) = 1
            
            'record digits 5 & 6
            checkc = mid(outs,5,2)
            vals3(val(checkc)) = 1
            
        next
    next
    
    dim as longint count1
    dim as longint count2
    dim as longint count3
    for a as longint = lbound(vals1) to ubound(vals1)
        if vals1(a) = 1 then count1+=1
        if vals2(a) = 1 then count2+=1
        if vals3(a) = 1 then count3+=1
    next
    print
    print "checking values 000,000 to 255,255"
    print
    print "places 1 & 2 tot = " ; count1
    print "places 3 & 4 tot = " ; count2
    print "places 5 & 6 tot = " ; count3
    
sleep
end

albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Richard

I think you already wrote it , but i need a converter , to convert base 256 ascii , to base 10.
Can you give me a link to it?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Squares

Post by MrSwiss »

@albert,

seems, you are looking for a BCD encoder (binary coded decimal).
You may want to look at: Union as 'own' data-type which is only at byte level currently,
but can be extended by yourself, if needed/wanted ...
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Squares

Post by fxm »

???:

Code: Select all

Function Base256asciiToBase10 (Byref s As String, Byref u As Ulongint) As Integer  '' return value = 1 if conversion overflows (Len(s) > 8)
  Dim As Ubyte Ptr p = Cptr(Ubyte Ptr, @u)
  Function = 0
  For I As Integer = Len(s) - 1 To 0 Step -1
    If p = @u + 1 Then
      Function = 1
      Exit For
    End If
    *p = s[I]
    p += 1
  Next I
End Function

Dim As Ulongint u1
Dim As String s1 = Chr(1) & Chr(0)
Print Base256asciiToBase10(s1, u1), u1

Sleep
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@fxm

Your code returns an integer , instead of a base 10 string.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Post by dodicat »

Have you got gmp Albert?
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Post by Richard »

Albert wrote:I think you already wrote it , but i need a converter , to convert base 256 ascii , to base 10.
Can you give me a link to it?
I don't know exactly what you mean.
My converters go both ways so you need to accurately and separately describe the two formats you are converting between.
Is the data in a string or an array ?
What is base 256 ascii ?
Is “base 10” a string of ascii numeric digits { “0” – “9” } ?

Maybe; https://freebasic.net/forum/viewtopic.p ... 26#p253026
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

My compressor almost does 1:1 compression.

1,000 bytes in converts to 1,044 bytes out. My best yet!!
No matter what the input data is , it always outputs 1,044 bytes..

Code: Select all


screen 19

dim as string num=""
dim as string outputs=""
do
    
    dim as longint size = 1000
    
    num=""
    for a as longint = 1 to size
        num+=chr(int(rnd*256))
    next
    
    'print "converting number to decimal"
    dim as string decimal = ""'num
    for a as longint = 0 to len(num)-1 step 1
        decimal+=right("000"+str(num[a]),3)
    next
    
    dim as string _12  = ""
    dim as string _45 = ""
    dim as string _36 = ""
    for a as longint = 1 to len(decimal) step 6
        _12+= mid(decimal,a+0,2)
        _45+= mid(decimal,a+3,2)
        _36+= mid(decimal,a+2,1) + mid(decimal,a+5,1)
    next
    
    'print "12 = " ; _12
    'print "45 = " ; _45
    'print "36 = " ; _36 
    
    dim as string bin_12 = ""
    dim as string bin_45 = ""
    for a as longint = 1 to len(_12) step 2
        bin_12+= right(string(5,"0") + bin(val(mid(_12,a,2))),5)
        bin_45+= right(string(5,"0") + bin(val(mid(_45,a,2))),5)
    next
    
    dim as string bin_36 = ""
    for a as longint = 1 to len(_36) step 3
       bin_36+= right(string(10,"0") + bin(val(mid(_36,a,3))),10)
    next
    
    dim as string out_12 = ""
    dim as string out_45 = ""
    for a as longint = 1 to len(bin_12) step 8
        out_12+= chr(valulng("&B" + mid(bin_12,a,8)))
        out_45+= chr(valulng("&B" + mid(bin_45,a,8)))
    next
    
    dim as string out_36 = ""
    for a as longint = 1 to len(bin_36) step 8
        out_36+= chr(valulng("&B" + mid(bin_36,a,8)))
    next
    
    outputs = out_12 + out_45 + out_36
    
    print
    print "input  digits = " ; size
    print "output digits = " ; len(outputs)
    print "compression   = " ; 100 - ( 100 / (size / len(outputs)) )
    
    sleep
    
loop until inkey = chr(27)

end

Locked