Public
Edited
Nov 27, 2022
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
wordLists = (await import("https://cdn.skypack.dev/wordle-wordlist@1.0.1c?min"))
.default
Insert cell
likelyWords = new Set(await wordLists.answers())
Insert cell
words = wordLists.all()
Insert cell
Insert cell
normalizedFreqs = {
let freqs = Object.entries(wordFreqs);
let max = d3.max(freqs, (d) => d[1]);
return Object.fromEntries(freqs.map(([word, freq]) => [word, freq / max]));
}
Insert cell
scoreWord = (word) => {
word = word.toLowerCase();
return (likelyWords.has(word) ? 1 : 0) + (normalizedFreqs[word] ?? 0);
}
Insert cell
bestWordsFrom = (list, limit = 4) =>
d3
.sort(list, (w) => -scoreWord(w))
.slice(0, limit)
.map((w) => (likelyWords.has(w) ? w.toUpperCase() : w))
Insert cell
import {invalidationListener} from "@mythmon/bonus-lib@86"
Insert cell
function Square({ value = "grey", className = "", onClick = () => {} } = {}) {
let colorCycle = Object.keys(colorMap);
let output = htl.html`<div class="${className}" style="
width: ${cellSize}px;
height: ${cellSize}px;
display: inline-block;
"></div>`;
output.value = value;

function update(nextValue = output.value) {
if (nextValue !== output.value) {
output.value = nextValue;
output.dispatchEvent(new Event("input", { bubbles: true }));
}
output.style.backgroundColor = colorMap[output.value];
}

invalidationListener(output, "click", invalidation, () => {
let index = colorCycle.indexOf(output.value);
index = (index + 1) % colorCycle.length;
update(colorCycle[index]);
onClick();
});

update();
return output;
}
Insert cell
import { view } from "@tomlarkworthy/view"
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