Liberty BASIC Community Forum
« piramid - piramid = 1 »

Welcome Guest. Please Login or Register.
Feb 18th, 2018, 3:45pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: piramid - piramid = 1  (Read 180 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 961
xx piramid - piramid = 1
« Thread started on: Feb 7th, 2018, 07:29am »

there are 2 priramids :
a 3 sided one
and a 4 sided one
they have 1 kokonut difference
how big are the piramids ?

?
is there a faster way to calc this
are there solutions above 400


Code:
q = 400
dim a( q ) , b( q )
q4$ = ""
q3$ = ""

for n = 1 to q
  q4$ = q4$ ; " " ; n * n
  a( n ) = sum( q4$ )
  temp = 0
  a$ = ""
  for i = 1 to n
    a$ = a$ ; " " ; i
    temp = temp + sum( a$ )
  next i
  b( n ) = temp
next n
for a = 1 to q
  for b = 1 to q
    if abs( a( a ) - b( b ) ) <= 1 then
      print a , a( a ) , b , b( b )
    end if
  next b
next a




end

function sum( a$ )
  uit = 0
  i = 1
  while word$( a$ , i ) <> ""
    uit = uit + val( word$( a$ , i ) )
    i = i + 1
  wend
  sum = uit
end function

 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
tsh73
Board Moderator

member is online

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1745
xx Re: piramid - piramid = 1
« Reply #1 on: Feb 7th, 2018, 08:51am »

err
is there a description of a problem somewhere?
User IP Logged

damned Dog in the Manger
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 961
xx Re: piramid - piramid = 1
« Reply #2 on: Feb 8th, 2018, 02:35am »

@ tsh73 :
i don't know where i got the problem from
the Original was with kanonbal's
but i liked kokonut's better
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 961
xx Re: piramid - piramid = 1
« Reply #3 on: Feb 8th, 2018, 03:57am »

upadate :
a faster way

i can't look beond 63 now

is there a fast way to do this ans stil do big ones ?

Code:

q = 200
dim a( q ) , b( q )
temp = 0
for n = 1 to q
  temp = temp + n * n
  a( n ) = temp
  b( n ) = over2( n , 3 )
next n

for a = 1 to q
  for b = 1 to q
    if abs( a( a ) - b( b ) ) = 1 then
      print a , a( a ) , b , b( b )
    end if
  next b
next a




end

function sum( a$ )
  uit = 0
  i = 1
  while word$( a$ , i ) <> ""
    uit = uit + val( word$( a$ , i ) )
    i = i + 1
  wend
  sum = uit
end function
function f( x )
'' x!
  uit = 1
  if x > 1 and x < 60 then
    uit = x * f( x - 1 )
  end if
  f = uit
end function
function over( a , b )
  over = f( a ) / ( f( a - b ) )
end function
function over2( a , b )
  over2 = f( a ) / ( f( b ) * f( a - b ) )
end function
 
« Last Edit: Feb 8th, 2018, 03:59am by bluatigro » User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 961
xx Re: piramid - piramid = 1
« Reply #4 on: Feb 8th, 2018, 05:39am »

update :
i checked 6 sided piramid's to

result :
no higher solution's

Code:
'' bluatigro 8 feb 2018
'' piramid's of kokonuts

q = 63
dim a( q ) , b( q ) , c( q )
temp = 0
t = 0
for n = 1 to q
  temp = temp + n * n
  a( n ) = temp
  b( n ) = over2( n , 3 )
  t = t + six( n )
  c( n ) = t
next n
print 4 , , 3
for a = 2 to q
  for b = 2 to q
    if abs( a( a ) - b( b ) ) = 1 then
      print a , a( a ) , b , b( b )
    end if
  next b
next a
print
print 6 , , 3
for a = 2 to q
  for b = 2 to q
    if abs( c( a ) - b( b ) ) = 1 then
      print a , c( a ) , b , b( b )
    end if
  next b
next a
print
print 4 , , 6
for a = 2 to q
  for b = 2 to q
    if abs( a( a ) - c( b ) ) = 1 then
      print a , a( a ) , b , c( b )
    end if
  next b
next a

print "[ game over ]"



end
function six( x )
'' six sided plane of kokonut's
  uit = 1
  if x = 2 then uit = 3
  if x > 2 then
    uit = over2( x , 3 ) + 4 * over2( x - 1 , 3 )
  end if
  six = uit
end function
function f( x )
'' x!
  uit = 1
  if x > 1 and x < 60 then
    uit = x * f( x - 1 )
  end if
  f = uit
end function
function over( a , b )
  over = f( a ) / ( f( a - b ) )
end function
function over2( a , b )
  over2 = f( a ) / ( f( b ) * f( a - b ) )
end function
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: piramid - piramid = 1
« Reply #5 on: Feb 8th, 2018, 06:48am »

Is this the problem?

Build a three sided pyramid and a four sided pyramid by stacking coconuts. keep building them higher and higher. At some point you will find you have used nearly the same number of coconuts for each pyramid. When the difference in the number of coconuts is 1, how big are the pyramids, ie how many coconuts used in each.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: piramid - piramid = 1
« Reply #6 on: Feb 8th, 2018, 07:54am »

On that basis I find one solution in in up to 5000 sided pyramids

That is a two sided tetra and a two sided square 4 and 5 coconuts respectively.

EDIT, no I had a bug, fixed now thanks to bplus, there are three solutions up to 5000 nuts per side.

Code:
dim tetra(500,2)
dim squar(500,2)
'build tetra pyramid
tb=0
for n=1 to 500
    scan
    ba=0
    for b=1 to n
        ba=ba+b
    next
    tb=tb+ba
    tetra(n,1)=n
    tetra(n,2)=tb
next
'build square pyramid
tb=0
for n=1 to 500
    scan
    ba=0
    for b=1 to n
        ba=n^2
    next
    tb=tb+ba
    squar(n,1)=n
    squar(n,2)=tb
next

'compare sizes looking for difference <=1
for n= 1 to 500
 for m = n to 500
    dif=abs(tetra(m,2)-squar(n,2))
    if dif >0 and dif<=1 then
    print m,tetra(m,2),n,squar(n,2)
end if
next
next
 
« Last Edit: Feb 8th, 2018, 10:39am by Rod » User IP Logged

tsh73
Board Moderator

member is online

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1745
xx Re: piramid - piramid = 1
« Reply #7 on: Feb 8th, 2018, 3:05pm »

I run it really long
((m+n) up to 100 000 000
in LBB)
EDIT I'm sure about 1 000 000. As for 100 000 000 I'm afraid it not stored whole numbers up to sigle digit in my tests.
There are no more solutions.
Code:
iSq=1
nSq=1
iTri=1
nTri=1

print "Triangle piramid", "Square piramid"
print "i", "n", "i", "n"
i=0
while i <1000000    'cut
    i=i+1
    if nSq > nTri then
        'next triangle piramidal number
        iTri=iTri+1
        nTri=nTri+iTri*(iTri+1)/2
    else
        'next square piramidal number
        iSq=iSq+1
        nSq=nSq+iSq^2
    end if
    if abs(nTri - nSq) = 1 then
        print iTri, nTri, iSq, nSq
    end if
wend
  
« Last Edit: Feb 9th, 2018, 02:22am by tsh73 » User IP Logged

damned Dog in the Manger
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1182
xx Re: piramid - piramid = 1
« Reply #8 on: Feb 9th, 2018, 04:39am »

Just caught up on this thread. Not having much time at present to code, but this sparked the idea of doing visualisations of at least the first few small piles.
Image below shows the beginning of this, but I really would want it to be rotatable to any chosen angle in 3D.... and of course adding the z-axis layers. And scaling for distance correctly.

User Image
User IP Logged

bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 961
xx Re: piramid - piramid = 1
« Reply #9 on: Feb 11th, 2018, 03:23am »

update :
i got the filling of piramid's in O(N)
the looking for solution's in O(N^2)

can looking for solution not faster ?

Code:
'' bluatigro
'' piramid's of kokonuts

q = 100
dim quadpir( q ) , tripir( q ) , triangle( q )
temp = 0
for n = 1 to q
  temp = temp + n
  triangle( n ) = temp
next n
temp3 = 0
temp4 = 0
for n = 1 to q
  temp3 = temp3 + triangle( n )
  tripir( n ) = temp3
  temp4 = temp4 + n * n
  quadpir( n ) = temp4
next n
print "tripiramid" , , "quadpiramid"
for a = 2 to q
  for b = 2 to q
    if abs( tripir( a ) - quadpir( b ) ) = 1 then
      print a , tripir( a ) , b , quadpir( b )
    end if
  next b
next a
print
print "[ game over ]"
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls