diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stern-brocot-sequence.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stern-brocot-sequence.md index a6bb5ef3b21..3aedf64540e 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stern-brocot-sequence.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stern-brocot-sequence.md @@ -6,8 +6,7 @@ challengeType: 5 ## Description
-For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the -Fibonacci sequence. +For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the Fibonacci sequence.
  1. The first and second members of the sequence are both 1:
  2. @@ -31,12 +30,11 @@ For this task, the Stern-Brocot sequence is to be generated by an algorithm simi
  3. Consider the next member of the series, (the fourth member i.e. 1)
-Create a function that returns the $ n^{th} $ member of the sequence using the method outlined above.
## Instructions
- +Create a function that returns the $ n^{th} $ member of the sequence using the method outlined above.
## Tests @@ -67,7 +65,7 @@ tests:
```js -function sternBrocot (num) { +function sternBrocot(num) { // Good luck! } ``` @@ -79,7 +77,7 @@ function sternBrocot (num) {
```js -function sternBrocot (num) { +function sternBrocot(num) { function f(n) { return n < 2 ? n : (n & 1) ? f(Math.floor(n / 2)) + f(Math.floor(n / 2 + 1)) : f(Math.floor(n / 2)); } diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/straddling-checkerboard.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/straddling-checkerboard.md index 8001f98c62e..a860949ef05 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/straddling-checkerboard.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/straddling-checkerboard.md @@ -6,7 +6,7 @@ challengeType: 5 ## Description
-Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The functions will take a string and an array as parameters. The array has 3 strings representing the 3 rows of the checkerboard. The output will be a series of decimal digits. +Implement functions to encrypt and decrypt a message using the straddling checkerboard method. The functions will take a string and an array as parameters. The array has 3 strings representing the 3 rows of the checkerboard. The output will be a series of decimal digits. Numbers should be encrypted by inserting the escape character before each digit, then including the digit unencrypted. This should be reversed for decryption.
@@ -49,10 +49,11 @@ tests:
```js -function straddle (message, alphabet) { +function straddle(message, alphabet) { // Good luck! } -function unstraddle (message, alphabet) { + +function unstraddle(message, alphabet) { // Good luck! } ``` @@ -64,7 +65,7 @@ function unstraddle (message, alphabet) {
```js -function straddle (message, alphabet) { +function straddle(message, alphabet) { var prefixes = new Array("", alphabet[0].indexOf(" "), alphabet[0].lastIndexOf(" ")) var out = "" @@ -82,7 +83,7 @@ function straddle (message, alphabet) { } return out } -function unstraddle (message, alphabet) { +function unstraddle(message, alphabet) { var prefixes = new Array("", alphabet[0].indexOf(" "), alphabet[0].lastIndexOf(" ")) var out = "" var n, o diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stream-merge.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stream-merge.md index 86b1ed700c2..d6a94077ace 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stream-merge.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/stream-merge.md @@ -21,8 +21,8 @@ Write a function that takes multiple sorted arrays of items, and returns one arr tests: - text: mergeLists should be a function. testString: assert(typeof mergeLists == 'function', 'mergeLists should be a function.'); - - text: mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return a array. - testString: assert(Array.isArray(mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])), 'mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return a array.'); + - text: mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return an array. + testString: assert(Array.isArray(mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]])), 'mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return an array.'); - text: mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. testString: assert.deepEqual(mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'mergeLists([[1, 3, 5, 9, 10], [2, 4, 6, 7, 8]]) should return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].'); - text: mergeLists([[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]]) should return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]. @@ -42,7 +42,7 @@ tests:
```js -function mergeLists (lists) { +function mergeLists(lists) { // Good luck! } ``` @@ -54,7 +54,7 @@ function mergeLists (lists) {
```js -function mergeLists (lists) { +function mergeLists(lists) { function merge (l1, l2) { var result = [], i=0, j=0; while (l1.length && l2.length) { diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/strip-control-codes-and-extended-characters-from-a-string.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/strip-control-codes-and-extended-characters-from-a-string.md index d9766261635..45e493e9c49 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/strip-control-codes-and-extended-characters-from-a-string.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/strip-control-codes-and-extended-characters-from-a-string.md @@ -6,8 +6,7 @@ challengeType: 5 ## Description
-The task is to strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results: -A string with control codes and extended characters stripped. +The task is to strip control codes and extended characters from a string. In ASCII, the control codes have decimal codes 0 through to 31 and 127. On an ASCII based system, if the control codes are stripped, the resultant string would have all of its characters within the range of 32 to 126 decimal on the ASCII table. On a non-ASCII based system, we consider characters that do not have a corresponding glyph on the ASCII table (within the ASCII range of 32 to 126 decimal) to be an extended character for the purpose of this task.
@@ -45,7 +44,7 @@ tests:
```js -function strip (s) { +function strip(s) { // Good luck! } ``` @@ -57,7 +56,7 @@ function strip (s) {
```js -function strip (s) { +function strip(s) { return s.split('').filter(function(x) { var n = x.charCodeAt(0); diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/subleq.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/subleq.md index eaee485dd40..e26a8a98011 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/subleq.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/subleq.md @@ -6,8 +6,7 @@ challengeType: 5 ## Description
-Subleq is an example of a One-Instruction - Set Computer (OISC). +Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Your task is to create an interpreter which emulates such a machine. @@ -35,7 +34,8 @@ character sets or Unicode. You may translate it into another character set if yo non-ASCiI-compatible environment.)
15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 0 -1 72 101 108 108 111 44 32 119 111 114 108 100 33 10 0
Which corresponds to something like this in a hypothetical assembler language: -
start:
+
+start:
     zero, message, -1
     message, -1, -1
     neg1, start+1, -1
@@ -43,14 +43,14 @@ Which corresponds to something like this in a hypothetical assembler language:
     zero, zero, start
 zero: 0
 neg1: -1
-message: "Hello, world!\n\0"
-Write a function that takes an array of integers as a parameter. This represents the memory elements. The function -should interpret the sequence and return the output string. For this task, assume that there is no standard input. +message: "Hello, world!\n\0" +
## Instructions
- +Write a function that takes an array of integers as a parameter. This represents the memory elements. The function +should interpret the sequence and return the output string. For this task, assume that there is no standard input.
## Tests @@ -73,7 +73,7 @@ tests:
```js -function Subleq (mem) { +function Subleq(mem) { // Good luck! } ``` @@ -85,7 +85,7 @@ function Subleq (mem) {
```js -function Subleq (mem) { +function Subleq(mem) { var out = ""; var instructionPointer = 0; do { diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sudoku.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sudoku.md index 1da23b47e47..45d268b1c15 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sudoku.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sudoku.md @@ -6,8 +6,8 @@ challengeType: 5 ## Description
-Write a function to solve a partially filled-in normal 9x9 Sudoku grid and return the result. The blank fields are represented by 0s. -Algorithmics of Sudoku may help implement this. +Write a function to solve a partially filled-in normal 9x9 Sudoku grid and return the result. The blank fields are represented by 0s. +Algorithmics of Sudoku may help implement this.
## Instructions @@ -22,8 +22,8 @@ Write a function to solve a partially filled-in normal 9x9 series, i.e. the sum of the n first terms of the corresponding sequence. +Compute the nth term of a series, i.e. the sum of the n first terms of the corresponding sequence. Informally this value, or its limit when n tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: -$S_n = \sum_{k=1}^n \frac{1}{k^2}$ +$S_n = \sum_{k=1}^n \frac{1}{k^2}$ and compute $S_{1000}$ This approximates the zeta function for S=2, whose exact value -$\zeta(2) = {\pi^2\over 6}$ +$\zeta(2) = {\pi^2\over 6}$ is the solution of the Basel problem. -Write a function that take $a$ and $b$ as parameters and returns the sum of $a^{th}$ to $b^{th}$ members of the sequence.
## Instructions
- +Write a function that take $a$ and $b$ as parameters and returns the sum of $a^{th}$ to $b^{th}$ members of the sequence.
## Tests @@ -50,7 +49,7 @@ tests:
```js -function sum (a, b) { +function sum(a, b) { // Good luck! } ``` @@ -62,7 +61,7 @@ function sum (a, b) {
```js -function sum (a, b) { +function sum(a, b) { function fn(x) { return 1 / (x * x) } diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-of-squares.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-of-squares.md index c6f73e4adeb..cc55ba63582 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-of-squares.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-of-squares.md @@ -42,7 +42,7 @@ tests:
```js -function sumsq (array) { +function sumsq(array) { // Good luck! } ``` @@ -54,7 +54,7 @@ function sumsq (array) {
```js -function sumsq (array) { +function sumsq(array) { var sum = 0; var i, iLen; diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-to-100.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-to-100.md index cc5471e3cb0..7d4dbae9a0c 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-to-100.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sum-to-100.md @@ -10,12 +10,11 @@ Find solutions to the sum to one hundred puzzle. Add (insert) the mathematical operators + or (plus or minus) before any of the digits in the decimal numeric string 123456789 such that the resulting mathematical expression adds up to a particular sum (in this iconic case, 100). Example:
123 + 4 - 5 + 67 - 89   =   100
-Write a function that takes a number as parameter. The function should return an array containing all solutions for the given number. The solutions should be strings representing the expressions. For example: "1+23-456+78-9". Note: sort the array before returning it.
## Instructions
- +Write a function that takes a number as parameter. The function should return an array containing all solutions for the given number. The solutions should be strings representing the expressions. For example: "1+23-456+78-9". Sort the array before returning it.
## Tests @@ -25,8 +24,8 @@ Write a function that takes a number as parameter. The function should return an tests: - text: sumTo100 should be a function. testString: assert(typeof sumTo100 == 'function', 'sumTo100 should be a function.'); - - text: sumTo100(199) should return a array. - testString: assert(Array.isArray(sumTo100(199)), 'sumTo100(199) should return a array.'); + - text: sumTo100(199) should return an array. + testString: assert(Array.isArray(sumTo100(199)), 'sumTo100(199) should return an array.'); - text: sumTo100(199) should return ["-1+2-3+45+67+89", "123-4+5+6+78-9", "123-4+56+7+8+9"]. testString: assert.deepEqual(sumTo100(199), ["-1+2-3+45+67+89", "123-4+5+6+78-9", "123-4+56+7+8+9"], 'sumTo100(199) should return ["-1+2-3+45+67+89", "123-4+5+6+78-9", "123-4+56+7+8+9"].'); - text: sumTo100(209) should return ["1+234+56+7-89"]. @@ -46,7 +45,7 @@ tests:
```js -function sumTo100 (n) { +function sumTo100(n) { // Good luck! } ``` @@ -58,7 +57,7 @@ function sumTo100 (n) {
```js -function sumTo100 (n) { +function sumTo100(n) { var permutationsWithRepetition = function(n, as) { return as.length > 0 ? foldl1(curry(cartesianProduct)(as), replicate(n, as)) : []; diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sutherland-hodgman-polygon-clipping.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sutherland-hodgman-polygon-clipping.md index 1cde765c849..abed0c58f0c 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sutherland-hodgman-polygon-clipping.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sutherland-hodgman-polygon-clipping.md @@ -6,18 +6,17 @@ challengeType: 5 ## Description
-The Sutherland-Hodgman clipping algorithm finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). +The Sutherland-Hodgman clipping algorithm finds the polygon that is the intersection between an arbitrary polygon (the “subject polygon”) and a convex polygon (the “clip polygon”). It is used in computer graphics (especially 2D graphics) to reduce the complexity of a scene being displayed by eliminating parts of a polygon that do not need to be displayed. Take the closed polygon defined by the points: -$[(50, 150), (200, 50), (350, 150), (350, 300), (250, 300), (200, 250), (150, 350), (100, 250), (100, 200)]$ +
[(50, 150), (200, 50), (350, 150), (350, 300), (250, 300), (200, 250), (150, 350), (100, 250), (100, 200)]
and clip it by the rectangle defined by the points: -$[(100, 100), (300, 100), (300, 300), (100, 300)]$ -Write a function that takes 2 arrays as parameters. The first array contains the points of the subject polygon and the second array contains the points of the clipping polygon. The function should return an array containing the points of the clipped polygon. Each number should be rounded to 3 decimal places. +
[(100, 100), (300, 100), (300, 300), (100, 300)]
## Instructions
- +Write a function that takes 2 arrays as parameters. The first array contains the points of the subject polygon and the second array contains the points of the clipping polygon. The function should return an array containing the points of the clipped polygon. Each number should be rounded to 3 decimal places.
## Tests @@ -27,8 +26,8 @@ Write a function that takes 2 arrays as parameters. The first array contains the tests: - text: clip should be a function. testString: assert(typeof clip == 'function', 'clip should be a function.'); - - text: clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return a array. - testString: assert(Array.isArray(clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])), 'clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return a array.'); + - text: clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return an array. + testString: assert(Array.isArray(clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]])), 'clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return an array.'); - text: clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return [[100, 116.667], [125, 100], [275, 100], [300, 116.667], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]]. testString: assert.deepEqual(clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]), [[100, 116.667], [125, 100], [275, 100], [300, 116.667], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]], 'clip([[50, 150], [200, 50], [350, 150], [350, 300], [250, 300], [200, 250], [150, 350], [100, 250], [100, 200]], [[100, 100], [300, 100], [300, 300], [100, 300]]) should return [[100, 116.667], [125, 100], [275, 100], [300, 116.667], [300, 300], [250, 300], [200, 250], [175, 300], [125, 300], [100, 250]].'); - text: clip([[150, 200], [400, 450], [30, 50]], [[10, 10], [300, 200], [400, 600], [100, 300]]) should return [[150, 200], [350, 400], [348.611, 394.444], [30, 50]]. @@ -44,7 +43,7 @@ tests:
```js -function clip (subjectPolygon, clipPolygon) { +function clip(subjectPolygon, clipPolygon) { // Good luck! } ``` @@ -56,7 +55,7 @@ function clip (subjectPolygon, clipPolygon) {
```js -function clip (subjectPolygon, clipPolygon) { +function clip(subjectPolygon, clipPolygon) { var cp1, cp2, s, e, i, j; var inside = function(p) { return (cp2[0] - cp1[0]) * (p[1] - cp1[1]) > (cp2[1] - cp1[1]) * (p[0] - cp1[0]); diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/symmetric-difference.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/symmetric-difference.md index a98889f1fb9..8ea2a048c4e 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/symmetric-difference.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/symmetric-difference.md @@ -6,15 +6,14 @@ challengeType: 5 ## Description
-Given two sets A and B, compute $(A \setminus B) \cup (B \setminus A).$ -That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. +Given two sets A and B, compute $(A \setminus B) \cup (B \setminus A).$ +That is, enumerate the items that are in A or B but not both. This set is called the symmetric difference of A and B. In other words: $(A \cup B) \setminus (A \cap B)$ (the set of items that are in at least one of A or B minus the set of items that are in both A and B). -Write a function that takes two arrays as parameters and returns the symmetric difference. Note: Sort the resultant array before returning it.
## Instructions
- +Write a function that takes two arrays as parameters and returns the symmetric difference. Sort the resultant array before returning it.
## Tests @@ -24,8 +23,8 @@ Write a function that takes two arrays as parameters and returns the symmetric d tests: - text: symmetricDifference should be a function. testString: assert(typeof symmetricDifference == 'function', 'symmetricDifference should be a function.'); - - text: symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return a array. - testString: assert(Array.isArray(symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])), 'symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return a array.'); + - text: symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return an array. + testString: assert(Array.isArray(symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"])), 'symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return an array.'); - text: symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return ["Jim", "Serena"]. testString: assert.deepEqual(symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]), ["Jim", "Serena"], 'symmetricDifference(["John", "Bob", "Mary", "Serena"], ["Jim", "Mary", "John", "Bob"]) should return ["Jim", "Serena"].'); - text: symmetricDifference([1, 2, 3], [3, 4]) should return [1, 2, 4]. @@ -45,7 +44,7 @@ tests:
```js -function symmetricDifference (A, B) { +function symmetricDifference(A, B) { // Good luck! } ``` @@ -57,7 +56,7 @@ function symmetricDifference (A, B) {
```js -function symmetricDifference (A, B) { +function symmetricDifference(A, B) { function relative_complement(A, B) { return A.filter(function(elem) { return B.indexOf(elem) == -1