Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Find Sequence by Sim0000
"use strict";
function sequence(matrix) {
function search(x, y, dx, dy){
const c = matrix[y][x];
for(let i = 0; i < 3; i++){
x += dx;
y += dy;
if(!(0 <= x && x < N && 0 <= y && y < N)) return false;
if(matrix[y][x] != c) return false;
}
return true;
}
const N = matrix.length;
for(let y = 0; y < N; y++){
for(let x = 0; x < N; x++){
if(search(x, y, 0, 1)) return true;
if(search(x, y, 1, 0)) return true;
if(search(x, y, 1, -1)) return true;
if(search(x, y, 1, 1)) return true;
}
}
return false;
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(sequence([
[1, 2, 1, 1],
[1, 1, 4, 1],
[1, 3, 1, 6],
[1, 7, 2, 5]
]), true)
assert.equal(sequence([
[7, 1, 4, 1],
[1, 2, 5, 2],
[3, 4, 1, 3],
[1, 1, 8, 1]
]), false)
assert.equal(sequence([
[2, 1, 1, 6, 1],
[1, 3, 2, 1, 1],
[4, 1, 1, 3, 1],
[5, 5, 5, 5, 5],
[1, 1, 3, 1, 1]
]), true)
assert.equal(sequence([
[7, 1, 1, 8, 1, 1],
[1, 1, 7, 3, 1, 5],
[2, 3, 1, 2, 5, 1],
[1, 1, 1, 5, 1, 4],
[4, 6, 5, 1, 3, 1],
[1, 1, 9, 1, 2, 1]
]), true)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
July 21, 2018