piramid - piramid = 1 kokonut

General FreeBASIC programming questions.
bluatigro
Posts: 652
Joined: Apr 25, 2012 10:35
Location: netherlands

piramid - piramid = 1 kokonut

Postby bluatigro » Feb 08, 2018 9:02

a old puzle :
you have a 4 sided piramid and a 3 sided one
they differ in size 1 kokonut
how big are the piramid's ?

error :
function sum() isn't right

? :
are there solutions above 400
how do i speed this up

Code: Select all

'' bluatigro 8 feb 2018
'' piramid's

function sum( a() as integer , l as integer )
  dim as integer i , uit
  for i = 0 to l
    uit +=  a( i )
  next i
  return uit
end function

const as integer q = 400
dim as integer qa( q ) , qb( q ) , a( q ) , b( q ) , i , n , temp
for i = 0 to q
  qa( i ) = 0
  qb( i ) = 0
next i

for n = 1 to q
  qa( n ) = n * n
  a( n ) = sum( qa() , n )
  temp = 0
  for i = 1 to n
    qb( i ) = i
    temp = temp + sum( qb() , i )
  next i
  b( n ) = temp
next n
for i = 1 to q
  for n = 1 to q
    if abs( a( i ) - b( n ) ) <= 1 then
      print i , a( i ) , n , b( n )
    end if
  next n
next i
sleep
end


bluatigro
Posts: 652
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: piramid - piramid = 1 kokonut

Postby bluatigro » Feb 08, 2018 10:12

update :
a faster way

? :
how do i bigger that 63 and stil have speed

error :
i get other number's in libertyB . why ?

Code: Select all

'' bluatigro 8 feb 2018
'' piramid's

function f( x as ulong ) as ulong
'' x!
  dim as ulong uit = 1
  if x > 1 and x < 60 then
    uit = x * f( x - 1 )
  end if
  return uit
end function
function over( a as ulong , b as ulong ) as ulong
  return f( a ) / ( f( a - b ) )
end function
function over2( a as ulong , b as ulong ) as ulong
  return f( a ) / ( f( b ) * f( a - b ) )
end function


const as integer q = 63
dim as ulong temp , a( q ) , b( q ) , i , n

for n = 1 to q
  temp  += n * n
  a( n ) = temp
  b( n ) = over2( n , 3 )
next n
for i = 2 to q
  for n = 2 to q
    if abs( a( i ) - b( n ) ) <= 1 then
      print i , a( i ) , n , b( n )
    end if
  next n
next i
print "[ game over ]"
sleep
end


integer
Posts: 391
Joined: Feb 01, 2007 16:54
Location: usa

Re: piramid - piramid = 1 kokonut

Postby integer » Feb 08, 2018 12:36

Is the 4 side pyramid a pyramid with a base and four (4) faces and the 3 side pyramid a tetrahedron?
or is the 4side a quadrilateral and the 3 side a triangle?

Running your code does not clarify that (for me).
Is the "kokonut" a sphere or is it supposed to be a linear measurement?
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: piramid - piramid = 1 kokonut

Postby frisian » Feb 10, 2018 22:44

@integer

This is my interpretation of the description given by bluatigro.
You have a four sided stack of coconuts (or cannon balls) of a certain height containing X amount of coconuts and you need to construct a three sided stack with X - 1 coconuts.
How many are needed and how high are the stacks.

3 sided: ground surface is a triangle, tetrahedron pyramid.
4 sided: ground surface is a square, square pyramidal pyramid.

1 layer: no solution 1 - 1 = 0

4 sided stack 2 layers: base 4 coconuts + 1 on top.
3 sided stack 2 layers: base 3 coconuts + 1 on top.

4 sided - 3 sided = (4+1) - (3+1) = 1 coconut, you need 5 coconuts, 4 sided is 2 layers and 3 sided is 2 layers.

4 sided stack 3 layers: 9 + 4 + 1 = 14
3 sided stack 3 layers: 6 + 3 + 1 = 10
3 sided stack 4 layers: 10 + 6 + 3 + 1 = 20

Link to PDF with formulas for both pyramids http://www2.mae.ufl.edu/~uhk/STACKING-CANNONBALLS.pdf
bluatigro
Posts: 652
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: piramid - piramid = 1 kokonut

Postby bluatigro » Feb 12, 2018 8:54

update :
i got making piramid's in O( N )
i got checking in O( N ^ 2 )

strange :
i got different result's

rem :
the kokonut's can be replaced by any sphere shaped object

Code: Select all

'' bluatigro 12 feb 2018
'' piramid's




const as integer q = 100
dim as ulong temp , tripir( q ) , forpir( q ) , triangle( q ) , i , n
temp = 0
for n = 1 to q
  temp += n
  triangle( n ) = temp
next n
temp = 0
i = 0
for n = 1 to q
  temp  += n * n
  forpir( n ) = temp
  i += triangle( n )
  tripir( n ) = i
next n
print "piramid 3" ,, "piramid 4"
for i = 2 to q
  for n = 2 to q
    if abs( tripir( i ) - forpir( n ) ) = 1 then
      print i , tripir( i ) , n , forpir( n )
    end if
  next n
next i
print "[ game over ]"
sleep
end

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests