정션 인쇄


16

로 표시되는 Tetration a^^b이 반복 지수화됩니다. 예를 들어 2^^3is 2^2^2는 16입니다.

두 개의 숫자 ab가 주어지면 인쇄하십시오 a^^b.

테스트 사례

1 2 -> 1
2 2 -> 4
5 2 -> 3125
3 3 -> 7625597484987
etc.

과학적 표기법이 허용됩니다.

이것은 이므로 바이트 수가 가장 적은 코드가 이깁니다.


2
어떤 종류의 숫자입니까? 양의 정수?
xnor


9
지수화는 비연 관적입니다. b> 2 인 테스트 아카데미를 하나 이상 포함해야합니다 .
Dennis

@Dennis3 3 -> 7625597484987
가브리엘 Benamy

1
@RosLuP 아니요, 3^3^3자동을 의미 3^(3^(3))합니다. en.wikipedia.org/wiki/Order_of_operations를 참조하십시오. "스택 된 지수는 위에서 아래로, 즉 오른쪽에서 왼쪽으로 적용됩니다."라고 표시되어 있습니다.
Oliver Ni

답변:


14

Dyalog APL, 3 바이트

*/⍴

TryAPL.

설명

*/⍴  Input: b (LHS), a (RHS)
  ⍴  Create b copies of a
*/   Reduce from right-to-left using exponentation

