## Squares

General FreeBASIC programming questions.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Yah-Zip

I got it fixed.... Now all the nibbles start with "1" and end in "0"

Here's Test-Bed.bas.. Where i write the decompression..

Still compresses 90+% after 100 loops..

If the nibble is 0 then the out is "1111 + 0" which can't be mistaken for any other combo..

I need some help with the decompression... I got the de-compressor started..

nibble 1 is in compressor bits1 and de-compressor bin1
nibble 2 is in compressor bits2 and de-compressor bin2

Code: Select all

`Declare Function      compress_loop( chrs as string ) as stringDeclare Function decompress_loop( chrs as string ) as stringscreen 19'====================================================================='====================================================================='start program'====================================================================='=====================================================================dim as double time1 , time2 , time3 , time4do       randomize       dim as string s = ""    For n As Long = 1 To 8        s+=chr(Int(Rnd*256))    Next       time1=timer    'begin compress        dim as string comp = s            'do            '    dim as longint chk = len(comp) - 1            '    comp = compress_loop(comp)            '    if len(comp) >= chk then exit do            '    if inkey = chr( 27 ) then end            'loop            for a as longint = 1 to 1 step 1                comp = compress_loop(comp)            next    'end compress    time2 = timer       time3=timer    'begin decompress        dim as string final_out = comp        for a as longint = 1 to 1 step 1            final_out = decompress_loop(final_out)        next    'end decompress    time4 = timer      'sleep       print string(99,"=")    print "inp = " ; (s)    print string(99,"=")    print "out = " ; (final_out)    print    print "compress time   = "; time2-time1    print "decompress time = "; time4-time3    print       if s = final_out then print "Decompressed OK" else print "Decompression failed."    print string(99,"=")       sleep   loop until inkey = chr(27)sleepend'==============================================================================='==============================================================================='compress'==============================================================================='===============================================================================Function compress_loop( chrs as string ) as string       print "c inp = " ; len(chrs) ' , chrs        dim as string bits1 = ""    dim as string bits2 = ""    dim as string zeros = string( 8 , "0" )    dim as string n1 , n2 , n3    for a as longint = 1 to len( chrs ) step 1                n1 = zeros + bin( chrs[ a - 1 ] )        n1 = right( n1 , 8 )                n2 = ""        if mid( n1 , 1 , 1 ) = "1" then n2+= "1"        if mid( n1 , 2 , 1 ) = "1" then n2+= "10"        if mid( n1 , 3 , 1 ) = "1" then n2+= "11"        if mid( n1 , 4 , 1 ) = "1" then n2+= "0"        if n2 = "" then n2 = "1111"                n3 = ""        if mid( n1 , 5 , 1 ) = "1" then n3+= "1"        if mid( n1 , 6 , 1 ) = "1" then n3+= "10"        if mid( n1 , 7 , 1 ) = "1" then n3+= "11"        if mid( n1 , 8 , 1 ) = "1" then n3+= "0"        if n3 = "" then n3 = "1111"                bits1+= n2 + "0"        bits2+= n3 + "0"                'print n1 , val( "&B" + n1 ) , n2 , n3        'sleep        'if inkey = " " then end            next        print "c bit = " ; len( bits1 ) , bits1    print "c bit = " ; len( bits2 ) , bits2        dim as ubyte count1  = 0    dim as string str1    dim as ubyte dec1    do        str1 = str( len( bits1 ) / 8 )        dec1 = instr( 1 , str1 , "." )        if dec1 <> 0  then bits1+= "0" : count1+= 1    loop until dec1 = 0        dim as ubyte count2 = 0    dim as string str2    dim as ubyte dec2    do        str2 = str( len( bits2 ) / 8 )        dec2 = instr( 1 , str2 , "." )        if dec2 <> 0  then bits2+= "0" : count2+= 1    loop until dec2 = 0            dim as string final = ""    'dim as string s , n    for a as longint = 1 to len( bits1 ) step 8        's = mid( bits1 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits1 , a , 8 ) ) )    next    final+= "END"    for a as longint = 1 to len( bits2 ) step 8        's = mid( bits2 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits2 , a , 8 ) ) )    next        final = chr( count1 ) + chr( count2 ) + final        print "c fin = " ; len(final)       return final   end function'==============================================================================='============================================================================Function decompress_loop( chrs as string ) as string        print    print "d inp = " ; len( chrs )        dim as ubyte count1 = asc( left( chrs , 1 ) ) : chrs = mid( chrs , 2 )    dim as ubyte count2 = asc( left( chrs , 1 ) ) : chrs = mid( chrs , 2 )        dim as longint place = instr( 1 , chrs , "END" ) - 1        dim as string bits1 = left( chrs , place )    chrs = mid( chrs , place + 4 )    dim as string bits2 = chrs        dim as string bin1 = ""    dim as string zeros = string( 8 , "0" )    dim as string n1    for a as longint = 1 to len( bits1 ) step 1        n1 = zeros + bin( bits1[ a - 1 ] )        n1 = right( n1 , 8 )        bin1+= n1    next    bin1 = left( bin1 , len( bin1 ) - count1 )        dim as string bin2 = ""    for a as longint = 1 to len( bits2 ) step 1        n1 = zeros + bin( bits2[ a - 1 ] )        n1 = right( n1 , 8 )        bin2+= n1    next    bin2 = left( bin2 , len( bin2 ) - count2 )        print "d bit = " ; len( bin1 ) , bin1    print "d bit = " ; len( bin2 ) , bin2                return chrs   end function`

