Skip to content

Instantly share code, notes, and snippets.

'use strict';
function swiftney_impl(nums, expr, goal) {
if (goal === eval(expr) && nums.length === 0) {
console.log(`${expr} = ${goal}`);
}
if (nums.length > 0) {
const num = nums[0];
['+', '-', '*', '/'].forEach(op => swiftney_impl(nums.slice(1), `(${expr}${op}${num})`, goal));
}