1
@Dennis를 때리는 사람! 이제는 드 rare니다! (; : P
HyperNeutrino

10

J, 5 4 바이트

^/@#

이것은 말 그대로 정의의 정의입니다.

용법

   f =: ^/@#
   3 f 2
16
   2 f 1
1
   2 f 2
4
   2 f 5
3125
   4 f 2
65536

설명

^/@#  Input: b (LHS), a (RHS)
   #  Make b copies of a
^/@   Reduce from right-to-left using exponentation

Ok a ^^ b is
reverseed

@RosLuP 예, J와 APL 때문에, 오른쪽에서 왼쪽에서 평가 2 ^ 2 ^ 2로서 평가 2 ^ (2 ^ 2)
마일

9

하스켈, 19 바이트

a%b=iterate(a^)1!!b

1목록을 생성하기 위해 시작하여 지수를 반복 [1,a,a^a,a^a^a,...]한 다음 b'번째 요소 를 가져옵니다 .

동일한 길이를 직접 :

a%0=1;a%b=a^a%(b-1)

포인트 프리가 더 깁니다 :

(!!).(`iterate`1).(^)

9

수학, 16 바이트

Power@@Table@##&

설명

Table@##

b의 사본을 만듭니다.

Power@@...

지수화.


8

파이썬, 30 바이트

f=lambda a,b:b<1or a**f(a,b-1)

재귀 정의를 사용합니다.


5

파이썬, 33 바이트

lambda a,b:eval('**'.join([a]*b))

이것은 숫자와 숫자의 문자열 표현을 취하는 명명되지 않은 함수로 평가됩니다. 예를 들면 다음과 같습니다.

>>> f=lambda a,b:eval('**'.join([a]*b))
>>> f('5',2)
3125
>>>

이와 같은 입력 형식을 혼합하지 않으면 38 바이트 버전도 있습니다.

lambda a,b:eval('**'.join([str(a)]*b))

2
정말 멋진 방법입니다!
xnor


3

펄, 19 바이트

에 +1 포함 -p

STDIN에서 별도의 줄에 숫자를 입력하십시오

tetration.pl
2
3
^D

tetration.pl

#!/usr/bin/perl -p
$_=eval"$_**"x<>.1

3

R, 39 바이트

재귀 함수 :

f=function(a,b)ifelse(b>0,a^f(a,b-1),1)

2

요소 , 11 바이트

__2:':1[^]`

온라인으로 사용해보십시오!

이것은 루프에서 "직선"지수입니다.

__2:':1[^]`
__              take two values as input (x and y)
  2:'           duplicate y and send one copy to the control stack
     :          make y copies of x
      1         push 1 as the initial value
       [ ]      loop y times
        ^       exponentiate
          `     print result

2

자바 스크립트 (ES7), 24 바이트

f=(a,b)=>b?a**f(a,b-1):1

ES6 버전은 33 바이트입니다.

f=(a,b)=>b?Math.pow(a,f(a,b-1)):1

1 바이트 저장 :f=a=>b=>b?a**f(a,b-1):1
programmer5000

2

dc, 35 29 바이트 :

?dsdsa?[ldla^sa1-d1<b]dsbxlap

의 첫 번째 완전한 프로그램은 다음과 같습니다 dc.


1

펄, 40 바이트

map{$a=$ARGV[0]**$a}0..$ARGV[1];print$a;

함수에 두 개의 정수를 입력하고 결과를 출력합니다.


1
사용 pop얻을 $ARGV[1]후 사용 "@ARGV"얻을 $ARGV[0]. (옵션 또는 무료) say대신 사용하십시오 . 그러나 여전히 길다. 프로그램은 거의 항상 승리print-M5.010-EARGV-p
톤 Hospel에게




1

게임 메이커 언어, 52 50 바이트

d=a=argument0;for(c=1;c<b;c++)d=power(a,d)return d

이것은 내 300 번째 답변입니다 : o
Timtech

게임 메이커 lol
단순히 아름다운 예술

@SimplyBeautifulArt 예, 그리고 내가있는 동안 나는 당신을 위해 2 바이트를 벗을 것입니다.
Timtech

롤, 좋아 =) 내 +1을 가지고 있고, 단순 해 보이며 이해합니다.
Simply Beautiful Art

@SimplyBeautifulArt 감사
Timtech


0

Minkolang 0.15 , 12 11 바이트

nnDI1-[;]N.

여기 사용해보십시오!

설명

nn             Read two integers from input
  D            Pop top of stack and duplicate next element that many times
   I1-         Push length of stack, minus 1
      [        Pop top of stack and repeat for loop that many times
       ;       Pop b, a and push a^b
        ]      Close for loop
         N.    Output as number and stop.

0

라켓 51 바이트

(define ans 1)(for((i b))(set! ans(expt a ans)))ans

언 골프 드 :

(define (f a b)
  (define ans 1)
  (for((i b))
    (set! ans
          (expt a ans)))
  ans)

테스트 :

(f 1 2)
(f 2 2)
(f 5 2)
(f 3 3)

산출:

1
4
3125
7625597484987

0

스칼라, 45 바이트

Seq.fill(_:Int)(_:Double)reduceRight math.pow

언 골프 드 :

(a:Int,b:Double)=>Seq.fill(a)(b).reduceRight(math.pow)

요소를 사용 하여 일련의 as를 작성하고 오른쪽에서 왼쪽으로 b적용하십시오 math.pow.


0

TI 기본, 19 바이트

Prompt A,B
A
For(C,2,B
A^Ans
End

0

자바 7, 71 57 바이트

double c(int a,int b){return b>0?Math.pow(a,c(a,b-1)):1;}

언 골프 및 테스트 코드 :

여기에서 시도하십시오.

class M{
  static double c(int a, int b){
    return b > 0
            ? Math.pow(a, c(a, b-1))
            :1;
  }

  public static void main(String[] a){
    System.out.println(c(1, 2));
    System.out.println(c(2, 2));
    System.out.println(c(5, 2));
    System.out.println(c(3, 3));
  }
}

산출:

1.0
4.0
3125.0
7.625597484987E12

0

C, 50 bytes

double t(int x,int n){return n?pow(x,t(x,n-1)):1;}

Straightforward from the definition of Tetration.


0

05AB1E, 4 bytes

sF¹m

Try it online!

s     # Swap input arguments.
 F    # N times...
  ¹m  # Top of the stack ^ the first argument.

3 bytes if arguments can be swapped:

F¹m

2 2 result 16 not 4=2^2
RosLuP

a=5, b=2 should output 3125. I'm not sure what order you're taking the input in , but however I put in 5 and 2 I get the wrong result.
FlipTack

0

Bash, 50 bytes

(within the bounds of bash integer data type)

Golfed

E() { echo $(($(printf "$1**%.0s" `seq 1 $2`)1));}

Explanation

Build expression with printf, e.g. E 2 5:

  2**2**2**2**2**1

then use bash built-in arithmetic expansion to compute the result

Test

E 1 2
1

E 2 2
4

E 5 2
3125

E 3 3
7625597484987

0

Powershell, 68 Bytes

filter p ($a){[math]::Pow($a,$_)};iex (,$args[0]*$args[1]-join"|p ")

This is the shortest of the three approaches I tried, not that great overall though, i'm 100% sure there's a shorter approach but the few things I tried somehow ended up with slightly more bytes.

PS C:\++\golf> (1,2),(2,2),(5,2),(3,3) | % {.\sqsq $_[0] $_[1]}
1
4
3125
7625597484987

Sadly Powershell has no built-in ^ or ** operator, or it would be a clean 32/33 byte answer, i.e.

iex (,$args[0]*$args[1]-join"^")


0

Axiom 70 bytes

l(a,b)==(local i;i:=1;r:=a;repeat(if i>=b then break;r:=a^r;i:=i+1);r)

this less golfed

l(a,b)==
  local i
  i:=1;r:=a;repeat(if i>=b then break;r:=a^r;i:=i+1)
  r


(3) ->  [l(1,2),l(2,2),l(5,2),l(3,3),l(4,3)]

     (3)
     [1, 4, 3125, 7625597484987,
      13407807929942597099574024998205846127479365820592393377723561443721764030_
       0735469768018742981669034276900318581864860508537538828119465699464336490_
       06084096
       ]
                                                   Type: List PositiveInteger

0

Wonder, 21 bytes

f\@@[#0?^#1f#1-#0 1?1

Uses the recursive approach. Usage:

f\@@[#0?^#1f#1-#0 1?1];f 2 3

Bonus solution, 22 bytes

@@:^ -#0 1(genc ^#1)#1

A slightly unconventional approach. Usage:

t\@@+>#[^;#1]tk -#0 1rpt#1;t 2 3

More readable:

@@
  iget
    - #0 1
    (genc ^#1) #1

Assuming a^^b:

Generates an infinite list of tetrated a; for a=2, this list would look something like [2 4 16 65536...]. Then indexes at b-1 because Wonder is zero-indexed.


0

Clojure, 56 bytes

(fn[a b](last(take a(iterate #(apply *(repeat % b))b))))

Maybe there is a shorter way via apply comp?

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.