Skip to content

Instantly share code, notes, and snippets.

@frangucc
Last active December 11, 2015 03:39
Show Gist options
  • Save frangucc/4539550 to your computer and use it in GitHub Desktop.
Save frangucc/4539550 to your computer and use it in GitHub Desktop.
Answer
API is implemented at :
http://ariise.com/api/matrix/min_weigth.json-
- mandatory parameter: matrix.
Matrix is sent to server as string, like: "[[3,1,4],[1,5,9],[2,6,5]]",
"[[3,1,4],[1,5,9],[2,6,5,4,7]]", etc.
Return:
- status: 200: valid call, 205: invalid matrix
- min_path: min weight path, as tring, for example : "[1,1,4]"
- total_paths: total min paths
Example:
curl -X POST 'http://ariise.com/api/matrix/min_weigth.json' -d
'matrix=[[3,1,4],[5,5,9],[2,6,2]]'
Response: {"status":200,"min_path":"[1,5,2]","total_path":4}
curl -X POST 'http://ariise.com/api/matrix/min_weigth.json' -d
'matrix=[[3,1,4],[5,9],[2,6,1]]'
{"status":200,"min_path":"[1,5,1]","total_path":1}
curl -X POST 'http://ariise.com/api/matrix/min_weigth.json' -d
'matrix=[[3,1,4],[5,9, 6],[2,6,1]]'
Response: {"status":200,"min_path":"[1,5,1]","total_path":1}
curl -X POST 'http://ariise.com/api/matrix/min_weigth.json' -d
'matrix=[[3,1,4],[5,9, 6],[a,b]]'
Response: {"status":205,"message":"invalid matrix"}, because the last
row does not content any numeric element.
@datapimp
Copy link

var sample = [[3, 1, 4], [5, 9, 6], [2, 6, 1]];

//using underscore.js
_( sample ).reduce(function(memo,row){
  memo.push( _( row ).min() );
  return memo
}, []);  //=> [1,5,1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment