diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hailstone-sequence.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hailstone-sequence.english.md index 6b145fa56c..f4ddc4cda0 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hailstone-sequence.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hailstone-sequence.english.md @@ -6,21 +6,27 @@ challengeType: 5 ## Description
-

The Hailstone sequence of numbers can be generated from a starting positive integer, n by:

- If n is 1 then the sequence ends. - If n is even then the next n of the sequence = n/2 - If n is odd then the next n of the sequence = (3 * n) + 1

The (unproven) Collatz conjecture is that the hailstone sequence for any starting number always terminates.

-

The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.

-Task: -Create a routine to generate the hailstone sequence for a number. -Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with 27, 82, 41, 124 and ending with 8, 4, 2, 1 -Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length. (But don't show the actual sequence!)See also: - xkcd (humourous). +The Hailstone sequence of numbers can be generated from a starting positive integer, n by: + +The (unproven) Collatz conjecture is that the hailstone sequence for any starting number always terminates. +The hailstone sequence is also known as hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as the Collatz sequence.
## Instructions
- +
    +
  1. Create a routine to generate the hailstone sequence for a number.
  2. +
  3. Use the routine to show that the hailstone sequence for the number 27 has 112 elements starting with 27, 82, 41, 124 and ending with 8, 4, 2, 1
  4. +
  5. Show the number less than 100,000 which has the longest hailstone sequence together with that sequence's length. (But don't show the actual sequence!)
  6. +
+See also: +
## Tests @@ -44,7 +50,7 @@ tests: ```js // noprotect -function hailstoneSequence () { +function hailstoneSequence() { const res = []; // Good luck! diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/happy-numbers.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/happy-numbers.english.md index 186442168f..616e9931e8 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/happy-numbers.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/happy-numbers.english.md @@ -6,14 +6,13 @@ challengeType: 5 ## Description
-

A happy number is defined by the following process:

-

Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.

-

Implement a function that returns true if the number is happy, or false if not.

+A happy number is defined by the following process: +Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
## Instructions
- +Implement a function that returns true if the number is happy, or false if not.
## Tests @@ -58,7 +57,7 @@ tests:
```js -function happy (number) { +function happy(number) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/harshad-or-niven-series.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/harshad-or-niven-series.english.md index 971800a110..222723d408 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/harshad-or-niven-series.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/harshad-or-niven-series.english.md @@ -6,15 +6,15 @@ challengeType: 5 ## Description
-

The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits.

For example, 42 is a Harshad number as 42 is divisible by (4 + 2) without remainder.

+The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits. +For example, 42 is a Harshad number as 42 is divisible by (4 + 2) without remainder. Assume that the series is defined as the numbers in increasing order. -Task: -

Implement a function to generate successive members of the Harshad sequence.

Use it to list the first twenty members of the sequence and list the first Harshad number greater than 1000.

## Instructions
- +Implement a function to generate successive members of the Harshad sequence. +Use it to list the first twenty members of the sequence and list the first Harshad number greater than 1000.
## Tests @@ -37,7 +37,7 @@ tests:
```js -function isHarshadOrNiven () { +function isHarshadOrNiven() { const res = { firstTwenty: [], firstOver1000: undefined diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-from-two-arrays.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-from-two-arrays.english.md index a8cdbfd902..4d77e67f3c 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-from-two-arrays.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-from-two-arrays.english.md @@ -6,10 +6,11 @@ challengeType: 5 ## Description
-Task: -

Using two Arrays of equal length, create a Hash object where the elements from one array (the keys) are linked to the elements of the other (the values)

-Related task: - Associative arrays/Creation +Using two Arrays of equal length, create a Hash object where the elements from one array (the keys) are linked to the elements of the other (the values). +Related task: +
## Instructions diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-join.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-join.english.md index 45260002e6..5c227461b2 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-join.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hash-join.english.md @@ -6,30 +6,37 @@ challengeType: 5 ## Description
-

An inner join is an operation that combines two data tables into one table, based on matching column values. The simplest way of implementing this operation is the nested loop join algorithm, but a more scalable alternative is the hash join algorithm.

-

Implement the "hash join" algorithm, and demonstrate that it passes the test-case listed below.

You should represent the tables as data structures that feel natural in your programming language.

-

The "hash join" algorithm consists of two steps:

-Hash phase: Create a multimap from one of the two tables, mapping from each join column value to all the rows that contain it. - The multimap must support hash-based lookup which scales better than a simple linear search, because that's the whole point of this algorithm. - Ideally we should create the multimap for the smaller table, thus minimizing its creation time and memory size. -Join phase: Scan the other table, and find matching rows by looking in the multimap created before. -

In pseudo-code, the algorithm could be expressed as follows:

+An inner join is an operation that combines two data tables into one table, based on matching column values. The simplest way of implementing this operation is the nested loop join algorithm, but a more scalable alternative is the hash join algorithm. +The "hash join" algorithm consists of two steps: +
    +
  1. Hash phase: Create a multimap from one of the two tables, mapping from each join column value to all the rows that contain it.
  2. +
      +
    • The multimap must support hash-based lookup which scales better than a simple linear search, because that's the whole point of this algorithm.
    • +
    • Ideally we should create the multimap for the smaller table, thus minimizing its creation time and memory size.
    • +
    +
  3. Join phase: Scan the other table, and find matching rows by looking in the multimap created before.
  4. +
+In pseudo-code, the algorithm could be expressed as follows:
-let A = the first input table (or ideally, the larger one)
-let B = the second input table (or ideally, the smaller one)
-let jA = the join column ID of table A
-let jB = the join column ID of table B
-let MB = a multimap for mapping from single values to multiple rows of table B (starts out empty)
-let C = the output table (starts out empty)
-for each row b in table B:
-  place b in multimap MB under key b(jB)
-for each row a in table A:
-  for each row b in multimap MB under key a(jA):
-    let c = the concatenation of row a and row b
-    place row c in table C

+let A = the first input table (or ideally, the larger one) +let B = the second input table (or ideally, the smaller one) +let jA = the join column ID of table A +let jB = the join column ID of table B +let MB = a multimap for mapping from single values to multiple rows of table B (starts out empty) +let C = the output table (starts out empty) +for each row b in table B: + place b in multimap MB under key b(jB) +for each row a in table A: + for each row b in multimap MB under key a(jA): + let c = the concatenation of row a and row b + place row c in table C
-Test-case -

Input

+
+ +## Instructions +
+Implement the "hash join" algorithm as a function and demonstrate that it passes the test-case listed below. The function should accept two arrays of objects and return an array of combined objects. +

Input

@@ -107,13 +114,13 @@ Test-case
-

Output

+

Output

- - - - + + + @@ -157,13 +164,7 @@ Test-case
A.Age A.Name B.Character B.Nemesis + A_age A_name B_character B_nemesis
27 Alan Zombies
-

The order of the rows in the output table is not significant.

-

If you're using numerically indexed arrays to represent table rows (rather than referring to columns by name), you could represent the output rows in the form [[27, "Jonah"], ["Jonah", "Whales"]].


-
- -## Instructions -
- +The order of the rows in the output table is not significant.
## Tests @@ -186,7 +187,7 @@ tests:
```js -function hashJoin (hash1, hash2) { +function hashJoin(hash1, hash2) { // Good luck! return []; } @@ -239,7 +240,7 @@ const bench2 = [{ friend: 'o8b', num: 8 }, { friend: 'ye', num: 2 }, { friend: ' ```js -function hashJoin (hash1, hash2) { +function hashJoin(hash1, hash2) { const hJoin = (tblA, tblB, strJoin) => { const [jA, jB] = strJoin.split('='); const M = tblB.reduce((a, x) => { diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/heronian-triangles.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/heronian-triangles.english.md index 5ab654789a..762c744509 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/heronian-triangles.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/heronian-triangles.english.md @@ -6,18 +6,21 @@ challengeType: 5 ## Description
-

Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by:

$$A = \sqrt{s(s-a)(s-b)(s-c)},$$

where s is half the perimeter of the triangle; that is,

$$s=\frac{a+b+c}{2}.$$

-

Heronian triangles are triangles whose sides and area are all integers.

-

An example is the triangle with sides 3, 4, 5 whose area is 6 (and whose perimeter is 12).

-

Note that any triangle whose sides are all an integer multiple of 3, 4, 5; such as 6, 8, 10, will also be a Heronian triangle.

Define a Primitive Heronian triangle as a Heronian triangle where the greatest common divisor

-

of all three sides is 1 (unity).

This will exclude, for example, triangle 6, 8, 10.

-Task: -

Implement a function based on Hero's formula that returns the first nth ordered triangles in an array of arrays.

+Hero's formula for the area of a triangle given the length of its three sides a, b, and c is given by: +$A = \sqrt{s(s-a)(s-b)(s-c)},$ +where s is half the perimeter of the triangle; that is, +$s=\frac{a+b+c}{2}.$ +Heronian triangles are triangles whose sides and area are all integers. +An example is the triangle with sides 3, 4, 5 whose area is 6 (and whose perimeter is 12). +Note that any triangle whose sides are all an integer multiple of 3, 4, 5; such as 6, 8, 10, will also be a Heronian triangle. +Define a Primitive Heronian triangle as a Heronian triangle where the greatest common divisor +of all three sides is 1 (unity). +This will exclude, for example, triangle 6, 8, 10.
## Instructions
- +Implement a function based on Hero's formula that returns the first nth ordered triangles in an array of arrays.
## Tests @@ -47,7 +50,7 @@ tests: ```js // noprotect -function heronianTriangle (n) { +function heronianTriangle(n) { // Good luck! return []; @@ -81,7 +84,7 @@ const res = [ ```js // noprotect -function heronianTriangle (n) { +function heronianTriangle(n) { const list = []; const result = []; diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-figure-figure-sequences.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-figure-figure-sequences.english.md index cd686cddd4..b4e5f12440 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-figure-figure-sequences.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-figure-figure-sequences.english.md @@ -6,23 +6,31 @@ challengeType: 5 ## Description
-

These two sequences of positive integers are defined as:

-

$$R(1)=1\ ;\ S(1)=2 \\R(n)=R(n-1)+S(n-1), \quad n>1.$$

-

The sequence $S(n)$ is further defined as the sequence of positive integers not present in $R(n)$.

Sequence $R$ starts:

-

1, 3, 7, 12, 18, ...

-

Sequence $S$ starts:

-

2, 4, 5, 6, 8, ...

-Task: -Create two functions named ffr and ffs that when given n return R(n) or S(n) respectively.(Note that R(1) = 1 and S(1) = 2 to avoid off-by-one errors). -No maximum value for n should be assumed. -Sloane's A005228 and A030124. -Wolfram MathWorld -Wikipedia: Hofstadter Figure-Figure sequences. +These two sequences of positive integers are defined as: +$R(1)=1\ ;\ S(1)=2 \\R(n)=R(n-1)+S(n-1), \quad n>1.$ +The sequence $S(n)$ is further defined as the sequence of positive integers not present in $R(n)$. +Sequence $R$ starts: +
1, 3, 7, 12, 18, ...
+Sequence $S$ starts: +
2, 4, 5, 6, 8, ...
## Instructions
- +Create two functions named ffr and ffs that when given n return R(n) or S(n) respectively. (Note that R(1) = 1 and S(1) = 2 to avoid off-by-one errors). +No maximum value for n should be assumed. +References +
## Tests diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-q-sequence.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-q-sequence.english.md index 4abc695b9a..6f992a001b 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-q-sequence.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/hofstadter-q-sequence.english.md @@ -6,16 +6,14 @@ challengeType: 5 ## Description
-

The Hofstadter Q sequence is defined as:

-

$Q(1)=Q(2)=1, \\ Q(n)=Q\big(n-Q(n-1)\big)+Q\big(n-Q(n-2)), \quad n>2.$

-

It is defined like the Fibonacci sequence, but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.

-Task: -Implement the Hofstadter Q Sequence equation into JavaScript +The Hofstadter Q sequence is defined as: +$Q(1)=Q(2)=1, \\ Q(n)=Q\big(n-Q(n-1)\big)+Q\big(n-Q(n-2)), \quad n>2.$ +It is defined like the Fibonacci sequence, but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
## Instructions
- +Implement the Hofstadter Q Sequence equation as a function. The function should accept number, n, and return an integer.
## Tests @@ -46,7 +44,7 @@ tests:
```js -function hofstadterQ (n) { +function hofstadterQ(n) { // Good luck! return n; }