Skip to main content
Commonmark migration
Source Link

#PHP, 114 bytes

PHP, 114 bytes

ignore the line breaks; they are for readability only.

function u($n,$m){return$m>1&$n>1?u(u($n-1,$m),$m-1):3**$n;}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);

It is possible to integrate the second case into the first one: for n=1, 3^n equals 3.
This will save a few bytes on - as far as I can see - all existing answers; saved two bytes on my

previous version, 62+43+11=116 bytes

function u($n,$m){return$m>1?$n>1?u(u($n-1,$m),$m-1):3:3**$n;}

PHP´s left associativity of the ternary requires parentheses ... or a specific order of tests.
This saved two bytes on the parenthesized expression.


There is probably an iterative approach, which may allow further golfing ...
but I can´t take the time for it now.

#PHP, 114 bytes

ignore the line breaks; they are for readability only.

function u($n,$m){return$m>1&$n>1?u(u($n-1,$m),$m-1):3**$n;}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);

It is possible to integrate the second case into the first one: for n=1, 3^n equals 3.
This will save a few bytes on - as far as I can see - all existing answers; saved two bytes on my

previous version, 62+43+11=116 bytes

function u($n,$m){return$m>1?$n>1?u(u($n-1,$m),$m-1):3:3**$n;}

PHP´s left associativity of the ternary requires parentheses ... or a specific order of tests.
This saved two bytes on the parenthesized expression.


There is probably an iterative approach, which may allow further golfing ...
but I can´t take the time for it now.

PHP, 114 bytes

ignore the line breaks; they are for readability only.

function u($n,$m){return$m>1&$n>1?u(u($n-1,$m),$m-1):3**$n;}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);

It is possible to integrate the second case into the first one: for n=1, 3^n equals 3.
This will save a few bytes on - as far as I can see - all existing answers; saved two bytes on my

previous version, 62+43+11=116 bytes

function u($n,$m){return$m>1?$n>1?u(u($n-1,$m),$m-1):3:3**$n;}

PHP´s left associativity of the ternary requires parentheses ... or a specific order of tests.
This saved two bytes on the parenthesized expression.


There is probably an iterative approach, which may allow further golfing ...
but I can´t take the time for it now.

iterative approach was faulty
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41

#PHP, 60+43+11 = 114 63 52114 bytes

There is probably an iterative approach, which may allow further golfing ...

g(m) is u(3,m), so let me see ...

m=1:
u(n,1) := 3^n

m=2: u(n,2)
    =u(u(n-1,2),1)      n=1: 3
    =3^u(n-1,2)         n=2: 3^u(1,2)=3^3
    =3^u(u(n-2,2),1)    n=3: 3^u(u(1,2),1)
    =3^3^u(n-2,2)           =3^3^u(1,2)=3^3^3
    =3^3^u(u(n-3,2),1)  n=4: 3^3^u(u(1,2),1)
    =3^3^3^u(n-3,2)         =3^3^3^u(1,2)=3^3^3^3
--> eval('$u=3'.str_repeat('^3',$n-1).';');

m=3: u(n,3) = u(u(n-1,3),2):
    $v=u($n-1,3);
    eval('$u=3'.str_repeat('^3',$v).';');

v=u(n-1,3) = u(u(n-2,3),2):
    $v=u(n-2,3);
    eval('$v=3'.str_repeat('**3',$v-1).',');

there it is: #PHP, 63 bytes

for(;$n<64;$n++)eval('$v=3'.str_repeat('**3',$v-1).';');echo$v;

to actually calculate it, use bc or gmp:

for(;$n<64;$n++)eval('$v='.str_repeat('bcpow(3,',$v-1).'1'.str_repeat(')',$v-1).';');echo$v;

oh wait ...
iteration will circumvent too deep nesting
bcpow() will circumvent integer overflow
but str_repeat() will killI can´t take the RAM somewhere


solution:

for($v=1;$n<64;$n++)for($i=$v;$i--;)$v=bcpow(3,$v);

or #PHP, 52 bytestime for it now.

for($v=1;$n<64;$n++)for($i=$v;$i--;)$v=3**$v;echo$v;

#PHP, 60+43+11 = 114 63 52 bytes

There is an iterative approach, which may allow further golfing ...

g(m) is u(3,m), so let me see ...

m=1:
u(n,1) := 3^n

m=2: u(n,2)
    =u(u(n-1,2),1)      n=1: 3
    =3^u(n-1,2)         n=2: 3^u(1,2)=3^3
    =3^u(u(n-2,2),1)    n=3: 3^u(u(1,2),1)
    =3^3^u(n-2,2)           =3^3^u(1,2)=3^3^3
    =3^3^u(u(n-3,2),1)  n=4: 3^3^u(u(1,2),1)
    =3^3^3^u(n-3,2)         =3^3^3^u(1,2)=3^3^3^3
--> eval('$u=3'.str_repeat('^3',$n-1).';');

m=3: u(n,3) = u(u(n-1,3),2):
    $v=u($n-1,3);
    eval('$u=3'.str_repeat('^3',$v).';');

v=u(n-1,3) = u(u(n-2,3),2):
    $v=u(n-2,3);
    eval('$v=3'.str_repeat('**3',$v-1).',');

there it is: #PHP, 63 bytes

for(;$n<64;$n++)eval('$v=3'.str_repeat('**3',$v-1).';');echo$v;

to actually calculate it, use bc or gmp:

for(;$n<64;$n++)eval('$v='.str_repeat('bcpow(3,',$v-1).'1'.str_repeat(')',$v-1).';');echo$v;

oh wait ...
iteration will circumvent too deep nesting
bcpow() will circumvent integer overflow
but str_repeat() will kill the RAM somewhere


solution:

for($v=1;$n<64;$n++)for($i=$v;$i--;)$v=bcpow(3,$v);

or #PHP, 52 bytes

for($v=1;$n<64;$n++)for($i=$v;$i--;)$v=3**$v;echo$v;

#PHP, 114 bytes

There is probably an iterative approach, which may allow further golfing ...
but I can´t take the time for it now.

edited body
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
function u($n,$m){return$m<2&$n<2return$m>1&$n>1?3**$n:u(u($n-1,$m),$m-1);:3**$n;}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);
function u($n,$m){return$m<2&$n<2?3**$n:u(u($n-1,$m),$m-1);}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);
function u($n,$m){return$m>1&$n>1?u(u($n-1,$m),$m-1):3**$n;}
function g($x){return u(3,$x>1?g($x-1):4);}
echo g(63);
solution to RAM bug, golfs another 11 bytes
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
added 16 characters in body
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
iterative solution ... bug
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
iterative solution
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
deleted 1 character in body
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading
Source Link
Titus
  • 14.8k
  • 1
  • 24
  • 41
Loading