Skip to content

Instantly share code, notes, and snippets.

@dkaraush
Last active December 11, 2025 11:10
Show Gist options
  • Select an option

  • Save dkaraush/5271c80333d4fa178950a21975e9e10b to your computer and use it in GitHub Desktop.

Select an option

Save dkaraush/5271c80333d4fa178950a21975e9e10b to your computer and use it in GitHub Desktop.
const input = Object.fromEntries(document.querySelector('pre').innerText.trim().split('\n').map(L => [L.substring(0, 3), L.substring(5).split(' ')]))
function traverse(
path = ['you'],
count = {},
last = path[path.length - 1],
dac = path.indexOf('dac') >= 0,
fft = path.indexOf('fft') >= 0,
key = last + dac + fft
) {
if (last == 'out') return !!(path[0] === 'you' || dac && fft)
if (key in count) return count[key]
return count[key] = input[last]
.filter(next => path.indexOf(next) < 0)
.reduce((acc, next) => acc + traverse([...path, next], count), 0)
}
console.log({ result1: traverse(), result2: traverse(['svr']) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment