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: 59694356a6e7011f7f1c5f4e
|
||||
title: FreeCell的交易卡
|
||||
challengeType: 5
|
||||
videoUrl: ''
|
||||
dashedName: deal-cards-for-freecell
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -63,5 +64,98 @@ assert.deepEqual(dealFreeCell(1), game1);
|
||||
assert.deepEqual(dealFreeCell(617), game617);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --after-user-code--
|
||||
|
||||
```js
|
||||
const replaceThis = 3;
|
||||
const game1 = [
|
||||
['JD', '2D', '9H', 'JC', '5D', '7H', '7C', '5H'],
|
||||
['KD', 'KC', '9S', '5S', 'AD', 'QC', 'KH', '3H'],
|
||||
['2S', 'KS', '9D', 'QD', 'JS', 'AS', 'AH', '3C'],
|
||||
['4C', '5C', 'TS', 'QH', '4H', 'AC', '4D', '7S'],
|
||||
['3S', 'TD', '4S', 'TH', '8H', '2C', 'JH', '7D'],
|
||||
['6D', '8S', '8D', 'QS', '6C', '3D', '8C', 'TC'],
|
||||
['6S', '9C', '2H', '6H']
|
||||
];
|
||||
const game617 = [
|
||||
['7D', 'AD', '5C', '3S', '5S', '8C', '2D', 'AH'],
|
||||
['TD', '7S', 'QD', 'AC', '6D', '8H', 'AS', 'KH'],
|
||||
['TH', 'QC', '3H', '9D', '6S', '8D', '3D', 'TC'],
|
||||
['KD', '5H', '9S', '3C', '8S', '7H', '4D', 'JS'],
|
||||
['4C', 'QS', '9C', '9H', '7C', '6H', '2C', '2S'],
|
||||
['4S', 'TS', '2H', '5D', 'JC', '6C', 'JH', 'QH'],
|
||||
['JD', 'KS', 'KC', '4H']
|
||||
];
|
||||
```
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function dealFreeCell(seed) {
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
// RNG
|
||||
function FreeCellRNG(seed) {
|
||||
return {
|
||||
lastNum: seed,
|
||||
next() {
|
||||
this.lastNum = ((214013 * this.lastNum) + 2531011) % (Math.pow(2, 31));
|
||||
return this.lastNum >> 16;
|
||||
}
|
||||
};
|
||||
}
|
||||
// Get cards
|
||||
function getDeck() {
|
||||
const ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'];
|
||||
const suits = ['C', 'D', 'H', 'S'];
|
||||
const cards = [];
|
||||
for (let i = 0; i < ranks.length; i += 1) {
|
||||
for (let j = 0; j < suits.length; j += 1) {
|
||||
cards.push(`${ranks[i]}${suits[j]}`);
|
||||
}
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
function dealFreeCell(seed) {
|
||||
const rng = FreeCellRNG(seed);
|
||||
const deck = getDeck();
|
||||
|
||||
const deltCards = [[], [], [], [], [], [], []];
|
||||
let currentColumn = 0;
|
||||
let currentRow = 0;
|
||||
|
||||
let rand;
|
||||
let temp;
|
||||
let card;
|
||||
while (deck.length > 0) {
|
||||
// Choose a random card
|
||||
rand = rng.next() % deck.length;
|
||||
|
||||
// Swap this random card with the last card in the array
|
||||
temp = deck[deck.length - 1];
|
||||
deck[deck.length - 1] = deck[rand];
|
||||
deck[rand] = temp;
|
||||
|
||||
// Remove this card from the array
|
||||
card = deck.pop();
|
||||
|
||||
// Deal this card
|
||||
deltCards[currentRow].push(card);
|
||||
currentColumn += 1;
|
||||
if (currentColumn === 8) {
|
||||
currentColumn = 0;
|
||||
currentRow += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return deltCards;
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user