Sorry albert, first error (min./day):albert wrote:There's 12 * 60 rhymes = 720 elements..
- 1) 12 hours AM
2) 12 hours PM
3) 24 hours/day
Before starting with such complex matters, you should get your math skills tuned.
Sorry albert, first error (min./day):albert wrote:There's 12 * 60 rhymes = 720 elements..
Code: Select all
Const As Integer maxindex = 720
Const As Integer period = 60
Dim As Integer index = (Timer / period) Mod maxindex + 1
Do
Dim As Integer i = (Timer / period) Mod maxindex + 1
If i <> index Then
index = i
Print index '' or play the #index element, with index in [1, maxindex]
End If
Sleep 10
Loop While Inkey = ""
I was conferring with the other admins. I wanted to make sure we were on the same page. I am here every day. Some of the other admins are not.MrSwiss wrote:@Imortis, seriously???
...snip...
What did take you so long, before eventually stepping in to those "below the waist-
level", stupid, annoying rhymes. I wouldn't have waited half the time (month's).
Fair enough (but only until you have the guiding lines).Imortis wrote:I was conferring with the other admins. I wanted to make sure we were on the same page.
Isn't that the very reason to have Mod's?Imortis wrote: I am here every day. Some of the other admins are not.
Code: Select all
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 10
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."
print string(99,"=")
sleep
loop until inkey = chr(27)
sleep
end
'===============================================================================
'===============================================================================
'begin functions
'===============================================================================
'===============================================================================
Function compress_loop( chrs as string ) as string
dim as string binari=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(chrs) step 1
n1 = zeros + bin( chrs[a-1] )
binari+=right(n1,8)
next
'we need to make binari and even multiple of 3
print "c inp = " ; len(chrs)
print "c bin = " ; len(binari) , binari
dim as string bin_count
dim as longint count = 0
dim as string str1
dim as longint dec1
do
str1 = str(len(binari)/3)
dec1=instr(1,str1,".")
if dec1<>0 then binari+="0" : count+=1
loop until dec1=0
bin_count = chr(count)
print "c bin = " ; len(binari) , binari
dim as string outs= ""
dim as string map= ""
for a as longint = 1 to len(binari) step 3
n1 = mid(binari,a,3)
if n1="000" then outs+="0" : map+="0"
if n1="001" then outs+="1" : map+="0"
if n1="010" then outs+="0" : map+="10"
if n1="011" then outs+="1" : map+="10"
if n1="100" then outs+="0" : map+="11"
if n1="101" then outs+="1" : map+="11"
if n1="110" then outs+="0" : map+="100"
if n1="111" then outs+="1" : map+="100"
next
print "c out = " ; len(outs) , outs
print "c map = " ; len(map) , map
'we need to make outs and map and even multiple of 8
dim as string out_count
count = 0
do
str1 = str(len(outs)/8)
dec1=instr(1,str1,".")
if dec1<>0 then outs+="0" : count+=1
loop until dec1=0
out_count = chr(count)
dim as string map_count
count = 0
do
str1 = str(len(map)/8)
dec1=instr(1,str1,".")
if dec1<>0 then map+="0" : count+=1
loop until dec1=0
map_count = chr(count)
dim as string final_out = ""
for a as longint = 1 to len(outs) step 8
final_out+=chr(valulng("&B"+mid(outs,a,8)))
next
final_out+="END"
for a as longint = 1 to len(map) step 8
final_out+=chr(valulng("&B"+mid(map,a,8)))
next
final_out = bin_count + out_count + map_count + final_out
print "c fin = " ; len(final_out) ', binari
return final_out
end function
'===============================================================================
'============================================================================
Function decompress_loop( chrs as string ) as string
dim as longint bin_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint out_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint map_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint place = instr(1,chrs,"END")
dim as string outs = left(chrs,place-1)
dim as string map = mid(chrs,place+3)
dim as string bin_outs=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(outs) step 1
n1 = zeros + bin( outs[a-1] )
bin_outs+=right(n1,8)
next
bin_outs = left(bin_outs,len(bin_outs)-out_count)
dim as string bin_map=""
for a as longint = 1 to len(map) step 1
n1 = zeros + bin( map[a-1] )
bin_map+=right(n1,8)
next
bin_map = left(bin_map,len(bin_map)-map_count)
print "d out = " ; len(bin_outs) , bin_outs
print "d map = " ; len(bin_map) , bin_map
dim as string bin_0 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "0" then mid(bin_0,a,1) = "0"
next
dim as string bin_1 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "1" then mid(bin_1,a,1) = "1"
next
print
print "d zer = " ; len(bin_0) , bin_0
print "d one = " ; len(bin_1) , bin_1
dim as string final_out = ""
return final_out
end function
Code: Select all
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."
print string(99,"=")
sleep
loop until inkey = chr(27)
sleep
end
'===============================================================================
'===============================================================================
'begin functions
'===============================================================================
'===============================================================================
Function compress_loop( chrs as string ) as string
dim as string binari=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(chrs) step 1
n1 = zeros + bin( chrs[a-1] )
binari+=right(n1,8)
next
'we need to make binari and even multiple of 3
print "c inp = " ; len(chrs)
print "c bin = " ; len(binari) , binari
dim as string bin_count
dim as longint count = 0
dim as string str1
dim as longint dec1
do
str1 = str(len(binari)/3)
dec1=instr(1,str1,".")
if dec1<>0 then binari+="0" : count+=1
loop until dec1=0
bin_count = chr(count)
print "c bin = " ; len(binari) , binari
dim as string outs= ""
dim as string map= ""
for a as longint = 1 to len(binari) step 3
n1 = mid(binari,a,3)
if n1="000" then outs+="0" : map+="00"
if n1="001" then outs+="1" : map+="00"
if n1="010" then outs+="0" : map+="01"
if n1="011" then outs+="1" : map+="01"
if n1="100" then outs+="0" : map+="10"
if n1="101" then outs+="1" : map+="10"
if n1="110" then outs+="0" : map+="1"
if n1="111" then outs+="1" : map+="1"
next
print "c out = " ; len(outs) , outs
print "c map = " ; len(map) , map
'we need to make outs and map and even multiple of 8
dim as string out_count
count = 0
do
str1 = str(len(outs)/8)
dec1=instr(1,str1,".")
if dec1<>0 then outs+="0" : count+=1
loop until dec1=0
out_count = chr(count)
dim as string map_count
count = 0
do
str1 = str(len(map)/8)
dec1=instr(1,str1,".")
if dec1<>0 then map+="0" : count+=1
loop until dec1=0
map_count = chr(count)
dim as string final_out = ""
for a as longint = 1 to len(outs) step 8
final_out+=chr(valulng("&B"+mid(outs,a,8)))
next
final_out+="END"
for a as longint = 1 to len(map) step 8
final_out+=chr(valulng("&B"+mid(map,a,8)))
next
final_out = bin_count + out_count + map_count + final_out
print "c fin = " ; len(final_out) ', binari
return final_out
end function
'===============================================================================
'============================================================================
Function decompress_loop( chrs as string ) as string
dim as longint bin_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint out_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint map_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint place = instr(1,chrs,"END")
dim as string outs = left(chrs,place-1)
dim as string map = mid(chrs,place+3)
dim as string bin_outs=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(outs) step 1
n1 = zeros + bin( outs[a-1] )
bin_outs+=right(n1,8)
next
bin_outs = left(bin_outs,len(bin_outs)-out_count)
dim as string bin_map=""
for a as longint = 1 to len(map) step 1
n1 = zeros + bin( map[a-1] )
bin_map+=right(n1,8)
next
bin_map = left(bin_map,len(bin_map)-map_count)
print "d out = " ; len(bin_outs) , bin_outs
print "d map = " ; len(bin_map) , bin_map
dim as string bin_0 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "0" then mid(bin_0,a,1) = "0"
next
dim as string bin_1 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "1" then mid(bin_1,a,1) = "1"
next
print
print "d zer = " ; len(bin_0) , bin_0
print "d one = " ; len(bin_1) , bin_1
dim as string final_out = ""
return final_out
end function
Code: Select all
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."
print string(99,"=")
sleep
loop until inkey = chr(27)
sleep
end
'===============================================================================
'===============================================================================
'begin functions
'===============================================================================
'===============================================================================
Function compress_loop( chrs as string ) as string
dim as string binari=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(chrs) step 1
n1 = zeros + bin( chrs[a-1] )
binari+=right(n1,8)
next
'we need to make binari and even multiple of 3
print "c inp = " ; len(chrs)
print "c bin = " ; len(binari) , binari
dim as string bin_count
dim as longint count = 0
dim as string str1
dim as longint dec1
do
str1 = str(len(binari)/3)
dec1=instr(1,str1,".")
if dec1<>0 then binari+="0" : count+=1
loop until dec1=0
bin_count = chr(count)
print "c bin = " ; len(binari) , binari
dim as string outs= ""
dim as string map= ""
for a as longint = 1 to len(binari) step 3
n1 = mid(binari,a,3)
if n1="000" then outs+="0" : map+="00"
if n1="001" then outs+="1" : map+="00"
if n1="010" then outs+="0" : map+="01"
if n1="011" then outs+="1" : map+="01"
if n1="100" then outs+="0" : map+="10"
if n1="101" then outs+="1" : map+="10"
if n1="110" then outs+="0" : map+="1"
if n1="111" then outs+="1" : map+="1"
next
print "c out = " ; len(outs) , outs
print "c map = " ; len(map) , map
'we need to make outs and map and even multiple of 8
dim as string out_count
count = 0
do
str1 = str(len(outs)/8)
dec1=instr(1,str1,".")
if dec1<>0 then outs+="0" : count+=1
loop until dec1=0
out_count = chr(count)
dim as string map_count
count = 0
do
str1 = str(len(map)/8)
dec1=instr(1,str1,".")
if dec1<>0 then map+="0" : count+=1
loop until dec1=0
map_count = chr(count)
dim as string final_out = ""
for a as longint = 1 to len(outs) step 8
final_out+=chr(valulng("&B"+mid(outs,a,8)))
next
final_out+="END"
for a as longint = 1 to len(map) step 8
final_out+=chr(valulng("&B"+mid(map,a,8)))
next
final_out = bin_count + out_count + map_count + final_out
print "c fin = " ; len(final_out) ', binari
return final_out
end function
'===============================================================================
'============================================================================
Function decompress_loop( chrs as string ) as string
dim as longint bin_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint out_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint map_count = asc(left(chrs,1))
chrs=mid(chrs,2)
dim as longint place = instr(1,chrs,"END")
dim as string outs = left(chrs,place-1)
dim as string map = mid(chrs,place+3)
dim as string bin_outs=""
dim as string zeros = "00000000"
dim as string n1
for a as longint = 1 to len(outs) step 1
n1 = zeros + bin( outs[a-1] )
bin_outs+=right(n1,8)
next
bin_outs = left(bin_outs,len(bin_outs)-out_count)
dim as string bin_map=""
for a as longint = 1 to len(map) step 1
n1 = zeros + bin( map[a-1] )
bin_map+=right(n1,8)
next
bin_map = left(bin_map,len(bin_map)-map_count)
print "d out = " ; len(bin_outs) , bin_outs
print "d map = " ; len(bin_map) , bin_map
dim as string bin_0 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "0" then mid(bin_0,a,1) = "0"
next
dim as string bin_1 = string( len(bin_map) , chr(0) )
for a as longint = 1 to len(bin_map) step 1
if mid(bin_map,a,1) = "1" then mid(bin_1,a,1) = "1"
next
print
print "d zer = " ; len(bin_0) , bin_0
print "d one = " ; len(bin_1) , bin_1
dim as string outputs = string(len(bin_map),chr(0))
place=0
do
place = instr(place+1,bin_map,"1001")
mid(outputs,place,4) = "1001"
mid(bin_map,place,4) = " "
loop until place = 0
place=0
do
place = instr(place+1,bin_map,"00")
mid(outputs,place,2) = "00"
mid(bin_map,place,2) = " "
loop until place = 0
place=0
do
place = instr(place+1,bin_map,"01")
mid(outputs,place,2) = "01"
mid(bin_map,place,2) = " "
loop until place = 0
place=0
do
place = instr(place+1,bin_map,"10")
mid(outputs,place,2) = "10"
mid(bin_map,place,2) = " "
loop until place = 0
print
print "d map = " ; len(bin_map) , bin_map
print "d out = " ; len(outputs) , outputs
dim as string final_out = ""
return final_out
end function