* 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>
2.1 KiB
2.1 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
5e6dd14797f5ce267c2f19d0 | Look-and-say sequence | 5 | 385277 | look-and-say-sequence |
--description--
The Look and say sequence is a recursively defined sequence of numbers.
Sequence Definition
- Take a decimal number
- Look at the number, visually grouping consecutive runs of the same digit.
- Say the number, from left to right, group by group; as how many of that digit there are - followed by the digit grouped.
An example:
- Starting with the number 1, you have one 1 which produces 11
- Starting with 11, you have two 1's. I.E.: 21
- Starting with 21, you have one 2, then one 1. I.E.: (12)(11) which becomes 1211
- Starting with 1211, you have one 1, one 2, then two 1's. I.E.: (11)(12)(21) which becomes 111221
--instructions--
Write a function that accepts a string as a parameter, processes it, and returns the resultant string.
--hints--
lookAndSay
should be a function.
assert(typeof lookAndSay == 'function');
lookAndSay("1")
should return a string.
assert(typeof lookAndSay('1') == 'string');
lookAndSay("1")
should return "11"
.
assert.equal(lookAndSay('1'), '11');
lookAndSay("11")
should return "21"
.
assert.equal(lookAndSay('11'), '21');
lookAndSay("21")
should return "1211"
.
assert.equal(lookAndSay('21'), '1211');
lookAndSay("1211")
should return "111221"
.
assert.equal(lookAndSay('1211'), '111221');
lookAndSay("3542")
should return "13151412"
.
assert.equal(lookAndSay('3542'), '13151412');
--seed--
--seed-contents--
function lookAndSay(str) {
}
--solutions--
function lookAndSay(str) {
return str.replace(/(.)\1*/g, function(seq, p1) {
return seq.length.toString() + p1;
});
}