diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/s-expressions.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/s-expressions.english.md index f8cca3d3ac..7c2d40306d 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/s-expressions.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/s-expressions.english.md @@ -6,50 +6,24 @@ challengeType: 5 ## Description
-

-S-Expressions are one convenient way to parse and store data. -

-Task: -

- Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats. -

-

-The function should read a single but nested S-Expression from a string and -return it as a (nested) array. -

-

- Newlines and other whitespace may be ignored unless contained within a quoted string. -

-

()” inside quoted strings are not interpreted, but treated as part of the string. -

-

-Handling escaped quotes inside a string is optional; thus “(foo"bar)” maybe treated as a string “foo"bar”, or as an error. -

-

-For this, the reader need not recognize “\” for escaping, but should, in addition, recognize numbers if the language has appropriate datatypes. -

-

-Note that with the exception of “()"” (“\” if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes. -

-

The reader should be able to read the following input

-

-

-    ((data "quoted data" 123 4.5)
-    (data (!@# (4.5) "(more" "data)")))
-
-

-

-and turn it into a native datastructure. (see the -Pike, -Python and -Ruby implementations -for examples of native data structures.) -

+S-Expressions are one convenient way to parse and store data.
## Instructions
- +Write a simple reader/parser for S-Expressions that handles quoted and unquoted strings, integers and floats. +The function should read a single but nested S-Expression from a string and return it as a (nested) array. +Newlines and other whitespace may be ignored unless contained within a quoted string. +“()” inside quoted strings are not interpreted, but treated as part of the string. +Handling escaped quotes inside a string is optional; thus “(foo"bar)” maybe treated as a string “foo"bar”, or as an error. +For this, the reader need not recognize “\” for escaping, but should, in addition, recognize numbers if the language has appropriate datatypes. +Note that with the exception of “()"” (“\” if escaping is supported) and whitespace there are no special characters. Anything else is allowed without quotes. +The reader should be able to read the following input +
+((data "quoted data" 123 4.5)
+(data (!@# (4.5) "(more" "data)")))
+
+and turn it into a native datastructure. (see the Pike, Python and Ruby implementations for examples of native data structures.)
## Tests diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sailors-coconuts-and-a-monkey-problem.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sailors-coconuts-and-a-monkey-problem.english.md index fc3245833a..26d40e3aa7 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sailors-coconuts-and-a-monkey-problem.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sailors-coconuts-and-a-monkey-problem.english.md @@ -6,69 +6,22 @@ challengeType: 5 ## Description
-

- Five sailors are shipwrecked on an island and - collect a large pile of coconuts during the day. -

-

That night the first sailor wakes up and decides - to take his first share early so tries to divide the pile of coconuts equally - into five piles but finds that there is one coconut left over, so he tosses it - to a monkey and then hides "his" one of the five equally sized piles of - coconuts and pushes the other four piles together to form a single visible pile - of coconuts again and goes to bed. -

-

- To cut a long story short, each of the sailors in - turn gets up once during the night and performs the same actions of dividing - the coconut pile into five, finding that one coconut is left over and giving - that single remainder coconut to the monkey. -

-

- In the morning (after the surreptitious and - separate action of each of the five sailors during the night), the remaining - coconuts are divided into five equal piles for each of the sailors, whereupon - it is found that the pile of coconuts divides equally amongst the sailors with - no remainder. (Nothing for the monkey in the morning.) -

- - The task: - - - Create a function that returns the - the minimum possible size - of the initial pile of coconuts collected during the day for N - sailors. - - - Note: - - - Of course the tale is told in a - world where the collection of any amount of coconuts in a day and multiple - divisions of the pile, etc can occur in time fitting the story line, so as - not to affect the mathematics. - - - - C.f: - - - Monkeys and Coconuts - Numberphile (Video) Analytical solution. - - - A002021 Pile of coconuts problem The On-Line - Encyclopedia of Integer Sequences. (Although some of its references may use - the alternate form of the tale). - - - +Five sailors are shipwrecked on an island and collect a large pile of coconuts during the day. +That night the first sailor wakes up and decides to take his first share early so tries to divide the pile of coconuts equally into five piles but finds that there is one coconut left over, so he tosses it to a monkey and then hides "his" one of the five equally sized piles of coconuts and pushes the other four piles together to form a single visible pile of coconuts again and goes to bed. +To cut a long story short, each of the sailors in turn gets up once during the night and performs the same actions of dividing the coconut pile into five, finding that one coconut is left over and giving that single remainder coconut to the monkey. +In the morning (after the surreptitious and separate action of each of the five sailors during the night), the remaining coconuts are divided into five equal piles for each of the sailors, whereupon it is found that the pile of coconuts divides equally amongst the sailors with no remainder. (Nothing for the monkey in the morning.)
## Instructions
- +Create a function that returns the minimum possible size of the initial pile of coconuts collected during the day for N sailors. +Note: +Of course the tale is told in a world where the collection of any amount of coconuts in a day and multiple divisions of the pile, etc. can occur in time fitting the story line, so as not to affect the mathematics. +C.f: +
## Tests diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sedols.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sedols.english.md index 3e7faedc52..f51dbf2690 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sedols.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sedols.english.md @@ -6,38 +6,22 @@ challengeType: 5 ## Description
- Task: - -

- For each number list of 6-digit - SEDOLs, - calculate and append the checksum digit. -

- -

- That is, given the input string on the left, your function should return the - corresponding string on the right: -

- -
-     710889 => 7108899
-     B0YBKJ => B0YBKJ7
-     406566 => 4065663
-     B0YBLH => B0YBLH2
-     228276 => 2282765
-     B0YBKL => B0YBKL9
-     557910 => 5579107
-     B0YBKR => B0YBKR5
-     585284 => 5852842
-     B0YBKT => B0YBKT7
-     B00030 => B000300
-    
- -

- Check also that each input is correctly formed, especially - with respect to valid characters allowed in a SEDOL string. Your function - should return null on invalid input. -

+For each number list of 6-digit SEDOLs, calculate and append the checksum digit. +That is, given the input string on the left, your function should return the corresponding string on the right: +
+710889 => 7108899
+B0YBKJ => B0YBKJ7
+406566 => 4065663
+B0YBLH => B0YBLH2
+228276 => 2282765
+B0YBKL => B0YBKL9
+557910 => 5579107
+B0YBKR => B0YBKR5
+585284 => 5852842
+B0YBKT => B0YBKT7
+B00030 => B000300
+
+Check that each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string. Your function should return null on an invalid input.
## Instructions @@ -71,7 +55,7 @@ tests:
```js -function sedol (input) { +function sedol(input) { // Good luck! return true; } diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-an-array-of-composite-structures.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-an-array-of-composite-structures.md index 7e02278220..1c46ae9b0a 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-an-array-of-composite-structures.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-an-array-of-composite-structures.md @@ -40,7 +40,7 @@ tests:
```js -function sortByKey (arr) { +function sortByKey(arr) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-disjoint-sublist.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-disjoint-sublist.md index 8d0a40dd65..d193a22be5 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-disjoint-sublist.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-disjoint-sublist.md @@ -47,7 +47,7 @@ tests:
```js -function sortDisjoint (values, indices) { +function sortDisjoint(values, indices) { // Good luck! } ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-stability.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-stability.md index 106e8474d9..a096b3129a 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-stability.md +++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sort-stability.md @@ -6,20 +6,22 @@ challengeType: 5 ## Description
-When sorting records in a table by a particular column or field, a stable sort will always retain the relative order of records that have the same key. +When sorting records in a table by a particular column or field, a stable sort will always retain the relative order of records that have the same key. For example, in this table of countries and cities, a stable sort on the second column, the cities, would keep the US Birmingham above the UK Birmingham. (Although an unstable sort might, in this case, place the US Birmingham above the UK Birmingham, a stable sort routine would guarantee it). -
UK  London
+
+UK  London
 US  New York
 US  Birmingham
-UK  Birmingham
+UK Birmingham +
Similarly, stable sorting on just the first column would generate “UK London” as the first item and “US Birmingham” as the last item (since the order of the elements having the same first word – “UK” or “US” – would be maintained). -Write a function that takes a 2D array as a parameter. Each element has 2 elements similar to the above example. The function should sort the array as mentioned previously and return the sorted array.
## Instructions
- +Write a function that takes a 2D array as a parameter. Each element has 2 elements similar to the above example. The function should sort the array as mentioned previously and return the sorted array.
+ ## Tests
@@ -27,8 +29,8 @@ Write a function that takes a 2D array as a parameter. Each element has 2 elemen tests: - text: stableSort should be a function. testString: assert(typeof stableSort == 'function', 'stableSort should be a function.'); - - text: stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return a array. - testString: assert(Array.isArray(stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])), 'stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return a array.'); + - text: stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return an array. + testString: assert(Array.isArray(stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]])), 'stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return an array.'); - text: stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return [["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]]. testString: assert.deepEqual(stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]), [["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]], 'stableSort([["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"]]) should return [["US", "Birmingham"], ["UK", "Birmingham"], ["UK", "London"], ["US", "New York"]].'); - text: stableSort([[2, 2], [1, 2], [1, 4], [1, 5]]) should return [[2, 2], [1, 2], [1, 4], [1, 5]]. @@ -48,7 +50,7 @@ tests:
```js -function stableSort (arr) { +function stableSort(arr) { // Good luck! } ```