コードゴルフ – パワーシーケンスの違い

プログラミングQA


x->d->g(x,d,4)double g(int x,int d,int k){return d>0?g(x,--d,k+1)-g(x,d,k):Math.pow(k,x);}

-37 バイトの移植 @loopyWaltのPythonの答え

出力します \$5^{th}\$ int の代わりに double であることを除いて、テスト ケースのような用語。

オンラインで試してみてください。

説明:

x->d->              // Method with two integer parameters and double return-type
  g(x,d,4)          //  Call the recursive method below with k=4

double g(int x,int d,int k){
                    // Recursive method with three integer parameters and double return
  return d>0?       //  If `d` is not 0:
    g(x,--d,k+1)    //   Do a recursive call with x, d-1, k+1
    -g(x,d,k)       //   Subtract a recursive call with x, d-1, k
   :                //  Else:
    Math.pow(k,x);} //   Calculate `k` to the power `x`
                    //   (which results in a double, hence the double return-type)



Source link

コメント

タイトルとURLをコピーしました