Skip to content

Commit

Permalink
Readme updated, Siege exercise continued
Browse files Browse the repository at this point in the history
  • Loading branch information
Granjow committed Oct 22, 2015
1 parent c62c1ab commit afa3afb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ to solve various types of problems. More exercises will be added. Current progre
Reading Problems ————————————·—————————————————·————————————————————O
Read large graphs from files.

Under Siege —————————————————·
Help the city ABC, which is under siege, to defend itself with your
new knowledge!


Under Siege —————————————————·————————————
Help the city Bohandur, which is under siege, to defend itself
with your new knowledge!


## Feedback

I’m very interested in reading your feedback to the exercises, like:

* Did you miss some information which would have been required for solving the exercise?
* Was an exercise too hard?
* Did the verification fail, or was the master solution wrong?
* Did you like it?

Please feel free to open a thread (issue) in the [GitHub Issue Tracker](https://github.com/Granjow/graphs-with-javascript/issues)
and drop some lines of text or code, so this tutorial can be further improved. Thank you!
49 changes: 36 additions & 13 deletions exercises/ex3-siege/problem-siege.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Under Siege

ABC is under siege. Its troops are very powerful, but limited in their number, so they can only be
present in one city at the same time.
The villages of Bohandur are under siege. Its troops are very powerful, but limited in their number, so they can only be
present in one village at the same time to defend their happy citizens.

Intelligence has provided us with a list of cities and attacking troops. Your task is to hand us
a list of cities with the largest number of attackers. The list has to be ready yesterday, so better
Expand All @@ -11,20 +11,43 @@ hurry up!

## Input format

Cities and attackers have no IDs in common. You will be provided three arrays. Return an array of cities.
Those invaluable lists use the following format:

var cities = [ 1, 2, 3 ];
var attackers = [ 4, 5, 7, 11 ];
var troops = [ [4,1], [5,1], [7,2] ];

// Expected output: [ 1 ]
3 4 3
1
2
3
4
5
7
11
4 1
5 1
7 2

They provide a list of `V` villages, `A` attackers, and `S` sieges. In the first line, you can find those numbers:

V A S

The next `V` lines are village IDs, then we have `A` attacker IDs, and finally a list of `S` sieges which say
which troop is attacking which village. Note that villages and attackers have no IDs in common.

Your exports should look like this:
## Task

var mostAttackers = function( cities, attackers, troops ) {
// Your Code
return solution;
};
Write a function which returns the city (or cities) with the highest number of attackers. Use the following template:

function mostAttackers( inputFilePath, callback ) {
// Your code here
// Once you have calculated your solution, call the callback:
callback( yourSolution );
}

module.exports = mostAttackers;

It should support code of the following form:

mostAttackers( 'sample1.in', function( defendThoseFirst ) {
console.log( 'We have to defend those villages first:', defendThoseFirst );
} );

You will be provided some sample input files so you can test your code.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"type": "git",
"url": "[email protected]:Granjow/graphs-with-javascript.git"
},
"description": "Small tutorial on using graph algorithms",
"description": "Small tutorial on using graph algorithms (after writing them :) )",
"main": "runner.js",
"dependencies": {
"adventure": "^2.11.0",
Expand Down

0 comments on commit afa3afb

Please sign in to comment.