Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- var matrix = [];
- var seqLength = Number(arr[arr.length - 1]);
- for (var i = 0; i < arr.length - 1; i++) {
- var obj = arr[i].split(' ');
- matrix.push(obj);
- }
- var merged = [].concat.apply([], matrix);
- for (var i = 0; i < merged.length; i++) {
- var repeats = 1;
- for (var j = i + 1; j < i + seqLength; j++) {
- if (merged[i] === merged[j]) {
- repeats++;
- }
- }
- if (repeats === seqLength) {
- for (var j = i; j < i + seqLength; j++) {
- merged[j] = 'removed';
- }
- }
- }
- for (var i = 0; i < matrix.length; i++) {
- var row = merged.splice(0, matrix[i].length).filter(function (x) {
- return x !== 'removed';
- });
- if (row.length) {
- console.log(row.join(' '));
- }
- else {
- console.log('(empty)');
- }
- }
- }
- var arr = [ '3 3 3 2 5 9 9 9 9 1 2',
- '1 1 1 1 1 2 5 8 1 1 7',
- '7 7 1 2 3 5 7 4 4 1 2',
- '2' ];
- arr = [ '1 2 3 3', '3 5 7 8', '3 2 2 1', '3' ];
- arr = [ '2 1 1 1', '1 1 1', '3 7 3 3 1', '2' ];
- arr = [ '1 2 3 3 2 1', '5 2 2 1 1 0', '3 3 1 3 3', '2' ];
- solve(arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement