## Squares

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

### Re: Squares

@Richard

If k And 1 Then sum += non-binary( 0 )

could you make it a :

If k And "?" Then sum += non-binary( ? )

Shorten it to a single line???
Richard
Posts: 3029
Joined: Jan 15, 2007 20:44
Location: Australia

### Re: Squares

Code: Select all

`Screen 19'====================================================Const As Short max_bits = 4' put your choice of numbers in this array, 0 for unused MSBsDim As Short non_binary( 0 To max_bits - 1 ) = { 1, 1, 4, 0 }'====================================================Dim As Short k, sum, n = 0, bits = 0For k As Short = 0 To max_bits - 1    If non_binary( k ) Then        n += non_binary( k )' find the maximum possible represented number        bits += 1           ' find number of bits specified at LSB end    Else        Exit For    ' the first zero found ends the game    End IfNext kDim As Short freq( 0 To n )'====================================================' evaluate binary pattern for all different possible codesFor k = 0 To ( 1 Shl bits ) - 1    sum = 0    For i As Short = 0 To bits - 1        If k And ( 1 Shl i ) Then sum += non_binary( i )    Next i    freq( sum ) += 1    ' accumulate frequency distributionNext k'====================================================' report if missing or duplicateFor k = 0 To n    If freq( k ) = 0 Then Print k; " is missing."    If freq( k ) > 1 Then Print k; " is duplicated *"; freq( k )Next kPrint " Maximum code is"; nPrint " Done. "'====================================================Sleep'====================================================`
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Thanks Richard!!

You Da God!!
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

I got 6 bits done!!!

Altered binary bits = { 10 , 14 , 16 , 18 , 23 , 36 , 0 , 0 } = 117

Now to fumble out the next 2 bits....

Code: Select all

`Screen 19'====================================================Const As Short max_bits = 8' put your choice of numbers in this array, 0 for unused MSBsDim As Short non_binary( 0 To max_bits - 1 ) = { 10 , 14 , 16 , 18 , 23 , 36 , 0 ,  0  }'====================================================Dim As Short k, sum, n = 0, bits = 0For k As Short = 0 To max_bits - 1    If non_binary( k ) Then        n += non_binary( k )' find the maximum possible represented number        bits += 1           ' find number of bits specified at LSB end    Else        Exit For    ' the first zero found ends the game    End IfNext kDim As Short freq( 0 To n )'====================================================' evaluate binary pattern for all different possible codesFor k = 0 To ( 1 Shl bits ) - 1    sum = 0    For i As Short = 0 To bits - 1        If k And ( 1 Shl i ) Then sum += non_binary( i )    Next i    freq( sum ) += 1    ' accumulate frequency distributionNext k'====================================================' report if missing or duplicateFor k = 0 To n    'If freq( k ) = 0 Then Print k; " is missing."    If freq( k ) > 1 Then Print k; " is duplicated *"; freq( k )Next kPrint " Maximum code is"; nPrint " Done. "'====================================================Sleep'====================================================`
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

I got an idea!!

How about modifying it so , it tells you what numbers you can add for the next bit..
It would scan all the values and then try others numbers and tell you if its safe to add that number to the next bit position..

So if you have a , 2 , 4 , 7 , it would tell you its safe to add a 10....
Richard
Posts: 3029
Joined: Jan 15, 2007 20:44
Location: Australia

### Re: Squares

You commented out the line that reports these missing codes.
1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 21, 22, 25, 27, 29, 31,
35, 38, 43, 45, 56, 61, 72, 74, 79, 82, 86, 88, 90, 92, 95, 96, 97, 98, 100,
102, 104, 105, 106, 108, 109, 110, 111, 112, 113, 114, 115, 116,
Maximum code is 117

They cannot be represented with bit values of only { 10 , 14 , 16 , 18 , 23 , 36 }
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

With "Altered Binary" all the values can be represented...

{ 10 , 14 , 16 , 18 , 23 , 36 }

If you want to do a 1 then it turns it into a 10
If you want to do a 2 then it turns it into a 14

If you want to do a 3 then it turns it into a 24 ( 10 + 14 )

If you want to do a 8 then it turns it into a 18
If you want to do a 10 then it turns it into a 32 ( 18 +14 )

Thanks for writing the Non_Binary code for me.... I've been having fun playing with values...

But I've found ; that altering the binary bits , doesn't compress , unless there's duplicates..

If you take in a random string , and change all the values to all different individual values.. it won't compress...
It just shuffles the deck , all the original values are still there. their just in different orders...

The only way to compress:
Is to order the values so they make compressible patterns...
And that requires a map , which usually makes the idea expand...

There's another way , to cut off 0's or 1's , but again , the map makes it expand..
Last edited by albert on Jul 24, 2020 1:53, edited 1 time in total.
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

I was wondering how you would undo it???

you can't do the normal :

if val > 128 then bit1+= 1 , val-= 128
if val > 064 then bit1+= 1 , val-= 064
etc...
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

!!~~OFF TOPIC~~!!

I got my two songs demo'd , their done....

"I Got Music"
"Dinner Time"

https://soundcloud.com/user-704620747

The "I Got Music" , i didn't really care for the music they put it to... Bu the song sounds good lyric wise..
The "Dinner Time" song , they did it perfectly... Good music and singing..
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

I came up with another multi-billion dollar idea...

"Vira-Vend" vending machines...

You insert your credit or debit card , and it charges you for the test..

It then spits out a straw , you insert the straw into a hole on the machine..
And blow into it...
It then uses liquid nitrogen , to condense the exhaled breath , into a liquid..
It then scans the liquid breath , under an electron microscope to look for viruses..

If it finds a virus , then it prints out a picture of the virus , so you can take it to the doctors office to get treated..

You would need some way to clean the condensing chamber between customers..

Every pharmacy on the planet would want a "Vira-Vend" machine...You could make trillions....
angros47
Posts: 1670
Joined: Jun 21, 2005 19:04

### Re: Squares

It would never work: viruses are not transmitted by exhaled air (not even airborne viruses), they are transmitted by the respiratory droplets (also called Flügge's droplets). They can be released by sneezing, by coughing, by talking, and sometimes by just breathing.

That is also the reason why masks work, even if they have pores that are larger than the virus: they could not stop the virus itself, but they can stop the droplets, and this is usually enough

So, a test made by blowing in a straw would be unreliable: exhaled air might not contain droplets, and without them the test would not detect any virus, even if there is actually a disease
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@angros47

You wrote:

It would never work: viruses are not transmitted by exhaled air (not even airborne viruses), they are transmitted by the respiratory droplets (also called Flügge's

Breathing out , has the virus in it , that's why you wear masks.
To stop other peoples breath from getting into your mouth or nose..

Just plain exhaling ( breathing ) , spreads droplets out to 12 feet , with a mask it lowers it down to 6 feet...for a bandana mask..

Other types of real masks , lowers the 6 foot droplet spread to less than a foot..
For a double layer t-shirt type of mask the droplets of a normal exhale , only got out to 2 inches..

They showed a laser scanned exhale on TV the other day...
And the different types of masks , and how far the droplets go thru each type of mask.
A double layer cotton mask was the best only 2 inches... Not counting the N-95 masks.. That are preferred by healthcare workers..

I need another programming problem to solve...I'll play with numbers some more , and see if i can find some interesting number theory...
Back in "Circles" , I invented a way to divide by multiplying , you divide 1 by one number , and then multply the two numbers..
Richard used the concept in his Base1e9 code..
Last edited by albert on Jul 25, 2020 0:57, edited 1 time in total.
paul doe
Posts: 1255
Joined: Jul 25, 2017 17:22
Location: Argentina

### Re: Squares

albert wrote:...
Back in "Circles" , I invented a way to divide by multiplying , you divide 1 by one number , and then multply the two numbers..

Oh, so it was you who 'invented' the multiplicative reciprocal? Who would have thought...

You need to go back to what you do best: writing songs. Seriously.
albert
Posts: 5884
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@paul doe

You wrote:
Oh, so it was you who 'invented' the multiplicative reciprocal? Who would have thought...

When was "multiplicative reciprocal" invented???

When i came up with the idea , Richard didn't have any knowledge of it , And Richard is a professional mathematician..
And he used it in his code :

Modulo 10^9 floating point arithmetic. ( Search the "Tips&Tricks" section of the forum for it or Base1e9... ) either one will bring up the code.
paul doe
Posts: 1255
Joined: Jul 25, 2017 17:22
Location: Argentina

### Re: Squares

albert wrote:...
When was "multiplicative reciprocal" invented???

When i came up with the idea...

Wikipedia wrote:...
The term reciprocal was in common use at least as far back as the third edition of Encyclopædia Britannica (1797)
...

So, that must mean you are at least 223 years old... wow! Mind blowing!