Skip to main content
Notice removed Reward existing answer by miles
Bounty Ended with clismique's answer chosen by miles
Notice added Reward existing answer by miles
Bounty Started worth 100 reputation by miles
Rollback to Revision 1
Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Doesn't really seem like it has to do with arrays to me
Link
DJMcMayhem
  • 59.6k
  • 17
  • 196
  • 348
Tweeted twitter.com/StackCodeGolf/status/787562282133942272
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Compute the kangaroo sequence

Backstory

Disclaimer: May contain made up information about kangaroos.

Kangaroos traverse several stages of development. As they grow older and stronger, they can jump higher and longer, and they can jump more times before they get hungry.

In stage 1, the kangaroo is very little and cannot jump at all. Despite this, is constantly requires nourishment. We can represent a stage 1 kangaroo's activity pattern like this.

o

In stage 2, the kangaroo can make small jumps, but not more than 2 before it gets hungry. We can represent a stage 2 kangaroo's activity pattern like this.

 o o
o o o

After stage 2 the kangaroo improves quickly. In each subsequent stage, the kangaroo can jump a bit higher (1 unit in the graphical representation) and twice as many times. For example, a stage 3 kangaroo's activity pattern looks like this.

  o   o   o   o
 o o o o o o o o
o   o   o   o   o

All that jumping requires energy, so the kangaroo requires nourishment after completing each activity pattern. The exact amount required can be calculated as follows.

  1. Assign each o in the activity pattern of a stage n kangaroo its height, i.e., a number from 1 to n, where 1 corresponds to the ground and n to the highest position.

  2. Compute the sum of all heights in the activity pattern.

For example, a stage 3 kangaroo's activity pattern includes the following heights.

  3   3   3   3
 2 2 2 2 2 2 2 2
1   1   1   1   1

We have five 1's, eight 2's, and four 3's; the sum is 5·1 + 8·2 + 4·3 = 33.

Task

Write a full program or a function that takes a positive integer n as input and prints or returns the nutritional requirements per activity of a stage n kangaroo.

This is ; may the shortest answer in bytes win!

Examples

 1 ->     1
 2 ->     7
 3 ->    33
 4 ->   121
 5 ->   385
 6 ->  1121
 7 ->  3073
 8 ->  8065
 9 -> 20481
10 -> 50689