Squares

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

Re: Squares

Postby jj2007 » Mar 11, 2019 9:04

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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 12, 2019 23:58

@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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 13, 2019 0:51

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: 2953
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Mar 13, 2019 5:19

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: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Postby dodicat » Mar 13, 2019 10:36

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

Re: Squares

Postby albert » Mar 13, 2019 18:46

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

Re: Squares

Postby badidea » Mar 13, 2019 19:59

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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 14, 2019 0:37

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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 15, 2019 17:34

@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: 3222
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Squares

Postby MrSwiss » Mar 15, 2019 18:13

@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
Posts: 9135
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Squares

Postby fxm » Mar 15, 2019 19:39

???:

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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 15, 2019 21:39

@fxm

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

Re: Squares

Postby dodicat » Mar 15, 2019 22:18

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

Re: Squares

Postby Richard » Mar 15, 2019 23:36

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; viewtopic.php?p=253026#p253026
albert
Posts: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Mar 16, 2019 0:20

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


Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests