Squares

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

Re: Squares

Postby albert » Jun 09, 2019 21:31

For the the earth quake machine:

Tapping a steel stair rail in time with the wave forms. makes the waves bigger and bigger..till the rail is swaying like rubber.

If you tap it at the wrong time , the waves , break into harmonics, and the rail stops waving and goes into vibrating , or stops waving all together.

you have to tap it at just the right moment to get it doing like rubber.


The Tacoma Narrows bridge was destroyed , by wind pulsing in time with the waves going through the bridge.
The whole bridge was swaying like rubber.
That could be stopped by tapping the bridge out of phase with the wave traveling through it....
badidea
Posts: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Postby badidea » Jun 09, 2019 22:15

A suspension bridge is a delicate thing. I cannot absorb much energy. The bridge (actually an aquaduct) below, built 2000 years ago, is a bit sturdier. Lots of tapping needed.
Image
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jun 09, 2019 22:34

Just like the "Earth Quake Machine" can cause an object to wave like rubber.

It could be used as a powerful weapon or to protect infrastructure in a real earthquake..

Tesla never patented the machine... He destroyed it , as soon as the police came to his lab..

But now we know how it worked.. It can be used to stop buildings and bridges from swaying in an real life earthquake..

Maybe some day all bridges and commercial buildings , will be required to have and earth quake tamper , to counter waves.

You could become a ,millionaire or more by making those industrial tampers..

( I the construction world , they have dirt tampers , they call them "Tiggers" because they are black & orange like "Tigger The Tiger" in Whinnie the pooh cartoons.)

A big solenoid with a rubber tamper , knocking on the building or bridge , out of phase with the waves traveling through it , would stop it from swaying and waving..


You use a seismic detector ( on the walls of the building ) , like the geologists use to detect earth quakes , and use the output to set the rate of the tamper tamps.
Last edited by albert on Jun 09, 2019 23:38, edited 2 times in total.
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jun 09, 2019 23:10

For the Data Compression , it seems the best formula is:

dim as string outputs=""
for a as longint = 1 to len(binari) step 2
n1=mid(binari,a,2)
if n1="00" then outputs+="0"
if n1="01" then outputs+="01"
if n1="10" then outputs+="10"
if n1="11" then outputs+="11"
next

But you have to figure out if a single "0" is a "00" or part of a "01" or "10" ??? Can't figure it out...
coderJeff
Site Admin
Posts: 2909
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Squares

Postby coderJeff » Jun 09, 2019 23:39

It is impossible to figure out. This will be true for all combinations of bit patterns (dictionary), where at least one bit pattern (word) forms the beginning of another bit pattern (word). In your case using 0, 01, 10, 11, the "0" can be found at the beginning of "01", so there is ambiguity when trying to figure what word it is.

There are many combinations of bit patterns that will be impossible to figure.

In the example I gave earlier, I was careful to select words where the shorter words do not form the start of any longer words. 0, 10, 110, 111, so there is no ambiguity when trying to figure the next word.
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jun 09, 2019 23:47

@CoderJeff

if n1="00" then outputs+="0"
if n1="01" then outputs+="01"
if n1="10" then outputs+="10"
if n1="11" then outputs+="11"

You could start , with searching for "0000" and "000" since 10 01 only has 2 zeros.

I'm confused about it.. I have to keep pondering it , till i come to a conclusion about it....
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Tesla's Earth Quake Machine

Postby albert » Jun 09, 2019 23:57

I put all the posts together , for a synopsis on Tesla's Earth Quake Machine..


I found out , that Tesla's Earth Quake Machine , works with audio as well...

Waveform amplification:
You tap an object , and it creates a waveform in the object.
The waveform goes to the opposite side and returns , and then goes back out to the other side.
If, when the waveform is starting to go back out , you tap it again , it amplifies the waveform.
Each tap in time with the waveform , increases the waveform energy , ( the waves get bigger )

With audio:
You put a wine glass on a table , and set a speaker next to it..
You start the speaker pulsing at 1 second intervals.
Then you gradually speed up the audio pulses. to 9 10th's , 8 10th's 7 10th's
When you get the audio pulses in time with the waveform , the glass will start wobbling like rubber.
It will eventually shatter..

It's different than finding the resonance. You have to calculate the time it takes for the waveform to traverse the glass.


You could destroy a skyscraper with a woofer speaker , pulsing in time with the waveform..

=========================================================================
I think wave forms travel at the speed of sound??

At sea level , that's 460 mph to 480 mph...?? Not sure..

So you would convert that speed , into inches per second , and then calculate the diameter of the wine glass. To find the required pulse rate.

For a building or skyscraper the pulse rate would be like , every 3 or 4 second intervals..
========================================================================

Whatever the calculated pulse rate is, you would need to double it or half it..

Because you have to wait for the wave to traverse the glass and then return.. So it's double.. Before you blast it again.

=====================================================================================
Tapping a steel stair rail in time with the wave forms. makes the waves bigger and bigger..till the rail is swaying like rubber.

If you tap it at the wrong time , the waves , break into harmonics, and the rail stops waving and goes into vibrating , or stops waving all together.

you have to tap it at just the right moment to get it doing like rubber.

====================================================================================
The Tacoma Narrows bridge was destroyed , by wind pulsing in time with the waves going through the bridge.
The whole bridge was swaying like rubber.
That could be stopped by tapping the bridge out of phase with the wave traveling through it....

Just like the "Earth Quake Machine" can cause an object to wave like rubber.

It could be used as a powerful weapon or to protect infrastructure in a real earthquake..

Tesla never patented the machine... He destroyed it , as soon as the police came to his lab..

But now we know how it worked.. It can be used to stop buildings and bridges from swaying in an real life earthquake..

Maybe some day all bridges and commercial buildings , will be required to have and earth quake tamper , to counter waves.

You could become a ,millionaire or more by making those industrial tampers..

( I the construction world , they have dirt tampers , they call them "Tiggers" because they are black & orange like "Tigger The Tiger" in Whinnie the pooh cartoons.)

A big solenoid with a rubber tamper , knocking on the building or bridge , out of phase with the waves traveling through it , would stop it from swaying and waving..


You use a seismic detector ( on the walls of the building ) , like the geologists use to detect earth quakes , and use the output to set the rate of the tamper tamps.


albert_redditt@yahoo.com

Albert Redditt
315 W. Carrillo St. #104
Santa Barbara,Ca. 93101 U.S.A.
Last edited by albert on Jun 10, 2019 1:21, edited 1 time in total.
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jun 10, 2019 1:05

@CoderJeff

words(0) = "0"
words(1) = "01"
words(2) = "10"
words(3) = "111"

Compresses , but doesn't de-compress... ( compresses 76% after 40 loops. )

You could start by searching for "111" since it can never occur otherwise , but then you have to look behind to see if its 01 111..
Then you search for "11" , it must be 0110

Then you have to figure the "01" , "10" from "0 01 , 0 10

Seems to be easy, but it's a real complex search & replace..
badidea
Posts: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Postby badidea » Jun 10, 2019 9:45

Nothing complex about it, just not possible as coderJeff said.
0010 can be 0 01 0 or 0 0 10
badidea
Posts: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Postby badidea » Jun 10, 2019 9:49

coderJeff wrote:Infinite* scrolling maze: it never ends!
...

I think Albert is trapped in this maze :-)
dodicat
Posts: 5828
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Postby dodicat » Jun 10, 2019 10:29

You can use a standard findandreplace to return an original string by substitutions.

Code: Select all

 

Function findAndReplace(instring As String,find As String,replace As String) As String
    dim as string s=instring
    dim as long position=Instr(s,find)
    While position>0
        s=Mid(s,1,position-1) & replace & Mid(s,position+Len(find))
        position=Instr(position+Len(replace),s,find)
    Wend
    return s
End Function



dim as string w(1 to 4)
w(1)="0"       
w(2)="01"       
w(3)="10"       
w(4)="111"     


#define f 1+int(rnd*4)
dim as string s
randomize

do
    s=""
for n as long=1 to 50
    s+=w(f) 'w(1) or w(2) or w(3) or w(4)
next

dim as string copy=s
'substitutions
'"a" = "0"
'"b" = "1"
color 2:print s
color 15
s=findandreplace(s,"0","a")
print s
s=findandreplace(s,"a1","b")
print s
s=findandreplace(s,"ba","c")
print s
s=findandreplace(s,"111","d")
print s
print "===== REVERSE PROCESS =========="
print s
s=findandreplace(s,"d","111")
print s
s=findandreplace(s,"c","ba")
print s
s=findandreplace(s,"b","a1")
print s
s=findandreplace(s,"a","0")
color 2:print s;"    ";"<return>"
color 15
print copy;"    ";"<original>"
print iif(copy<>s,"Error","OK")
print
sleep
loop until inkey=chr(27)

 

It is ambiguous but you carry the ambiguity back.
For this type of problem I think you need to pass a little more information to a decompressor, and perhaps a custom find and replace.
dodicat
Posts: 5828
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Postby dodicat » Jun 10, 2019 13:37

Is this any help Albert?

Code: Select all

Function StringSplit(s_in As String,chars As String,result() As String) As Long
    Dim As Long ctr,ctr2,k,n,LC=len(chars)
    dim As boolean tally(Len(s_in))
    #macro check_instring()
        n=0
        while n<Lc
        If chars[n]=s_in[k] Then
        tally(k)=true
        If (ctr2-1) Then ctr+=1
        ctr2=0
        exit while
        end if
        n+=1
       wend
    #endmacro
   
    #macro split()
    If tally(k) Then
        If (ctr2-1) Then ctr+=1:result(ctr)=Mid(s_in,k+2-ctr2,ctr2-1)
        ctr2=0
    End If
    #endmacro
    '==================  LOOP TWICE =======================
    For k  =0 To Len(s_in)-1
        ctr2+=1:check_instring()
    Next k
    if ctr=0 then
         if len(s_in) andalso instr(chars,chr(s_in[0])) then ctr=1':beep
         end if
    If ctr Then Redim result(1 To ctr): ctr=0:ctr2=0 Else  Return 0
    For k  =0 To Len(s_in)-1
        ctr2+=1:split()
    Next k
    '===================== Last one ========================
    If ctr2>0 Then
        Redim Preserve result(1 To ctr+1)
        result(ctr+1)=Mid(s_in,k+1-ctr2,ctr2)
    End If
    Return Ubound(result)
End Function


dim as string w(1 to 4)
w(1)="0"       
w(2)="01"       
w(3)="10"       
w(4)="111"     


#define f 1+int(rnd*4)
dim as string s
randomize


'this is your compressor string of zeros and ones (artificially created here)
'Must add a spacer to each w() within compressor
do  'loop a few times to test return
   
    s=""
for n as long=1 to 200
    s+=w(f)+chr(0) 'w(1) or w(2) or w(3) or w(4) + chr(0) spacer
next

dim as string copy=s 'keep a copy to check


'format a string to send to decompressor
redim as string a()
stringsplit(s,chr(0),a())
dim as string post
for n as long=lbound(a) to ubound(a)
    select case a(n)
    case "0":post+="a"
    case "01":post+="b"
    case "10":post+="c"
    case "111":post+="d"
    end select
next n
print
    print "Sent out:  "
    print post  'formatted and sent out
   
    print
    '---------------------------
    '========================
    '---------------------------
   'now in decompressor with post sent from compressor
    dim as string ret
   
    for n as long=0 to len(post)-1
      select case post[n]
    case asc("a"):ret+="0"+chr(0)
    case asc("b"):ret+="01"+chr(0)
    case asc("c"):ret+="10"+chr(0)
    case asc("d"):ret+="111"+chr(0)
    end select
next n 

print "return"
print ret
color 2
print "original"

print copy
color 15

print iif(copy<>ret,"Error","OK")
sleep
loop until inkey=chr(27)




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

Re: Squares

Postby albert » Jun 10, 2019 16:03

@Dodicat

Neither one compresses..


words(0) = "0"
words(1) = "01"
words(2) = "10"
words(3) = "111"

you start by searching for:
01 111
then 10 111
then 01 10
then 10 01

then 0 01
then 10 0

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

Re: Squares

Postby albert » Jun 10, 2019 17:37

@Dodicat

I think you need to make multiple passes..

The first pass you search for all the 01 111
The next pass you search for al the 10 111
The next pass you search for all the 0 111

The next pass you search for all the 01 10
The next pass you search for all the 10 01


Then you see , if you have any stray "11"'s or "1"'s , then you go back through and correct that , in another pass..

Can't quite , wrap my head around it!!
albert
Posts: 4827
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jun 10, 2019 19:14

@Dodicat

