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>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -3,6 +3,7 @@ id: 5a7dad05be01840e1778a0d1
|
||||
title: Fractran
|
||||
challengeType: 3
|
||||
videoUrl: ''
|
||||
dashedName: fractran
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -58,5 +59,54 @@ assert.deepEqual(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function fractran(progStr) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function fractran(progStr){
|
||||
var num = new Array();
|
||||
var den = new Array();
|
||||
var val ;
|
||||
var out="";
|
||||
function compile(prog){
|
||||
var regex = /\s*(\d*)\s*\/\s*(\d*)\s*(.*)/m;
|
||||
while(regex.test(prog)){
|
||||
num.push(regex.exec(prog)[1]);
|
||||
den.push(regex.exec(prog)[2]);
|
||||
prog = regex.exec(prog)[3];
|
||||
}
|
||||
}
|
||||
|
||||
function step(val){
|
||||
var i=0;
|
||||
while(i<den.length && val%den[i] != 0) i++;
|
||||
return num[i]*val/den[i];
|
||||
}
|
||||
|
||||
var seq=[]
|
||||
|
||||
function exec(val){
|
||||
var i = 0;
|
||||
while(val && i<limit){
|
||||
seq.push(val)
|
||||
val = step(val);
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
// Main
|
||||
compile(progStr);
|
||||
var limit = 10;
|
||||
exec(2);
|
||||
return seq;
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user