2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 5a23c84252665b21eecc7e76
|
2020-12-16 00:37:30 -07:00
|
|
|
|
title: 伽玛功能
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
实现一个算法(或更多)来计算[Gamma](<https://en.wikipedia.org/wiki/Gamma function>) ($ \\ Gamma $)函数(仅在实际字段中)。 Gamma功能可以定义为:
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
$ \\ Gamma(x)= \\ displaystyle \\ int_0 ^ \\ infty t ^ {x-1} e ^ { - t} dt $
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma`应该是一个功能。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
assert(typeof gamma == 'function');
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[0]+")`应该返回一个数字。
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert(typeof gamma(0.1) == 'number');
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[0]+")`应该返回`"+results[0]+"` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
```js
|
|
|
|
|
assert.equal(round(gamma(0.1)), round(9.513507698668736));
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[1]+")`应该返回`"+results[1]+"` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
assert.equal(round(gamma(0.2)), round(4.590843711998803));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[2]+")`应该返回`"+results[2]+"` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
```js
|
|
|
|
|
assert.equal(round(gamma(0.3)), round(2.9915689876875904));
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[3]+")`应该返回`"+results[3]+"` 。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
assert.equal(round(gamma(0.4)), round(2.218159543757687));
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`gamma("+tests[4]+")`应返回`"+results[4]+"` 。
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
assert.equal(round(gamma(0.5)), round(1.7724538509055159));
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|