Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.5 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
59c3ec9f15068017c96eb8a3 Farey序列 5 farey-sequence

--description--

编写一个返回n阶Farey序列的函数。该函数应该有一个参数n。它应该将序列作为数组返回。阅读以下内容了解更多详情

阶数n的Farey序列 F n是在0和1之间的完全减少的分数的序列当在最低阶段时具有小于或等于n的分母按照增大的大小排列。

Farey序列有时被错误地称为Farey系列。

每个Farey序列

:: *以值0开头由分数$ \ frac {0} {1} $表示

:: *以值1结尾由$ \ frac {1} {1} $分数表示。

订单1到5的Farey序列是

$ {\ bf \ it {F}} _ 1 = \ frac {0} {1}\ frac {1} {1} $

$ {\ bf \ it {F}} _ 2 = \ frac {0} {1}\ frac {1} {2}\ frac {1} {1} $

$ {\ bf \ it {F}} _ 3 = \ frac {0} {1}\ frac {1} {3}\ frac {1} {2}\ frac {2} {3}\ frac {1} {1} $

$ {\ bf \ it {F}} _ 4 = \ frac {0} {1}\ frac {1} {4}\ frac {1} {3}\ frac {1} {2}\ frac {2} {3}\ frac {3} {4}\ frac {1} {1} $

$ {\ bf \ it {F}} _ 5 = \ frac {0} {1}\ frac {1} {5}\ frac {1} {4}\ frac {1} {3}\ frac {2} {5}\ frac {1} {2}\ frac {3} {5}\ frac {2} {3}\ frac {3} {4}\ frac {4} {5 }\ frac {1} {1} $

--hints--

farey是一种功能。

assert(typeof farey === 'function');

farey(3)应该返回一个数组

assert(Array.isArray(farey(3)));

farey(3)应该返回["1/3","1/2","2/3"]

assert.deepEqual(farey(3), ['1/3', '1/2', '2/3']);

farey(4)应该返回["1/4","1/3","1/2","2/4","2/3","3/4"]

assert.deepEqual(farey(4), ['1/4', '1/3', '1/2', '2/4', '2/3', '3/4']);

farey(5)应返回["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]

assert.deepEqual(farey(5), [
  '1/5',
  '1/4',
  '1/3',
  '2/5',
  '1/2',
  '2/4',
  '3/5',
  '2/3',
  '3/4',
  '4/5'
]);

--seed--

--seed-contents--

function farey(n) {

}

--solutions--

function farey(n){
    let farSeq=[];
    for(let den = 1; den <= n; den++){
        for(let num = 1; num < den; num++){
            farSeq.push({
                str:num+"/"+den,
                val:num/den});
        }
    }
    farSeq.sort(function(a,b){
        return a.val-b.val;
    });
    farSeq=farSeq.map(function(a){
        return a.str;
    });
    return farSeq;
}