/* Implement the hyperfactorial (code golf) in Picat. https://codegolf.stackexchange.com/questions/235964/implement-the-hyperfactorial """ Implement the hyperfactorial The objective Given the non-negative integer n , output the value of the hyperfactorial H(n) . You don't have to worry about outputs exceeding your language's integer limit. Background The hyperfactorial is a variant of the factorial function. is defined as H(n)=1^1⋅2^2⋅3^3....⋅n^n For example, H(4)=1^1⋅2^2⋅3^3⋅4^4=27648 Test cases n H(n) 0 1 1 1 2 4 3 108 4 27648 5 86400000 6 4031078400000 7 3319766398771200000 8 55696437941726556979200000 Rules The standard loopholes are forbidden. As this is a code-golf, the shortest code in bytes wins. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go ?=> println(f=[f(N):N in 1..8]), println(g=[g(N):N in 1..8]), println(h=[h(N):N in 1..8]), nl. go => true. % 21 chars f(N)=[I**I:I in 1..N].prod. % 25 chars g(1)=1. g(N)=N**N*g(N-1). % 34 chars t(N)=N**N. h(N)=(1..N).map(t).prod.