Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Einzeiler [ES6] solution in Creative category for [old] Break Rings by vincent.tscherter
"use strict";
function breakRings(a) {
return !a.length ? 0 : Math.min(...[0,1].map(i => breakRings(a.filter(x => x[0] != a[0][i] && x[1] != a[0][i])))) + 1;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(breakRings([[1,2],[2,3],[3,4],[4,5],[5,2],[1,6],[6,7],[7,8],[8,9],[9,6],[1,10],[10,11],[11,12],[12,13],[13,10],[1,14],[14,15],[15,16],[16,17],[17,14]]),8,'extra2');
assert.equal(breakRings([[3,4],[5,6],[2,7],[1,5],[2,6],[8,4],[1,7],[4,5],[9,5],[2,3],[8,2],[2,4],[9,6],[5,7],[3,6],[1,3]]),5,'extra');
assert.equal(breakRings([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [4, 6]]), 3, "Example");
assert.equal(breakRings([[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]), 3, "All to all");
assert.equal(breakRings([[5, 6], [4, 5], [3, 4], [3, 2], [2, 1], [1, 6]]), 3, "Chain");
assert.equal(breakRings([[8, 9], [1, 9], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [8, 7]]), 5, "Long chain");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Nov. 12, 2016
Comments: