# The fourth power (Juzuk)

In 1939 Juzuk described a way to generate the fourth powers of natural numbers. Group the natural numbers like this:

1   2 3   4 5 6   7 8 9 10   11 12 13 14 15   ...


Scratch each second group:

1   4 5 6   11 12 13 14 15 ...


The sum of the n remaining groups is n**4.

• Input: none
• Task: print the fourth powers upto 100**4, using Juzuk's method.
• Output:

0 (optional) 1 16 81 ... 100000000

• While I find it acceptable to forbid language specificities that make it too easy to solve a problem, I'm not fond of that “use Juzuk’s method” rule. Is it allowed to take the n-1 result in account when computing for n? Is it allowed to simplify integer sums using the n(n+1)/2 formula? When is it no longer Juzuk’s method? – sam hocevar Mar 12 '11 at 16:08
• Rhetorical questions? – steenslag Mar 12 '11 at 21:29

## J, 40 38 (not summing unneeded)

+/\+/"1(+:i.100){(#~i.201)[/.>:i.20100


## J, 30 (summing unneeded)

+/\_2{.\(#~i.201)+//.>:i.20100


## J, 33

~.+/\(#~i.200)(+/*2|#)/.1+i.2!200

• Summing the groups you'll scratch later is a nice codesize optimization, but in an "implement it this way" context, I feel robbed ;) – J B Mar 12 '11 at 9:51
• @JB: well... I am using Juzuk's method, I just sum zeros :) – Eelvex Mar 12 '11 at 9:59

print[sum$concat$take x[take x\$drop(sum[1..x-1])[1..]|x<-[1,3..]]|x<-[0..100]]
[0,1,16,81,256,625,1296,2401,4096,6561,10000,14641,20736,28561,38416,50625,65536,...


Hope the slightly different output formatting is ok. There's probably a much better way to write this in Haskell, but I felt like solving this in a language I don't often use.

## Python 2, 68

Quick and dirty Python solution:

s=0
for n in range(100):s+=sum(range(2*n*n+n+1,2*n*n+3*n+2));print s