In Dodicats Zlib code....

Expands 2,000 bytes in and under.. 3,000 compresses to 25% after 100 loops.
Compresses 10,000 to 75% after 100 loops..Takes 9 seconds
Compresses 100,000 to 95% after 100 loops.. Takes 14 seconds..
Compresses 1,000,000 to 97% after 100 loops.. Takes 132 seconds..
Compresses 10,000,000 to 97% after 100 loops.. Takes 1,218 seconds..

I think i need to hard wire the outputs to speed it up , i think all the mid()'s are slowing it way down...

I told the voices in the wind , that if i accomplished compression , i'd call it "Yah-Zip" So i edited the post and renamed it "Yah-Zip"
The winds were howling and complaining , about the Binary Data Compressor ( BDC ) name...
They had told me , to step by 4's , and put the dictionary in at the end..
It steps by 4's and puts the 0's in at the end.. The 0's were the dictionary.. ( i guess?? )
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

I tried hard wiring the values to speed ti up and it actually slowed it down..
The timing increased to double , 32 seconds instead of 14 seconds..

But while hard wiring it.. i found a problem... there's duplicates...

n1 = left( 4 bits )

if mid( n1 , 1 , 1 ) = "1" then n2+= "1"
if mid( n1 , 2 , 1 ) = "1" then n2+= "10"
if mid( n1 , 3 , 1 ) = "1" then n2+= "11"
if mid( n1 , 4 , 1 ) = "1" then n2+= "0"
if n2 = "" then n2 = "1111"

hard wired:

if n1 = "0000" then n2 = "1111"
if n1 = "0001" then n2 = "00"
if n1 = "0010" then n2 = "110"
* if n1 = "0011" then n2 = "1100"
* if n1 = "0100" then n2 = "100"
if n1 = "0101" then n2 = "1000"
if n1 = "0110" then n2 = "10110"
if n1 = "0111" then n2 = "101100"
if n1 = "1000" then n2 = "10"
* if n1 = "1001" then n2 = "100"
if n1 = "1010" then n2 = "1110"
if n1 = "1011" then n2 = "11100"
* if n1 = "1100" then n2 = "1100"
if n1 = "1101" then n2 = "11000"
if n1 = "1110" then n2 = "110110"
if n1 = "1111" then n2 = "1101100"

There's two 100's and two 1100's
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

I fixed the duplicate problem... It still compresses 90+% after 100 loops..

n1 = left( 4 bits )

if mid( n1 , 1 , 1 ) = "1" then n2+= "1"
if mid( n1 , 2 , 1 ) = "1" then n2+= "10"
if mid( n1 , 3 , 1 ) = "1" then n2+= "11"
if mid( n1 , 4 , 1 ) = "1" then n2+= "01" , made it "01" instead of "0"
if n2 = "" then n2 = "1111"

hard wired:

if n1 = "0000" then n2 = "1111"
if n1 = "0001" then n2 = "010"
if n1 = "0010" then n2 = "110"
if n1 = "0011" then n2 = "11010"
if n1 = "0100" then n2 = "100"
if n1 = "0101" then n2 = "10010"
if n1 = "0110" then n2 = "10110"
if n1 = "0111" then n2 = "1011010"
if n1 = "1000" then n2 = "10"
if n1 = "1001" then n2 = "1010"
if n1 = "1010" then n2 = "1110"
if n1 = "1011" then n2 = "111010"
if n1 = "1100" then n2 = "1100"
if n1 = "1101" then n2 = "110010"
if n1 = "1110" then n2 = "110110"
if n1 = "1111" then n2 = "11011010"
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Yah-Zip

Here's "Yah-Zip"

Code: Select all

`Declare Function   compress_loop( chrs as string ) as stringDeclare Function decompress_loop( chrs as string ) as stringNamespace Zlibrary#inclib "zlib"Extern "C"    Declare Function compressBound(Byval sourceLen As Ulong) As Ulong    Declare Function uncompress(Byval dest As Ubyte Ptr, Byval destLen As Uinteger Ptr, Byval source As  Ubyte Ptr, Byval sourceLen As Ulong) As Long    Declare Function compress(Byval dest As Ubyte Ptr, Byval destLen As Uinteger Ptr, Byval source As  Ubyte Ptr, Byval sourceLen As Ulong) As LongEnd ExternFunction getpassedinfo(text As String,Byref passed_length As Integer) As String    Dim As String var1,var2    Dim As Integer pst    #macro splice(stri,char,var1,var2)    pst=Instr(stri,char)    var1="":var2=""    If pst<>0 Then        var1=Mid(stri,1,pst-1)        var2=Mid(stri,pst+1)    Else        var1=stri    End If    #endmacro    splice(text,"|",var1,var2)    text=var2    passed_length=Valint(var1)    Return textEnd Function'=================   UNPACK ===============Function unpack(file As String) As String    Dim As Integer passed_length    Dim As String text=getpassedinfo(file,passed_length)    Dim As Integer stringlength,destinationlength    stringlength=Len(text)    destinationlength =passed_length    Dim As Ubyte Ptr source    Dim As Ubyte Ptr  destination =Callocate(destinationlength,1)    source=@text[0]    Var mistake=uncompress(destination,@destinationlength, source, stringlength)    If mistake<>0 Then Print "There was an error":Sleep:End    Dim As String uncompressed    uncompressed=String(destinationlength,0)    For i As Integer = 0 To destinationlength- 1        uncompressed[i]=(destination[i])    Next    Deallocate destination    Return uncompressedEnd Function'===================  PACK ============Function pack(file As String) As String    Dim As String text=file    Dim As Integer stringlength,destinationlength    stringlength=Len(text)    destinationlength = compressBound(stringlength)    Dim As Ubyte Ptr source    Dim As Ubyte Ptr destination =Callocate(destinationlength,1)    source=@text[0]    Var mistake=compress(destination, @destinationlength, source, stringlength)    If mistake <>0 Then Print "There was an error"    Dim As String compressed    compressed=String(destinationlength,0)    For n As Integer=0 To destinationlength-1        compressed[n]=destination[n]    Next n    compressed=stringlength &"|"+compressed    Deallocate destination    Return compressedEnd FunctionEnd Namespace'=================================================================='=================================================================='test zipper'=================================================================='==================================================================screen 19Dim Shared As String sRandomizes=""dim as string check=""dim as string compare=""dim as longint length = 0dim as double compression = 0dim as longint loops = 0dim as double time1 , time2time1 = timerdo       loops+=1       'one time run , create initial string    if loops = 1 then        For n As Long = 1 To 100000            s+=chr(Int(Rnd*256))'+48        Next        compare =  s        length = len(s)    else        'modify compression to make further compression possible               s = compress_loop(s)        end if    check = s    compression = (100 - ( 100 / ( length / len(check) ) ))       Print "original string"    Print Len(s)    Print       Dim As String compressed=Zlibrary.pack(s)    s = compressed       Print "packed string "    Print Len(compressed)    Print       Dim As String uncompressed=Zlibrary.unpack(compressed)       Print "Retrieve"    Print Len(uncompressed)    Print    'Print "compression ratio  "; 100 - ( 100 / ( Len(s) / len(compressed) ) ) ; "%"    Print "compression ratio  "; 100 - ( 100 / ( length / len(s) ) ) ; "%"    Print Iif(uncompressed=check,"OK","ERROR")    Print "-------------------------------"       'sleep 1000       'if loops > 2 and (100 - ( 100 / ( length / len(s) ) )) < compression then exit do       print "press esc to exit."    print    print "press a key for next compression." ; " loops = " ; loops ; " out of 100."    'sleep        if inkey = chr(27) then exit do   loop until loops = 100time2 = timerprintprint  "Compress time = " ; time2 - time1printprint "Press a key to decompress."sleeps = str(loops) + "_" + s ' save as an output file...'=================================================================='decompress'==================================================================dim as longint dec = instr(1,s,"_")dim as longint count = val(left(s,dec-1))dim as string comp = mid(s,dec+1)dim as string val1dim as string outsfor a as longint = count to 2 step -1    s = Zlibrary.unpack(comp)    outs = decompress_loop(s)    comp = outsnextcomp = Zlibrary.unpack(comp)printprint "input = "; length , "output = " ; len(comp) , "compression ratio  "; 100 - ( 100 / ( length / len(s) ) ) ; "%"printif comp = compare then print "Decompression successful." else print "ERROR"printprintPrint "!!~~Done~~!!"Sleepend'==============================================================================='============================,==================================================='begin functions'==============================================================================='================='==============================================================Function compress_loop( chrs as string ) as string       print "c inp = " ; len(chrs) ' , chrs        dim as string bits1 = ""    dim as string bits2 = ""    dim as string zeros = string( 8 , "0" )    dim as string n1 , n2 , n3    for a as longint = 1 to len( chrs ) step 1                n1 = zeros + bin( chrs[ a - 1 ] )        n1 = right( n1 , 8 )                n2 = ""        if mid( n1 , 1 , 1 ) = "1" then n2+= "1"        if mid( n1 , 2 , 1 ) = "1" then n2+= "10"        if mid( n1 , 3 , 1 ) = "1" then n2+= "11"        if mid( n1 , 4 , 1 ) = "1" then n2+= "01"        if n2 = "" then n2 = "1111"                n3 = ""        if mid( n1 , 5 , 1 ) = "1" then n3+= "1"        if mid( n1 , 6 , 1 ) = "1" then n3+= "10"        if mid( n1 , 7 , 1 ) = "1" then n3+= "11"        if mid( n1 , 8 , 1 ) = "1" then n3+= "01"        if n3 = "" then n3 = "1111"                bits1+= n2 + "0"        bits2+= n3 + "0"                'print n1 , val( "&B" + n1 ) , n2 , n3        'sleep        'if inkey = " " then end            next        print "c bit = " ; len( bits1 ) ' , bits1    print "c bit = " ; len( bits2 ) ' , bits2        dim as string final = ""    dim as string s , n    for a as longint = 1 to len( bits1 ) step 8        's = mid( bits1 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits1 , a , 8 ) ) )    next    final+= "END"    for a as longint = 1 to len( bits2 ) step 8        's = mid( bits2 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits2 , a , 8 ) ) )    next        print "c fin = " ; len(final)       return final   end function'==============================================================================='============================================================================Function decompress_loop( chrs as string ) as string            return chrs   end function`

Here's the Test-Bed .. to write the decompression...

I need some help writing the scanner for the search and replace....

Code: Select all

`' Binary Data Compressor ( BDC )Declare Function      compress_loop( chrs as string ) as stringDeclare Function decompress_loop( chrs as string ) as stringscreen 19'====================================================================='====================================================================='start program'====================================================================='=====================================================================dim as double time1 , time2 , time3 , time4do       randomize       dim as string s = ""    For n As Long = 1 To 8        s+=chr(Int(Rnd*256))    Next       time1=timer    'begin compress        dim as string comp = s            'do            '    dim as longint chk = len(comp) - 1            '    comp = compress_loop(comp)            '    if len(comp) >= chk then exit do            '    if inkey = chr( 27 ) then end            'loop            for a as longint = 1 to 1 step 1                comp = compress_loop(comp)            next    'end compress    time2 = timer       time3=timer    'begin decompress        dim as string final_out = comp        for a as longint = 1 to 1 step 1            final_out = decompress_loop(final_out)        next    'end decompress    time4 = timer      'sleep       print string(99,"=")    print "inp = " ; (s)    print string(99,"=")    print "out = " ; (final_out)    print    print "compress time   = "; time2-time1    print "decompress time = "; time4-time3    print       if s = final_out then print "Decompressed OK" else print "Decompression failed."    print string(99,"=")       sleep   loop until inkey = chr(27)sleepend'==============================================================================='==============================================================================='compress'==============================================================================='===============================================================================Function compress_loop( chrs as string ) as string       print "c inp = " ; len(chrs) ' , chrs        dim as string bits1 = ""    dim as string bits2 = ""    dim as string zeros = string( 8 , "0" )    dim as string n1 , n2 , n3    for a as longint = 1 to len( chrs ) step 1                n1 = zeros + bin( chrs[ a - 1 ] )        n1 = right( n1 , 8 )                n2 = ""        if mid( n1 , 1 , 1 ) = "1" then n2+= "1"        if mid( n1 , 2 , 1 ) = "1" then n2+= "10"        if mid( n1 , 3 , 1 ) = "1" then n2+= "11"        if mid( n1 , 4 , 1 ) = "1" then n2+= "01"        if n2 = "" then n2 = "1111"                n3 = ""        if mid( n1 , 5 , 1 ) = "1" then n3+= "1"        if mid( n1 , 6 , 1 ) = "1" then n3+= "10"        if mid( n1 , 7 , 1 ) = "1" then n3+= "11"        if mid( n1 , 8 , 1 ) = "1" then n3+= "01"        if n3 = "" then n3 = "1111"                bits1+= n2 + "0"        bits2+= n3 + "0"                'print n1 , val( "&B" + n1 ) , n2 , n3        'sleep        'if inkey = " " then end            next        print "c bit = " ; len( bits1 ) , bits1    print "c bit = " ; len( bits2 ) , bits2        dim as ubyte count1  = 0    dim as string str1    dim as ubyte dec1    do        str1 = str( len( bits1 ) / 8 )        dec1 = instr( 1 , str1 , "." )        if dec1 <> 0  then bits1+= "0" : count1+= 1    loop until dec1 = 0        dim as ubyte count2 = 0    dim as string str2    dim as ubyte dec2    do        str2 = str( len( bits2 ) / 8 )        dec2 = instr( 1 , str2 , "." )        if dec2 <> 0  then bits2+= "0" : count2+= 1    loop until dec2 = 0            dim as string final = ""    'dim as string s , n    for a as longint = 1 to len( bits1 ) step 8        's = mid( bits1 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits1 , a , 8 ) ) )    next    final+= "END"    for a as longint = 1 to len( bits2 ) step 8        's = mid( bits2 , a , 4 )        'n = ""        'n+= right( "00" + bin( val( mid( s , 1 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 2 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 3 , 1 ) ) ) , 2 )        'n+= right( "00" + bin( val( mid( s , 4 , 1 ) ) ) , 2 )        'final+= chr( val( "&B" + n ) )        final+= chr( val( "&B" + mid( bits2 , a , 8 ) ) )    next        final = chr( count1 ) + chr( count2 ) + final        print "c fin = " ; len(final)       return final   end function'==============================================================================='============================================================================Function decompress_loop( chrs as string ) as string        print    print "d inp = " ; len( chrs )        dim as ubyte count1 = asc( left( chrs , 1 ) ) : chrs = mid( chrs , 2 )    dim as ubyte count2 = asc( left( chrs , 1 ) ) : chrs = mid( chrs , 2 )        dim as longint place = instr( 1 , chrs , "END" ) - 1        dim as string bits1 = left( chrs , place )    chrs = mid( chrs , place + 4 )    dim as string bits2 = chrs        dim as string bin1 = ""    dim as string zeros = string( 8 , "0" )    dim as string n1    for a as longint = 1 to len( bits1 ) step 1        n1 = zeros + bin( bits1[ a - 1 ] )        n1 = right( n1 , 8 )        bin1+= n1    next    bin1 = left( bin1 , len( bin1 ) - count1 )        dim as string bin2 = ""    for a as longint = 1 to len( bits2 ) step 1        n1 = zeros + bin( bits2[ a - 1 ] )        n1 = right( n1 , 8 )        bin2+= n1    next    bin2 = left( bin2 , len( bin2 ) - count2 )        print "d bit = " ; len( bin1 ) , bin1    print "d bit = " ; len( bin2 ) , bin2                return chrs   end function`
angros47
Posts: 1673
Joined: Jun 21, 2005 19:04

