Public
Edited
May 6, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
function hypernets(ip) {
return (ip.match(/\[[^\]]*\]/g) || []).join(" ");
}
Insert cell
Insert cell
function supernets(ip) {
return ip.split(/\[[^\]]*\]/).join(" ");
}
Insert cell
Insert cell
function supportsTls(ip) {
const hasAbba = (str) => /(.)(?!\1)(.)\2\1/.test(str);
return hasAbba(supernets(ip)) && !hasAbba(hypernets(ip));
}
Insert cell
function part1(ips) {
return ips.split("\n").filter(supportsTls).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function findABAs(str) {
const abas = [];
for (let i = 0; i < str.length - 2; i++) {
if (str[i] === str[i + 2] && str[i] !== str[i + 1]) {
abas.push(str.slice(i, i + 3));
}
}
return abas;
}
Insert cell
Insert cell
function supportsSsl(ip) {
const abas = findABAs(supernets(ip));
for (const aba of abas) {
if (hypernets(ip).includes(aba[1] + aba[0] + aba[1])) {
return true;
}
}
return false;
}
Insert cell
function part2(input) {
return input.split("\n").filter(supportsSsl).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more