This formula , is the closest I've got to decompressing.. Keep pressing a key to advance it one... Press esc to end.

Sometimes it decompresses okay , and sometimes not , but mostly not.

I've got to set it to read ahead , to see if a "00" is followed by a "001" or if it's a 00 10


Code: Select all


Declare Function findAndReplace(instring As String,find As String,replace As String) As String

Declare Function compress_loop( chrs as string ) as string
Declare Function decompress_loop( chrs as string ) as string

screen 19

dim as double time1,time2,time3,time4
do
   
    randomize
   
    dim as string s=""
    For n As Long = 1 To 8
        s+=chr(Int(Rnd*256))'+8)
    Next
   
    time1=timer
    'begin compress
        dim as string comp=s
        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
   
    'cls
    'draw string( 0,10) , left(s,100)
    'draw string( 0,30) , left(final_out,100)
    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."
   
    sleep
   
loop until inkey = chr(27)

sleep
end
'===============================================================================
'===============================================================================
'begin functions
'===============================================================================
'===============================================================================
Function findAndReplace(instring As String,find As String,replace As String) As String
    dim as string s=instring
    dim as long position=Instr(s,find)
    While position>0
        s=Mid(s,1,position-1) & replace & Mid(s,position+Len(find))
        position=Instr(position+Len(replace),s,find)
    Wend
    return s
End Function
'===============================================================================
'===============================================================================
Function compress_loop( chrs as string ) as string
   
    dim as string binari=""
    dim as string n1
    dim as string zeros = string(64,"0")
    dim as ulongint ptr ubp = cptr(ulongint ptr,strptr(chrs))
    for a as longint = 1 to len(chrs) step 8
        n1 = bin(*ubp) : ubp+=1
        n1 = right(zeros+n1,64)
        binari+= n1
    next
   
    print "c inp = "  ; len(chrs) ', binari
    print "c bin = "  ; len(binari) , binari
   
    dim as string outputs=""
    for a as longint = 1 to len(binari) step 2
        n1=mid(binari,a,2)
        if n1="00" then outputs+="00"
        if n1="01" then outputs+="01"
        if n1="10" then outputs+="10"
        if n1="11" then outputs+="001"
    next
 
    print "c bin = "  ; len(outputs) , outputs
   
    dim as ubyte count=0
    dim as string str1
    dim as longint dec1
    do
        str1=str(len(outputs)/8)
        dec1=instr(1,str1,".")
        if dec1<>0 then outputs+="0" : count+=1
    loop until dec1=0
   
    dim as string final_out = ""
    for a as longint = 1 to len(outputs) step 8
        final_out+=chr(val("&B"+mid(outputs,a,8)))
    next
   
    final_out = str(count) + final_out
   
    print "c out = "; len(final_out)
       
    return final_out
       
end function
'===============================================================================
'============================================================================
Function decompress_loop( chrs as string ) as string
       
    dim as ubyte count = val(left(chrs,1))
   
    chrs=mid(chrs,2)
   
    dim as string binari=""
    dim as string n1
    dim as string zeros = string(8,"0")
    dim as ubyte ptr ubp = cptr(ubyte ptr,strptr(chrs))
    for a as longint = 1 to len(chrs) step 1
        n1 = bin(*ubp) : ubp+=1
        n1 = right(zeros+n1,8)
        binari+= n1
    next
   
    binari=left(binari,len(binari)-count)
   
    print "d bin = "  ; len(binari) , binari
   
        'if n1="00" then outputs+="00"
        'if n1="01" then outputs+="01"
        'if n1="10" then outputs+="10"
        'if n1="11" then outputs+="001"
   
   dim as string outputs=""
   dim as ubyte toggle = 0
   for a as longint = 1 to len(binari) step 2
       n1 = mid(binari,a,2)
       toggle = 0
       if left(n1,1) = "0" then
            n1 = mid(binari,a,3)
            if n1 = "001" then
                outputs+="11"
                a+=1
                toggle=1
            end if
        end if
        if toggle = 0 then
            n1 = mid(binari,a,2)
            outputs+=n1
        end if
    next
   
    print "d out = "  ; len(outputs) , outputs
   
    dim as string final_out = ""
    for a as longint = 1 to len(outputs) step 64
        final_out+=mklongint(valulng("&B"+mid(outputs,a,64)))
    next
   
    return final_out

end function


Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests