Public
Edited
Dec 17, 2022
Importers
Insert cell
Insert cell
renderItems(puzzleInput)
Insert cell
renderItems = (inputText) => {
const _width = Math.min(600, width);

const parts = parseInput(inputText);
const n = parts.length;
const dy = 14;

const baseStyle = "font-family: Monospace; fill: #1FA774";
const styleLeft = `text-anchor: end;${baseStyle}`;

const renderLeft = (item) => {
const [partA, partB] = item;
const shared = getSharedItem(partA, partB);
const chars = partA.map((c) =>
c === shared
? svg`<tspan fill="#FF6163" font-weight="bold">${c}</tspan>`
: c
);
return svg`<text x="-5" style="${styleLeft}">${chars}</text>`;
};

const renderRight = (item) => {
const [partA, partB] = item;
const shared = getSharedItem(partA, partB);
const chars = partA.map((c) =>
c === shared
? svg`<tspan fill="#FF6163" font-weight="bold">${c}</tspan>`
: c
);
return svg`<text x="5" style="${baseStyle}">${chars}</text>`;
};

return svg`
<svg width=${_width} height=${n * dy}>
<g transform="translate(${_width / 2}, 0)">
${parts.map(
(item, itemIndex) => svg`
<g transform="translate(0, ${(1 + itemIndex) * dy})">
${renderLeft(item)}
${renderRight(item)}
</g>`
)}
</g>
</svg>
`;
}
Insert cell
Insert cell
prioritySum = _.sum(priorityList)
Insert cell
priorityList = data.map(([a, b]) => getSharedItem(a, b)).map((c) => priority(c))
Insert cell
data = parseInput(puzzleInput)
Insert cell
Insert cell
import { NEWLINE } from "@pnavarrc/advent-of-code-utils"
Insert cell
Insert cell
Insert cell
Insert cell
function priority(char) {
const lower = "abcdefghijklmnopqrstuvwxyz";
const upper = lower.toUpperCase();
const all = `${lower}${upper}`.split("");
return all.findIndex((d) => d === char) + 1;
}
Insert cell
puzzleInput = FileAttachment("2022-03-puzzle-input.txt").text()
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