n
where proper divisors are all positive integers n
other than n
itself.
If P(n) < n
then n
is classed as deficient
@@ -16,13 +16,13 @@ If P(n) === n
then n
is classed as perfect
P(n) > n then n
is classed as abundant
Example:
-6 has proper divisors of 1, 2, and 3.
-1 + 2 + 3 = 6, so 6 is classed as a perfect number.
+6
has proper divisors of 1
, 2
, and 3
.
+1 + 2 + 3 = 6
, so 6
is classed as a perfect number.
[deficient, perfect, abundant]
.
+Implement a function that calculates how many of the integers from 1
to 20,000
(inclusive) are in each of the three classes. Output the result as an array in the following format [deficient, perfect, abundant]
.
"Radius Zero"
."Coincident point. Infinite solutions"
."No intersection. Points further apart than circle diameter"
.p1 p2 r 0.1234, 0.9876 0.8765, 0.2345 2.0 diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/closest-pair-problem.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/closest-pair-problem.english.md index 4ee1cbc96c..28803bd2be 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/closest-pair-problem.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/closest-pair-problem.english.md @@ -9,31 +9,31 @@ challengeType: 5 Provide a function to find the closest two points among a set of given points in two dimensions, i.e. to solve the Closest pair of points problem in the planar case. The straightforward solution is a O(n2) algorithm (which we can call brute-force algorithm); the pseudo-code (using indexes) could be simply:-bruteForceClosestPair of P(1), P(2), ... P(N) -if N < 2 then - return ∞ -else +bruteForceClosestPair of P(1), P(2), ... P(N) +if N < 2 then + return ∞ +else minDistance ← |P(1) - P(2)| minPoints ← { P(1), P(2) } - foreach i ∈ [1, N-1] - foreach j ∈ [i+1, N] - if |P(i) - P(j)| < minDistance then + foreach i ∈ [1, N-1] + foreach j ∈ [i+1, N] + if |P(i) - P(j)| < minDistance then minDistance ← |P(i) - P(j)| minPoints ← { P(i), P(j) } - endif - endfor - endfor - return minDistance, minPoints -endif + endif + endfor + endfor + return minDistance, minPoints +endifA better algorithm is based on the recursive divide and conquer approach, as explained also at Wikipedia's Closest pair of points problem, which isO(nlog(n))
a pseudo-code could be:-closestPair of (xP, yP) +closestPair of (xP, yP) where xP is P(1) .. P(N) sorted by x coordinate, and yP is P(1) .. P(N) sorted by y coordinate (ascending order) -if N ≤ 3 then - return closest points of xP using brute-force algorithm -else +if N ≤ 3 then + return closest points of xP using brute-force algorithm +else xL ← points of xP from 1 to ⌈N/2⌉ xR ← points of xP from ⌈N/2⌉+1 to N xm ← xP(⌈N/2⌉)x @@ -42,26 +42,26 @@ A better algorithm is based on the recursive divide and conquer approach, as exp (dL, pairL) ← closestPair of (xL, yL) (dR, pairR) ← closestPair of (xR, yR) (dmin, pairMin) ← (dR, pairR) - if dL < dR then + if dL < dR then (dmin, pairMin) ← (dL, pairL) - endif + endif yS ← { p ∈ yP : |xm - px| < dmin } nS ← number of points in yS (closest, closestPair) ← (dmin, pairMin) - for i from 1 to nS - 1 + for i from 1 to nS - 1 k ← i + 1 - while k ≤ nS and yS(k)y - yS(i)y < dmin - if |yS(k) - yS(i)| < closest then + while k ≤ nS and yS(k)y - yS(i)y < dmin + if |yS(k) - yS(i)| < closest then (closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)}) - endif + endif k ← k + 1 - endwhile - endfor - return closest, closestPair -endif + endwhile + endfor + return closest, closestPair +endifFor the input, expect the argument to be an array of objects (points) withx
andy
members set to numbers. For the output, return an object containing the key:value pairs fordistance
andpair
(the pair of two closest points). -References and further readings: +References and further readings:
m
and n
, generate all size m
combinations of the integers from 0
(zero) to n-1
in sorted order (each combination is sorted and the entire table is sorted).
+Example:
+3
comb 5
is:
0 1 2 0 1 3 diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/comma-quibbling.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/comma-quibbling.english.md index 51e01743c7..33f78c04b5 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/comma-quibbling.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/comma-quibbling.english.md @@ -13,10 +13,10 @@ Comma quibbling is a task originally set by Eric Lippert in his --So 17 multiplied by 34, by the Ethiopian method is 578. +So- An input of just one word, e.g. ["ABC"], produces the output string of the word inside the two braces, e.g. "{ABC}".
-- An input of two words, e.g. ["ABC", "DEF"], produces the output string of the two words inside the two braces with the words separated by the string " and ", e.g. "{ABC and DEF}".
-- An input of three or more words, e.g. ["ABC", "DEF", "G", "H"], produces the output string of all but the last word separated by ", " with the last word separated by " and " and all within braces; e.g. "{ABC, DEF, G and H}".
+- An input of no words produces the output string of just the two brace characters (
+"{}"
)- An input of just one word, e.g.
+["ABC"]
, produces the output string of the word inside the two braces, e.g."{ABC}"
- An input of two words, e.g.
+["ABC", "DEF"]
, produces the output string of the two words inside the two braces with the words separated by the string" and "
, e.g."{ABC and DEF}"
- An input of three or more words, e.g.
Test your function with the following series of inputs showing your output here on this page:["ABC", "DEF", "G", "H"]
, produces the output string of all but the last word separated by", "
with the last word separated by" and "
and all within braces; e.g."{ABC, DEF, G and H}"
diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/convert-seconds-to-compound-duration.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/convert-seconds-to-compound-duration.english.md index 884989ae4b..416d040e6b 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/convert-seconds-to-compound-duration.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/convert-seconds-to-compound-duration.english.md @@ -33,7 +33,7 @@ Demonstrate that it passes the following three test-cases: | second |
sec
| --- |- - However, only include quantities with non-zero values in the output (e.g., return
1 d
and not0 wk, 1 d, 0 hr, 0 min, 0 sec
). + However, only include quantities with non-zero values in the output (e.g., return1 d
and not0 wk, 1 d, 0 hr, 0 min, 0 sec
).- Give larger units precedence over smaller ones as much as possible (e.g., return
2 min, 10 sec
and not1 min, 70 sec
or130 sec
). diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/date-format.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/date-format.english.md index 7342b8a7ba..3e6be9f116 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/date-format.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/date-format.english.md @@ -8,8 +8,8 @@ challengeType: 5Return an array with the current date in the formats: diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/deal-cards-for-freecell.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/deal-cards-for-freecell.english.md index fbfd06246d..bb7cb79db2 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/deal-cards-for-freecell.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/deal-cards-for-freecell.english.md @@ -27,8 +27,8 @@ The algorithm follows:-
Example output:- 2007-11-23 and
-- Sunday, November 23, 2007
+- 2007-11-23
+- Sunday, November 23, 2007
['2007-11-23', 'Sunday, November 23, 2007']
- Deal all 52 cards, face up, across 8 columns. The first 8 cards go in 8 columns, the next 8 cards go on the first 8 cards, and so on.
-Example: -Order to deal cards +Example: +Order to deal cards1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 @@ -36,7 +36,7 @@ The algorithm follows: 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52-Game #1 +Game #1 ```js [ @@ -49,7 +49,7 @@ The algorithm follows: ['6S', '9C', '2H', '6H'] ] ``` -Game #617 +Game #617 ```js [ diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md index 65de08bbd8..b23dc9943f 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/element-wise-operations.english.md @@ -7,7 +7,7 @@ challengeType: 5 ## DescriptionImplement basic element-wise matrix-matrix and scalar-matrix operations. -Implement: +Implement: ## Instructions diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md index 2341674379..fa4153a382 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/ethiopian-multiplication.english.md @@ -7,15 +7,15 @@ challengeType: 5 ## Description-3 is an equilibrium index, because: +
- addition
- subtraction
diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md index e792797255..9e5557d563 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/emirp-primes.english.md @@ -6,19 +6,19 @@ challengeType: 5 ## Description-An emirp (prime spelled backwards) are primes that when reversed (in their decimal representation) are a different prime. +An emirp (prime spelled backwards) are primes that when reversed (in their decimal representation) are a different prime. ## InstructionsWrite a function that: ## Tests diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md index c27caf1d1b..47ce45bd78 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/equilibrium-index.english.md @@ -17,16 +17,16 @@ For example, in a sequence $A$:-
-The function should accept two parameters. The first will receive n or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or the nth prime). According to the parameters the function should return an array or a number. +The function should accept two parameters. The first will receive- Shows the first n emirp numbers.
+- Shows the first
n
emirp numbers.- Shows the emirp numbers in a range.
- Shows the number of emirps in a range.
-- Shows the nth emirp number.
+- Shows the
nth
emirp number.n
or the range as an array. The second will receive a boolean, that specifies if the function returns the emirps as an array or a single number (the number of primes in the range or thenth
prime). According to the parameters the function should return an array or a number.- $A_5 = 3$
- $A_6 = 0$
3
is an equilibrium index, because:-6 is also an equilibrium index, because: +
- $A_0 + A_1 + A_2 = A_4 + A_5 + A_6$
6
is also an equilibrium index, because:(sum of zero elements is zero) -7 is not an equilibrium index, because it is not a valid index of sequence $A$. +
- $A_0 + A_1 + A_2 + A_3 + A_4 + A_5 = 0$
7
is not an equilibrium index, because it is not a valid index of sequence $A$.Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving. -Method: +Method: -
-For example: 17 × 34 +For example:- Take two numbers to be multiplied and write them down at the top of two columns.
-- In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of 1.
-- In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows 1.
-- Examine the table produced and discard any row where the value in the left column is even.
+- Take two numbers to be multiplied and write them down at the top of two columns
+- In the left-hand column repeatedly halve the last number, discarding any remainders, and write the result below the last in the same column, until you write a value of
+1
- In the right-hand column repeatedly double the last number and write the result below. stop when you add a result in the same row as where the left hand column shows
+1
- Examine the table produced and discard any row where the value in the left column is even
- Sum the values in the right-hand column that remain to produce the result of multiplying the original two numbers together
17 × 34
17 34@@ -53,7 +53,7 @@ Sum the remaining numbers in the right-hand column: ==== 578
17
multiplied by 34
, by the Ethiopian method is 578
.
2 s
5 s
and10 s
100 °C
20 °C
0.07
0 s
to 100 s
.
(period) present before the [replacement], then this is a terminating rule in which case the interpreter must halt execution.
A ruleset consists of a sequence of rules, with optional comments.
Rulesets
Use the following tests on entries:
-Ruleset 1:
+Ruleset 1:
# This rules file is extracted from Wikipedia: # http://en.wikipedia.org/wiki/Markov_Algorithm @@ -34,7 +34,7 @@ Sample text of:I bought a B of As from T S.
Should generate the output:I bought a bag of apples from my brother.
-Ruleset 2: +Ruleset 2: A test of the terminating rule# Slightly modified from the rules on Wikipedia @@ -49,7 +49,7 @@ Sample text of:I bought a B of As from T S.
Should generate:I bought a bag of apples from T shop.
-Ruleset 3: +Ruleset 3: This tests for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped.#BNF Syntax testing rules @@ -68,7 +68,7 @@ Sample text of:I bought a B of As W my Bgage from T S.
Should generate:I bought a bag of apples with my money from T shop.
-Ruleset 4: +Ruleset 4: This tests for correct order of scanning of rules, and may trap replacement routines that scan in the wrong order. It implements a general unary multiplication engine. (Note that the input expression must be placed within underscores in this implementation.)### Unary Multiplication Engine, for testing Markov Algorithm implementations @@ -101,9 +101,9 @@ Sample text of:_1111*11111_
should generate the output:11111111111111111111
-Ruleset 5: -A simple Turing machine, -implementing a three-state busy beaver.The tape consists of 0s and 1s, the states are A, B, C and H (for Halt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input. +Ruleset 5: +A simple Turing machine, implementing a three-state busy beaver. +The tape consists of0
s and1
s, the states areA
,B
,C
andH
(forH
alt), and the head position is indicated by writing the state letter before the character where the head is. All parts of the initial tape the machine operates on have to be given in the input. Besides demonstrating that the Markov algorithm is Turing-complete, it also made me catch a bug in the C++ implementation which wasn't caught by the first four rulesets.#Turing machine: three-state busy beaver diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md index 723a27149c..e4f5cc7909 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/extensible-prime-generator.english.md @@ -9,12 +9,12 @@ challengeType: 5 Write a generator of prime numbers, in order, that will automatically adjust to accommodate the generation of any reasonably high prime. The generator should be able to:
n
prime numbersnth
prime numbern
or the range as an array. The second will receive a boolean, that specifies if the function returns the prime numbers as an array or a single number(the number of primes in the range or the nth
prime). According to the parameters the function should return an array.
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24
0! = 1
## Instructions
diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md
index ed5d361855..28653716a0 100644
--- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md
+++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/factors-of-a-mersenne-number.english.md
@@ -6,17 +6,16 @@ challengeType: 5
## Description
2P-1
.
+If P
is prime, the Mersenne number may be a Mersenne prime. (If P
is not prime, the Mersenne number is also not prime.)
In the search for Mersenne prime numbers it is advantageous to eliminate exponents by finding a small factor before starting a, potentially lengthy, Lucas-Lehmer test.
-There are very efficient algorithms for determining if a number divides 2P-1 (or equivalently, if 2P mod (the number) = 1).
+There are very efficient algorithms for determining if a number divides 2P-1
(or equivalently, if 2P mod (the number) = 1
).
Some languages already have built-in implementations of this exponent-and-mod operation (called modPow or similar).
The following is how to implement this modPow yourself:
-For example, let's compute 223 mod 47.
-Convert the exponent 23 to binary, you get 10111. Starting with square = 1, repeatedly square it.
-Remove the top bit of the exponent, and if it's 1 multiply square by the base of the exponentiation (2), then compute square modulo 47.
-Use the result of the modulo from the last step as the initial value of square in the next step:
+For example, let's compute 223 mod 47
.
+Convert the exponent 23 to binary, you get 10111. Starting with square = 1
, repeatedly square it.
+Remove the top bit of the exponent, and if it's 1 multiply square
by the base of the exponentiation (2), then compute square modulo 47
.
+Use the result of the modulo from the last step as the initial value of square
in the next step:
Remove Optional square top bit multiply by 2 mod 47 @@ -27,18 +26,18 @@ square top bit multiply by 2 mod 47 32*32 = 1024 1 1 1024*2 = 2048 27 27*27 = 729 1 729*2 = 1458 1-Since 223 mod 47 = 1, 47 is a factor of 2P-1. -(To see this, subtract 1 from both sides: 223-1 = 0 mod 47.) -Since we've shown that 47 is a factor, 223-1 is not prime. +Since
223 mod 47 = 1
, 47 is a factor of 2P-1
.
+(To see this, subtract 1 from both sides: 223-1 = 0 mod 47
.)
+Since we've shown that 47 is a factor, 223-1
is not prime.
Further properties of Mersenne numbers allow us to refine the process even more.
-Any factor q of 2P-1 must be of the form 2kP+1, k being a positive integer or zero. Furthermore, q must be 1 or 7 mod 8.
-Finally any potential factor q must be prime.
-As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N).These primality tests only work on Mersenne numbers where P is prime. For example, M4=15 yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1.
+Any factor q
of 2P-1
must be of the form 2kP+1
, k
being a positive integer or zero. Furthermore, q
must be 1
or 7 mod 8
.
+Finally any potential factor q
must be prime.
+As in other trial division algorithms, the algorithm stops when 2kP+1 > sqrt(N)
.These primarily tests only work on Mersenne numbers where P
is prime. For example, M4=15
yields no factors using these techniques, but factors into 3 and 5, neither of which fit 2kP+1
.
2929-1
(aka M929)
Fn
of order n
is the sequence of completely reduced fractions between 0
and 1
which, when in lowest terms, have denominators less than or equal to n
, arranged in order of increasing size.
The Farey sequence is sometimes incorrectly called a Farey series.
Each Farey sequence:
1
to 5
are:
n
. The function should have one parameter that is n
. It should return the sequence as an array.
"l"
, then return the Lucas sequence. The sequences must be returned as an array.
nth
Fibonacci number.
+The nth
Fibonacci number is given by:
+Fn = Fn-1 + Fn-2
+The first two terms of the series are 0 and 1.
Hence, the series is: 0, 1, 1, 2, 3, 5, 8, 13...
-Define F_Word1 as 1 -Define F_Word2 as 0 -Form F_Word3 as F_Word2 concatenated with F_Word1 i.e.: 01 +Define F_Word1 as 1 +Define F_Word2 as 0 +Form F_Word3 as F_Word2 concatenated with F_Word1 i.e.: 01 Form F_Wordn as F_Wordn-1 concatenated with F_wordn-2
{ N: 1, Length: 1, Entropy: 0, Word: '1' }
.
+Write a function to return the Fibonacci Words up to n
. n
will be provided as a parameter to the function. The function should return an array of objects. The objects should be of the form: { N: 1, Length: 1, Entropy: 0, Word: '1' }
.
fibWord
is a function.
- testString: assert(typeof fibWord === 'function', 'fibWord
is a function.');
+ testString: assert(typeof fibWord === 'function');
- text: fibWord(5)
should return an array.
- testString: assert(Array.isArray(fibWord(5)),'fibWord(5)
should return an array.');
- - text: fibWord(5)
should return '+JSON.stringify(ans)+'
.
- testString: assert.deepEqual(fibWord(5),ans,'fibWord(5)
should return '+JSON.stringify(ans)+'
.');
+ testString: assert(Array.isArray(fibWord(5)));
+ - text: fibWord(5)
should return [{ N:1, Length:1, Entropy:0, Word:"1" },{ N:2, Length:1, Entropy:0, Word:"0" },{ N:3, Length:2, Entropy:1, Word:"01" },{ N:4, Length:3, Entropy:0.9182958340544896, Word:"010" },{ N:5, Length:5, Entropy:0.9709505944546688, Word:"01001" }]
.
+ testString: assert.deepEqual(fibWord(5),ans);
```
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 42bbc524e0..b987b4f312 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,11 +6,11 @@ challengeType: 5
## Description
n
by:
= n/2
= (3 * n) + 1
n
is 1
then the sequence endsn
is even
then the next n
of the sequence = n/2
n
is odd
then the next n
of the sequence = (3 * n) + 1
27, 82, 41, 124
and ending with 8, 4, 2, 1
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.
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.
-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
@@ -114,7 +114,7 @@ Implement the "hash join" algorithm as a function and demonstrate that it passes |
A_age | 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 7b8bd6e2b8..c0fc662a6d 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 @@ -11,11 +11,11 @@ challengeType: 5 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. +An example is the triangle with sides
---|
P9 | P2 | P3 |
P8 | P1 | P4 |
P8 | P1 | P4 |
P7 | P6 | P5 |