### Re: Squares

albert wrote:But while hard wiring it.. i found a problem... there's duplicates...

How many times have you repeated this part? There will always be duplicates, it is inevitable, because in n bits you can only have 2^n possible combinations, so you cannot map all the combinations of n bits in a number of bits lower than n.

In the past, I saw people trying to solve the Seven Bridges of Königsberg puzzle, or the Three utilities problem (both of them have no solution): most people, when told that there was no solution, dropped it, but some were so stubborn to try to solve it anyway, getting upset, and not even realizing that everyone else was looking at them and laughing. You are at that stage, now. You keep banging your head against the same problem over and over, making no progress... how many times have you restarted from scratch?

Sincerely, you would have more chances of success if you tried to invent a faster than light drive: for that, at least, there is no mathematical proof of its impossibility.

(sorry if my post sounds harsh, I don't want to belittle your efforts. I am just trying to save you some frustration)
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

I fixed the duplicate problem.. by making the 4th bit "01" instead of "0"
So now , there's no duplicates...

With 100,000 input , there's 25,000 nibbles...

If you make 1 nibble 3 bits instead of 4 bits , it would compress 25,000 bits.

if only 1 bit is set then the output is 2 bits = 25,000 *2 = 50,000 bits compressed
if 2 bits are set then the output is 2 , 3 or 4 bits = 0 or 25,000 or 50,000 bits compressed

So for 100,000 bytes = 800,000 bits in , it compresses around 150,000 bits..

I just need help with the scanner to separate the output bits back into the original nibbles..
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

I was mistaken in my above post..

For 100,000 bytes in , there's 200,000 nibbles..
200,000 \ 4 = 50,000 of each type of nibble..

If you shave off 1 bit , from 1 type of nibble , that's 50,000 bits of compression.
If you shave off 2 bits , from 1 type of nibble , that's 100,000 bits of compression.

So even though some sets are 8 bits out.. The compressed ones counter the expanded ones...And so it compresses...
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

I came up with an idea , about your line "Faster than light drive."

You have a laser bank computer... Then you have crystals that the lasers shine into..

Each crystal performs a different function..
So the laser beam splitter , shines into all the crystals at the same time..

So a rotate by 1 crystal , would be a mirrored saw tooth , with the end light , mirroring back to the first bit.

You'd have a crystal for each type of function..And all the functions would all be solved at the same time...
Then you just pick out the answer you want...

As the lasers come out of each crystal , they shine into a bank of laser receivers. then you just pick out the answer.

I think lasers can only pulse at 800 megahertz, and the distance the beam has to travel , might make the idea too slow...

Each crystal has mirrors and splitters and such , to output a desired function..
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

For 100,000 bytes in = 200,000 nibbles.
200,000 nibbles / 4 = 50,000 of each type of nibble.

n1 = left( 4 bits )

if mid( n1 , 1 , 1 ) = "1" then n2+= "1"
if mid( n1 , 2 , 1 ) = "1" then n2+= "10"
if mid( n1 , 3 , 1 ) = "1" then n2+= "11"
if mid( n1 , 4 , 1 ) = "1" then n2+= "01" , made it "01" instead of "0"
if n2 = "" then n2 = "1111"

hard wired:

if n1 = "0000" then n2 = "1111"
if n1 = "0001" then n2 = "010" = 1 bit compressed = 50,000 bits compressed
if n1 = "0010" then n2 = "110" = 1 bit compressed = 50,000 bits compressed
if n1 = "0011" then n2 = "11010"
if n1 = "0100" then n2 = "100" = 1 bit compressed = 50,000 bits compressed
if n1 = "0101" then n2 = "10010"
if n1 = "0110" then n2 = "10110"
if n1 = "0111" then n2 = "1011010"
if n1 = "1000" then n2 = "10" = 2 bit compressed = 100,000 bits compressed
if n1 = "1001" then n2 = "1010"
if n1 = "1010" then n2 = "1110"
if n1 = "1011" then n2 = "111010"
if n1 = "1100" then n2 = "1100"
if n1 = "1101" then n2 = "110010"
if n1 = "1110" then n2 = "110110"
if n1 = "1111" then n2 = "11011010"

So total compression = 250,000 bits = 30,000 bytes of compression..For 100,000 bytes input..
After you count in all the expanded sets , you got like 4-6 thousand bytes of total compression.
The output is actually larger than the input, But Zlib. is able to compress it by several thousand bytes...

From observation : as the output gets smaller , the compression drops dramatically each loop..
angros47
Posts: 1673
Joined: Jun 21, 2005 19:04

### Re: Squares

*sigh*
You wrote:
I fixed the duplicate problem.. by making the 4th bit "01" instead of "0"
So now , there's no duplicates...

Nibbles 0100 and 1000 : they produce 100 and 10
Nibble 0101: it produces 10010

When I have to decompress, if I find the sequence 10010, shall I interpret it as 0101, or as 0100+1000 ?
Posts: 2149
Joined: May 24, 2007 22:10
Location: The Netherlands

### Re: Squares

angros47 wrote:*sigh*

In case you did not believe my previous post, this was post #205 in this topic in 2010 (we are now at #7435, 2020):

Richard wrote:
Albert wrote:Do you think this method might work?????
Information theory says it cannot work without loss.
...

Having daily compression fantasy spam from albert is much better than dialy twisted physics spam or even subjects totally off-topic requiring heavy moderation.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

When I have to decompress, if I find the sequence 10010, shall I interpret it as 0101, or as 0100+1000 ?

1 = bit1 set
10 = bit2 set
11 = bit3 set
01 = bit4 set

plus the ending "0"

The first bit is the left most bit...

a 10010 is 10 + 01 + ending 0

possibilities:

1 + 0
1 + 10 + 0
1 + 11 + 0
1 + 01 + 0

1 + 10 + 01 + 0
1 + 11 + 01 + 0
1 + 10 + 11 + 0
1 + 10 + 11 + 01 + 0

10 + 0
10 + 11 + 0
10 + 01 + 0 <----- your query = 2nd bit and 4th bit are set = 0101
10 + 11 + 01 + 0

11 + 0
11 + 01 + 0

01 + 0

1111

I don't know if i got them all... I got 16 outputs ? that equals a nibble..

The 8 bits input is split into 2 nibbles..
compressor bits1 and decompressor bin1 hold the left nibbles..
compressor bits2 and decompressor bin2 hold the right nibbles..
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

That's why i was asking for help with the decompression...It's rather complicated..

10 + 01 + 0
10 + 0 + 10 ' you can't have a 10 + 0 + 1 or plus 10 , Each set has to end in a "0"

10 + 0 + 10 you can have two 10's in the same set..
You have to read ahead , and see if it's logical to add the next 1 or 2 digits.. Each set ends with a "0"
Last edited by albert on Jan 07, 2020 2:23, edited 3 times in total.
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

### Re: Squares

The old Circles topic evolved for people who go round in circles, the Squares topic was created for square people, not for experts in the calculus of geometry. Squares is somewhere the bonds of reality can be shed, along with the bounds of mathematics.

Albert needs a challenge that he believes is possible. FB can be a medium, like oil paint. You can dab it onto a page with your fingers or a brush, then step back to appreciate the result. Everyone learns at different rates and we all reach different points of suspended development in our many different dimensions of expression.

@angros47
I hope you can understand that it is better to support those in squares than to attack or abandon them. They should not be condemned to wander like the “Flying Dutchman”, scattering random posts throughout the forum forever.
https://en.wikipedia.org/wiki/Flying_Dutchman
https://en.wikipedia.org/wiki/Dunning%E ... ger_effect
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

After looking at it some more , i see your point...

if n1 = "0000" then n2 = "1111"
if n1 = "0001" then n2 = "010"
if n1 = "0010" then n2 = "110"
if n1 = "0011" then n2 = "11010"
if n1 = "0100" then n2 = "100" <---- ?
if n1 = "0101" then n2 = "10010" <----- ?
if n1 = "0110" then n2 = "10110"
if n1 = "0111" then n2 = "1011010"
if n1 = "1000" then n2 = "10" <----- ?
if n1 = "1001" then n2 = "1010"
if n1 = "1010" then n2 = "1110"
if n1 = "1011" then n2 = "111010"
if n1 = "1100" then n2 = "1100"
if n1 = "1101" then n2 = "110010"
if n1 = "1110" then n2 = "110110"
if n1 = "1111" then n2 = "11011010"

100-10 = 0100 + 1000
10010 = 0101

I'll play with it some , and correct the problem... also 10 = 1010