Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Keys and Locks by SaintDron
"use strict";
function keysAndLocks(lock, some_key) {
const parse = (str) => str.trim().split('\n').map(r => [...r]),
clip = (arr) => arr.filter(row => row.includes('#')),
rotate = (arr) => arr[0].map((_, c) => arr.map(row => row[c]).reverse());
lock = clip(rotate(clip(parse(lock)))); // <- smile
some_key = clip(rotate(clip(parse(some_key))));
for (let i = 0; i < 4; i++) {
if (JSON.stringify(lock) === JSON.stringify(some_key))
return true;
some_key = rotate(some_key);
}
return false;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(keysAndLocks(`
0##0
0##0
00#0
00##
00##`,
`
00000
000##
#####
##000
00000`))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(keysAndLocks(`
0##0
0##0
00#0
00##
00##`,
`
00000
000##
#####
##000
00000`), true)
assert.equal(keysAndLocks(`
###0
00#0`,
`
00000
00000
#0000
###00
0#000
0#000`), false)
assert.equal(keysAndLocks(`
0##0
0#00
0000`,
`
##000
#0000
00000
00000
00000`), true)
assert.equal(keysAndLocks(`
###0
0#00
0000`,
`
##00
##00`), false)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 13, 2018
Comments: