From 80b736b826cb0c2ad6ff0370b4418129e8db9009 Mon Sep 17 00:00:00 2001 From: gikf <60067306+gikf@users.noreply.github.com> Date: Mon, 14 Jun 2021 08:31:51 +0200 Subject: [PATCH] fix(curriculum): improve description and tests descriptions (#42408) * fix: add input and output to tests descriptions * fix: remove results from background code * fix: clarify input and output of function * fix: corrections from review Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> --- .../rosetta-code/topological-sort.md | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/topological-sort.md b/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/topological-sort.md index c1acebe3a07..f57d218e66c 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/topological-sort.md +++ b/curriculum/challenges/english/10-coding-interview-prep/rosetta-code/topological-sort.md @@ -8,19 +8,19 @@ dashedName: topological-sort # --description-- -Given a mapping between items, and items they depend on, a [topological sort]( "wp: Topological sorting") orders items so that no item precedes an item it depends upon. The compiling of a library in the [VHDL](https://en.wikipedia.org/wiki/VHDL "wp: VHDL") language has the constraint that a library must be compiled after any library it depends on. +Given a mapping between items, and items they depend on, a topological sort orders items so that no item precedes an item it depends upon. There are two popular algorithms for topological sorting: Kahn's (1962) topological sort and depth-first search. # --instructions-- -Write a function that will return a valid compile order of VHDL libraries from their dependencies. +Write a function that will return a list with valid compile order of libraries from their dependencies. + +- Assume library names are single words. +- Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given. +- Any self dependencies should be ignored. +- Any un-orderable dependencies should be ignored. - Use the following data as an example: +
 LIBRARY          LIBRARY DEPENDENCIES
 =======          ====================
@@ -38,16 +38,18 @@ ramlib           std ieee
 std_cell_lib     ieee std_cell_lib
 synopsys
 
-Note: the above data would be un-orderable if, for example, dw04 is added to the list of dependencies of dw01. -C.f.: - -There are two popular algorithms for topological sorting: - + +The compiling of a library in the VHDL language has the constraint that a library must be compiled after any library it depends on. The above data would be un-orderable if, for example, `dw04` is added to the list of dependencies of `dw01`. + +The input of the function will be a multiline string, each line will consist of the name of the library, followed by its dependencies (if exist). + +For example: + +```js +const libsSimple = + `aaa bbb + bbb`; +``` # --hints-- @@ -57,28 +59,34 @@ There are two popular algorithms for topological sorting: assert(typeof topologicalSort === 'function'); ``` -`topologicalSort` should return correct library order. +`topologicalSort(libsSimple)` should return an array. + +```js +assert(Array.isArray(topologicalSort(libsSimple))); +``` + +`topologicalSort(libsSimple)` should return `['bbb', 'aaa']`. ```js assert.deepEqual(topologicalSort(libsSimple), ['bbb', 'aaa']); ``` -`topologicalSort` should return correct library order. +`topologicalSort(libsVHDL)` should return `['ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', 'dw03', 'des_system_lib']`. ```js -assert.deepEqual(topologicalSort(libsVHDL), solutionVHDL); +assert.deepEqual(topologicalSort(libsVHDL), ['ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', 'dw03', 'des_system_lib']); ``` -`topologicalSort` should return correct library order. +`topologicalSort(libsCustom)` should return `['base', 'c', 'd', 'b', 'a']`. ```js -assert.deepEqual(topologicalSort(libsCustom), solutionCustom); +assert.deepEqual(topologicalSort(libsCustom), ['base', 'c', 'd', 'b', 'a']); ``` `topologicalSort` should ignore unorderable dependencies. ```js -assert.deepEqual(topologicalSort(libsUnorderable), solutionUnorderable); +assert.deepEqual(topologicalSort(libsUnorderable), ['Base']); ``` # --seed-- @@ -105,26 +113,17 @@ const libsVHDL = std_cell_lib ieee std_cell_lib synopsys`; -const solutionVHDL = [ - 'ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06', - 'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys', - 'dw03', 'des_system_lib' -]; - const libsCustom = `a b c d b c d d c c base base`; -const solutionCustom = ['base', 'c', 'd', 'b', 'a']; const libsUnorderable = `TestLib Base MainLib MainLib TestLib Base`; - -const solutionUnorderable = ['Base']; ``` ## --seed-contents--