in reply to Re: Powers of three
in thread Powers of three
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
if we take only bit 0, (2**0) we get this
1
1 1
1 0 1
1 1 1 1
1 0 0 0 1
1 1 0 0 1 1
1 0 1 0 1 0 1
1 1 1 1 1 1 1 1
add up each row and we get this series
1, 2, 2, 4, 2, 4, 4, 8, ...after thinking about it for a few minutes i realised how to generate that series
#my code does this all in d() with a push and a map, ain't perl grand 1. take list @a and produce a copy of it in @d 2. double all the values in @d 3. push @b onto @a 4. goto step 1this will produce the series above now we add all the values in the list to those before the current value (not recursively, just a simple cumulative sum) and we get
1, 3, 5, 9, 11, 15, 19, 27, ...this is @b in my program, if you look closely at 2**$n-1 we now have 3**$n.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Powers of three
by truedfx (Monk) on Feb 07, 2006 at 18:04 UTC | |
|
Re^3: Powers of three
by tweetiepooh (Hermit) on Feb 10, 2006 at 11:09 UTC |