mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2012-02-20, 22:16   #1
bcp19
 
bcp19's Avatar
 
Oct 2011

7×97 Posts
Default a puzzle

You have 680 glasses and need to build a tower 15 levels high with 1 on top. Is there an equation that can be used to solve for glasses per level?
bcp19 is offline   Reply With Quote
Old 2012-02-20, 22:21   #2
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by bcp19 View Post
You have 680 glasses and need to build a tower 15 levels high with 1 on top. Is there an equation that can be used to solve for glasses per level?
only thing that comes to mind is (680-1)/14 =48.5 / level on average.
science_man_88 is offline   Reply With Quote
Old 2012-02-20, 22:37   #3
bcp19
 
bcp19's Avatar
 
Oct 2011

7·97 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
only thing that comes to mind is (680-1)/14 =48.5 / level on average.
it's more like a pyramid, your design would not be stable.
bcp19 is offline   Reply With Quote
Old 2012-02-20, 22:41   #4
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

222378 Posts
Default

Quote:
Originally Posted by bcp19 View Post
it's more like a pyramid, your design would not be stable.
You didn't define stability as being a requirement.
chalsall is offline   Reply With Quote
Old 2012-02-20, 22:48   #5
bcp19
 
bcp19's Avatar
 
Oct 2011

7×97 Posts
Default

Quote:
Originally Posted by chalsall View Post
You didn't define stability as being a requirement.
True, but that equation would be simple to figure out, plus how would you have 1 on top and have that .5 per level?
bcp19 is offline   Reply With Quote
Old 2012-02-20, 22:50   #6
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

Well the sum over the integers up to n := the nth triangular number would describe perfect triangles. So find the highest triangular number <= 680, then distribute the remainder evenly over each layer. In C:

Code:
int * pyramid(int x) {
        int i,j,diff;
        int sum=0;
        int * layer;
        printf("Input is %d\n", x);
        for( i=1; sum <= x; i++)
                sum += i;
        sum -= (--i); i--;                                                      // The loop goes one too far, so fix it
        layer = (int *)malloc(i*sizeof(int));                                   // Declares an array of size i
        for( j=0; j<i; j++)
                layer[j] = j+1;                                                 // The basic shape is a triangle
        diff = x - sum;
        if( diff > 0 ) {
                for( j=i-1; diff>0; diff-- /* Decrement diff until diff==0 */ ) {               // Distribute the difference over each layer
                        if( j<1 ) j = i - 1;                                    // Keep cycling over the pyramid
                        layer[j]++;                                             // Add one to the current layer
                        j--;                                                    // Move to the next higher layer
                }
                printf("There will be %d layers, as follows:\n", i);
                for( j=0; j<i; j++) printf("%d\n", layer[j]);
                printf("\n");
                return layer;
        }
        else if( diff==0 ) {printf("A perfect triangle of glasses!\n\n"); return NULL;}
        else {printf("You need %d more debugging printfs!\n", x); return (int *)"YOU SUCK";}
}
Will post results for 680 in a moment (if other inputs give the right outputs). Edit: For pyramid(6), it gave me 1,2,3,4,5 so something's not right. Hang on. Edit: Found one bug. The sum goes too far. (Not done yet though.) Edit: Got em all. Also realized that this isn't exactly optimal, but it's a solution.
Code:
What number of glasses should I use?
1
Input is 1
A perfect triangle of glasses!

What number of glasses should I use?
2
Input is 2
There will be 1 layers, as follows:
2

What number of glasses should I use?
3
Input is 3
A perfect triangle of glasses!

What number of glasses should I use?
4
Input is 4
There will be 2 layers, as follows:
1
3

What number of glasses should I use?
5
Input is 5
There will be 2 layers, as follows:
1
4

What number of glasses should I use?
6
Input is 6
A perfect triangle of glasses!

What number of glasses should I use?
7
Input is 7
There will be 3 layers, as follows:
1
2
4

What number of glasses should I use?
8
Input is 8
There will be 3 layers, as follows:
1
3
4

What number of glasses should I use?
680
Input is 680
There will be 36 layers, as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
24
25
26
27
28
29
30
31
32
33
34
35
36
37
When I say not optimal, I mean it seems to me that a stack of 5 glasses should be 1-2-2, not 1-4 as this code suggests, and 2 should be 1-1, not just 2. Will have to come back to this later though, I have to go code for my CS HW due in 2.5 hrs (Somebody else want to optimize the algo?)



EDIT: WHOOPS 15 per layer. There's a HUGE piece of missing information. Well, at least I had fun solving my own problem :/ (Another edit: This is a 2-D solution, as opposed to eh 3-D ones below :P:P:P)

Last fiddled with by Dubslow on 2012-02-20 at 23:24 Reason: replaced code with working version
Dubslow is offline   Reply With Quote
Old 2012-02-20, 22:53   #7
chalsall
If I May
 
chalsall's Avatar
 
"Chris Halsall"
Sep 2002
Barbados

937510 Posts
Default

Quote:
Originally Posted by bcp19 View Post
True, but that equation would be simple to figure out, plus how would you have 1 on top and have that .5 per level?
As I have learnt the hard way... Be very careful what you ask for -- you might just get it....
chalsall is offline   Reply With Quote
Old 2012-02-20, 22:53   #8
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by Dubslow View Post
Well the sum over the integers up to n := the nth triangular number would describe perfect triangles. So find the highest triangular number <= 680, then distribute the remainder evenly over each layer. In C:

Code:
int * pyramid(int x) {
    int i,j,diff;
    int sum=0;
    int * layer;
    for( i=0; sum <= x; i++)
        sum += i;
    layer = (int *)malloc(i*sizeof(int));    // Declares an array of size i
    for( j=0; j<i; j++)
        layer[j] = j+1;                               // The basic shape is a triangle
    diff = x - sum;
    if( diff != 0) {
        for( j=i-1; diff>0; diff-- /* Decrement diff until diff==0 */ ) {               // Distribute the difference over each layer
            if( j<1 ) j = i - 1;                        // Keep cycling over the pyramid
            layer[j]++;                                // Add one to the current layer                               
            j--;                                           // Move to the next higher layer
        }
        printf("There will be %d layers, as follows:\n", i);
        for( j=0; j<i; j++) printf("%d\n", layer[j]);
        printf("\n");
        return layer;
    else if( diff==0 ) {printf("A perfect triangle of glasses!\n"); return null;}
    else printf("You need %d more debugging printfs!\n", x);
}
Will post results for 680 in a moment (if other inputs give the right outputs).
Quote:
Originally Posted by PARI
Code:
(18:20)>sum(X=1,15,X)
%37 = 120
so it's definitely not a perfect triangle.
science_man_88 is offline   Reply With Quote
Old 2012-02-20, 23:00   #9
bcp19
 
bcp19's Avatar
 
Oct 2011

7·97 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
so it's definitely not a perfect triangle.
Actually, that may work...
1+3+6+10+15+21+28+36+45+55+66+78+91+105+120=680

yep, that works... I was thinking 15x15,14x14, etc but it went well over 1k.

With the levels now known, without using trial and error, is there an actual equation that would solve this?

Last fiddled with by bcp19 on 2012-02-20 at 23:02
bcp19 is offline   Reply With Quote
Old 2012-02-20, 23:13   #10
ccorn
 
ccorn's Avatar
 
Apr 2010

22·37 Posts
Default

Quote:
Originally Posted by bcp19 View Post
You have 680 glasses and need to build a tower 15 levels high with 1 on top. Is there an equation that can be used to solve for glasses per level?
It's a pyramid with triangles at each level, each triangle packed regularly with glasses in the (2-dimensional) densest possible way, one glass at the top, and each non-top level having its side length one glass longer than the previous (higher) level.

Numbering the levels beginning with 1 at the top, the glass count for level i is the triangular number T(i) = i*(i+1)/2.
The total glass count V(n) for n levels is then
V(n) = \sum_{i=1}^n \frac{i\,(i+1)}{2} = \frac{1}{2}\left(\left(\sum_{i=1}^n i^2\right)+\left(\sum_{i=1}^n i\right)\right) = \frac{1}{2}\left(\frac{n\,(n+1)\,(2n+1)}{6}+\frac{n\,(n+1)}{2}\right) = \frac{n\,(n+1)(n+2)}{6}.
And indeed V(15) = 680.

Edit: OK, folks, you have been faster.

Last fiddled with by ccorn on 2012-02-20 at 23:16
ccorn is offline   Reply With Quote
Old 2012-02-20, 23:21   #11
kar_bon
 
kar_bon's Avatar
 
Mar 2006
Germany

23×3×7×17 Posts
Default

Quote:
Originally Posted by bcp19 View Post
With the levels now known, without using trial and error, is there an actual equation that would solve this?
Every level n is the sum of all numbers from 1 to n.

So:

FOR level = 1 to 15
number of glasses = \sum_{i=1}^{level}i
kar_bon is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Some puzzle Harrywill Puzzles 4 2017-05-03 05:10
Four 1's puzzle Uncwilly Puzzles 75 2012-06-12 13:42
4 4s puzzle henryzz Puzzles 4 2007-09-23 07:31
Dot puzzle nibble4bits Puzzles 37 2006-02-27 09:35
now HERE'S a puzzle. Orgasmic Troll Puzzles 6 2005-12-08 07:19

All times are UTC. The time now is 01:59.

Thu Dec 3 01:59:12 UTC 2020 up 83 days, 23:10, 1 user, load averages: 2.07, 2.35, 2.21

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.