Skip to content

Instantly share code, notes, and snippets.

@scheibo
Last active October 9, 2024 04:02
Show Gist options
  • Save scheibo/d686767684d531d7d39501905ddbcf34 to your computer and use it in GitHub Desktop.
Save scheibo/d686767684d531d7d39501905ddbcf34 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1" name="viewport">
<link rel="shortcut icon" href="data:image/svg+xml,%3C%3Fxml version='1.0' standalone='no'%3F%3E%3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'%3E%3Csvg version='1.0' xmlns='http://www.w3.org/2000/svg' width='512.000000pt' height='512.000000pt' viewBox='0 0 512.000000 512.000000' preserveAspectRatio='xMidYMid meet'%3E%3Cg transform='translate(0.000000,512.000000) scale(0.100000,-0.100000)'%0Afill='%23000000' stroke='none'%3E%3Cpath d='M2096 3515 c-439 -660 -457 -685 -479 -674 -12 7 -69 41 -126 76 -57%0A34 -105 63 -107 63 -2 0 -314 -466 -694 -1035 l-690 -1035 2560 0 2560 0 -870%0A1305 -870 1305 -180 0 -180 0 -227 340 c-124 187 -229 340 -233 340 -4 0 -212%0A-308 -464 -685z m617 -75 l147 -220 180 0 180 0 488 -732 c269 -403 492 -740%0A497 -748 11 -18 57 -53 -610 454 -302 230 -555 420 -561 423 -7 2 -116 -72%0A-243 -166 -127 -94 -235 -171 -241 -171 -6 0 -29 11 -51 26 -22 14 -160 97%0A-307 186 -147 88 -273 166 -280 173 -11 10 45 101 314 504 180 270 330 491%0A334 491 4 0 73 -99 153 -220z m-558 -1277 l290 -176 160 -339 c88 -186 170%0A-361 182 -388 l23 -50 -1125 0 -1125 0 456 684 456 684 196 -120 c108 -65 328%0A-198 487 -295z m1520 -407 c346 -263 650 -494 674 -513 l44 -33 -625 0 -625 0%0A-197 417 c-108 229 -193 420 -189 424 44 41 269 197 277 192 6 -4 294 -223%0A641 -487z'/%3E%3C/g%3E%3C/svg%3E%0A">
<title>Grades</title>
<style>
:root {
--bg-color: #fff;
--fg-color: #000;
}
[data-theme="dark"] {
--bg-color: #121212;
--fg-color: #ddd;
}
html, body {
font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
height: 100%;
margin: 0;
}
body {
background-color: var(--bg-color);
color: var(--fg-color);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
#grade {
font-size: 30vw;
text-align: center;
}
#answer {
font-size: 10vw;
text-align: center;
}
</style>
</head>
<body>
<div id="grade"></div>
<div id="answer"></div>
</body>
<script>
const pref= window.matchMedia("(prefers-color-scheme: dark)");
pref.addEventListener("change", e => setTheme(e.matches?"dark":"light"));
document.documentElement.setAttribute("data-theme", pref.matches ? "dark" : "light");
</script>
<script>
const route =
`5.6 4c
5.7 5a
5.8 5b
5.9 5c
5.10a 6a
5.10b 6a+
5.10c 6b
5.10d 6b+
5.11a 6c
5.11b 6c~
5.11c 6c+
5.11d 7a
5.12a 7a+
5.12b 7b
5.12c 7b+
5.12d 7c
5.13a 7c+
5.13b 8a
5.13c 8a+
5.13d 8b
5.14a 8b+
5.14b 8c
5.14c 8c+
5.14d 9a
5.15a 9a+
5.15b 9b
5.15c 9b+
5.15d 9c`;
const boulder =
`VB 3
V0 4
V1 5
V2 5+
V3 6A/6A+
V4 6B/6B+
V5 6C/6C+
V6 7A
V7 7A+
V8 7B/7B+
V9 7C
V10 7C+
V11 8A
V12 8A+
V13 8B
V14 8B+
V15 8C
V16 8C+
V17 9A`;
const map = {};
for (const line of route.split('\n')) {
const [yds, font] = line.split(' ');
map[yds] = font;
map[font] = yds;
}
for (const line of boulder.split('\n')) {
const [v, font] = line.split(' ');
for (const f of font.split('/')) {
if (map[v]) {
map[v] = [map[v], f];
} else {
map[v] = f;
}
map[f] = v;
}
}
const keys = Object.keys(map);
const grade = document.getElementById('grade');
const answer = document.getElementById('answer');
const next = () => {
if (answer.style.visibility === 'hidden') {
answer.style.visibility = 'visible';
} else {
const q = keys[Math.floor(Math.random()*keys.length)];
grade.textContent = q;
answer.textContent = Array.isArray(map[q]) ? map[q].join('/') : map[q];
answer.style.visibility = 'hidden';
}
}
document.body.addEventListener('click', next);
next();
</script>
</html>
const readline = require('readline');
const route =
`5.6 4c
5.7 5a
5.8 5b
5.9 5c
5.10a 6a
5.10b 6a+
5.10c 6b
5.10d 6b+
5.11a 6c
5.11b 6c~
5.11c 6c+
5.11d 7a
5.12a 7a+
5.12b 7b
5.12c 7b+
5.12d 7c
5.13a 7c+
5.13b 8a
5.13c 8a+
5.13d 8b
5.14a 8b+
5.14b 8c
5.14c 8c+
5.14d 9a
5.15a 9a+
5.15b 9b
5.15c 9b+
5.15d 9c`;
const boulder =
`VB 3
V0 4
V1 5
V2 5+
V3 6A/6A+
V4 6B/6B+
V5 6C/6C+
V6 7A
V7 7A+
V8 7B/7B+
V9 7C
V10 7C+
V11 8A
V12 8A+
V13 8B
V14 8B+
V15 8C
V16 8C+
V17 9A`;
const map = {};
for (const line of route.split('\n')) {
const [yds, font] = line.split(' ');
map[yds] = font;
map[font] = yds;
}
for (const line of boulder.split('\n')) {
const [v, font] = line.split(' ');
for (const f of font.split('/')) {
if (map[v]) {
map[v] = [map[v], f];
} else {
map[v] = f;
}
map[f] = v;
}
}
const keys = Object.keys(map);
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const question = () => {
const q = keys[Math.floor(Math.random()*keys.length)];
rl.question(`${q}: `, a => {
const correct = Array.isArray(map[q])
? map[q].includes(a)
: (map[q] === a || map[q] === `5.${a}` || map[q] === `V${a}`);
const symbol = correct ? '✓' : '✗';
const color = correct ? '2' : '1';
const answer = Array.isArray(map[q]) ? map[q].join('/') : map[q];
console.log(`\x1b[3${color}m${symbol} ${answer}\x1b[0m`);
question();
});
};
question();
@scheibo
Copy link
Author

scheibo commented Oct 8, 2024

mountain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment