Skip to content

Instantly share code, notes, and snippets.

@dcdunkan
Last active February 8, 2024 07:15
Show Gist options
  • Save dcdunkan/f98cac20c0cc400d9eb4d859218e17cc to your computer and use it in GitHub Desktop.
Save dcdunkan/f98cac20c0cc400d9eb4d859218e17cc to your computer and use it in GitHub Desktop.
Resolve Telegram's slot machine dice value (from tdesktop source)
const e = ["🔤", "🫐", "🍋", "7️⃣"];
function computePartValue(value: number, partIndex: number) {
return ((value - 1) >> (partIndex * 2)) & 0x03; // 0..3
}
function resolve(value: number) {
if (value <= 0 && value > 64) return;
let text = `${value}:`;
for (let i = 0; i < 3; i++) text += ` e[computePartValue(value, i)]`;
console.log(text);
}
const input = Deno.args[0];
if (!input) {
console.log("No arguments.");
} else if (isNaN(Number(input))) {
console.log("Not a number!");
} else {
resolve(Number(Deno.args[0]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment