## Squares

General FreeBASIC programming questions.
Tourist Trap
Posts: 2176
Joined: Jun 02, 2015 16:24

### Re: Squares

Challenge related to multwise string reversal for well irrigated brains:)
===》Now that we made some step forward in the previous posts: can we prove that , granted a base at least equal to 27 (numbers coded with alphabetical chars from A to Z, and <space>), we can find such a base that every sentence made with the symbols of this base (embedding the alphabet, A=value... B=othervalue etc...) could be reversed multwise?

Said differently, for some base big enough to embed the alphabet as a part of the one-digit numbers of the base (and space), is there then a probability of 1 that we can find a one-digit multiplier that will effectively reverse any number shaped as a sentence?

For instance (fake), in base 3000, with a subset of the one-digit numbers of this base (A=1000, B=1900, etc.. granted that we can choose our values between 0 and 2999 in base 3000), we could imagine that a multiplier k will operate like this:
k*(HELLO WORLD) = DLROW OLLEH

What do you think of this? Can we at least evaluate what lower bound would be necessary to reach for a base where such a thing occures very often (probability close to 1)?
dodicat
Posts: 4146
Joined: Jan 10, 2006 20:30
Location: Scotland

### Re: Squares

Here is an extension of your previous bases.

Code: Select all

`base        multipliers 3             2 4             3 5             2 4 6             2 5 7             3 6 8             2 3 5 7 9             2 4 8 10            4 9 11            2 3 5 7 10 12            2 3 5 11 13            5 6 12 14            2 4 6 13 15            2 3 4 7 11 14 16            3 7 15 17            2 4 5 8 10 11 16 18            2 5 8 17 19            3 4 6 7 9 18 20            2 3 4 6 9 19 21            2 5 6 10 13 20 22            10 21 23            2 3 4 5 7 11 13 15 17 22 24            2 3 4 5 7 11 19 23 25            4 9 12 24 26            2 8 10 11 12 25 27            2 3 6 8 13 26 28            3 6 13 27 29            2 4 5 8 9 14 16 19 28 30            2 4 5 9 14 29 31            3 7 10 11 15 30 32            2 3 4 5 7 10 15 31 33            2 10 16 32 34            4 6 13 16 33 35            2 3 4 5 6 8 11 17 19 23 26 29 34 36            2 3 5 8 11 17 35 37            5 13 18 21 22 36 38            2 4 7 10 12 14 18 27 37 39            2 3 4 5 6 7 9 11 12 14 16 17 19 31 38 40            3 4 7 9 19 39 41            2 5 6 8 9 11 13 16 17 20 22 27 40 42            2 5 6 13 20 41 43            3 7 9 10 12 15 19 21 25 42 44            2 3 4 6 8 10 14 21 43 45            2 4 5 8 14 22 44 46            7 11 22 45 47            2 3 4 5 7 9 11 13 15 23 25 31 35 46 48            2 3 5 6 7 11 13 15 23 41 47 49            4 6 9 17 19 24 48 50            2 4 8 9 16 18 24 49Press any key to continue . . . `

Here is the code (It is Very slow)

Code: Select all

`#define irange(f,l) int(Rnd*((l+1)-(f))+(f))Function polyeval(Coefficients() As Double,Byval x As Double) As Double    Dim As Double acc    For i As Long=Ubound(Coefficients) To Lbound(Coefficients) Step -1        acc=acc*x+Coefficients(i)    Next i    Return accEnd Functionfunction notinarray(a() as double,n as double) as long    for m as long=lbound(a) to ubound(a)        if a(m)=n then return 0    next    return -1end functionsub bsort(a() as double)    for n1 as long=lbound(a) to ubound(a)-1        for n2 as long=n1+1 to ubound(a)            if a(n1)>a(n2) then swap a(n1),a(n2)        next    next    end sub#macro reverse(s)For n As long=Lbound(s) To Int((Lbound(s)+Ubound(s))/2):Swap s(n),s(Ubound(s)+Lbound(s)-n):Next#endmacrodim as double p(1 to 4)dim as double mfor z as double=3 to 50   dim as long count redim as double a(1 to 1)a(1)=z-1do    do    for n as long=lbound(p) to ubound(p)    p(n)=irange(0,(z-1))nextloop until p(lbound(p))<>0 and p(ubound(p))<>0var V1=polyeval(p(),z)reverse(p)var V2=polyeval(p(),z) m=v1/v2if m<>1 and m then    if m=int(m) then     if notinarray(a(),m) then        redim preserve a(1 to ubound(a)+1)        a(ubound(a))=m    end if    end ifend ifcount+=1loop until len(inkey) or count>10000*z*zbsort(a())print z,for n as long=lbound(a) to ubound(a)    print a(n);nextprintnext zsleep `
Tourist Trap
Posts: 2176
Joined: Jun 02, 2015 16:24

### Re: Squares

dodicat wrote:Here is an extension of your previous bases.

Thanks.

It seems that sometimes we havent any numbers reversed below the value base^4, but the failure never goes beyong base^4. Does this generalize to any base as big as we want it to be?

Note: base 0, base 1, base infinite, has no multwise reversal. The infinite base would lead to a list of unique one-digit numbers, so whatever you multiply there it's some different one-digit number that is obtained. So our game stands somewhere between the base 1, and the infinite base.
albert
Posts: 4017
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Heres some code for your ( reversal * num ) = num ^ 2

Code: Select all

`screen 19dim as longint value = 10do        dim as string num1 = str(value)    dim as string num2        for a as longint = len(num1) to 1 step -1        num2+= mid(num1,a,1)    next        dim as longint val1=0    do        val1+=1    loop until valulng(num2) * val1 >= valulng(num1)^2        if valulng(num1)^2 = valulng(num2) * val1 then        print        print num1 , valulng(num1) ^ 2         print num2 , valulng(num2) * val1 , val1        sleep    end if        if inkey= chr(27) then exit do            value+=1    loopsleepend`