Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
🎶 Schaffe schaffe, Häusle baue 🏡 solution in Clear category for [old] Ground for the House by vincent.tscherter
"use strict";
function house(plan) {
if (!plan.match(/#/)) return 0;
plan = plan.trim().split('\n');
let w, n, e, s; // west, north, east, south
let f = plan.filter( a => a.indexOf('#')>=0);
w = f.reduce((a,c) => Math.min(a, c.indexOf("#")), Number.MAX_SAFE_INTEGER);
e = f.reduce((a,c) => Math.max(a, c.lastIndexOf("#")), 0);
f = plan.map( a=> a.indexOf('#')>=0);
n = f.indexOf(true);
s = f.lastIndexOf(true);
return (1+e-w)*(1+s-n);
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(house(`
0000000
##00##0
######0
##00##0
#0000#0
`))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(house(`
0000000
##00##0
######0
##00##0
#0000#0
`), 24)
assert.equal(house(`0000000000
#000##000#
##########
##000000##
0000000000
`), 30)
assert.equal(house(`0000
0000
#000
`), 1)
assert.equal(house(`0000
0000
`), 0)
assert.equal(house(`0##0
0000
#00#
`), 12)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 5, 2018
Comments: