UNPKG

towers-of-hanoi

Version:
63 lines (52 loc) 1.65 kB
'use strict'; var _marked2 = /*#__PURE__*/ regeneratorRuntime.mark(solveHanoi); function solveHanoi(n) { var _marked, _solveHanoi; return regeneratorRuntime.wrap(function solveHanoi$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _solveHanoi = function _ref(n, from, stage, to) { return regeneratorRuntime.wrap(function _solveHanoi$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!(n > 0)) { _context.next = 5; break; } return _context.delegateYield(_solveHanoi(n - 1, from, to, stage), "t0", 2); case 2: _context.next = 4; return { from: from, to: to }; case 4: return _context.delegateYield(_solveHanoi(n - 1, stage, from, to), "t1", 5); case 5: case "end": return _context.stop(); } } }, _marked); }; _marked = /*#__PURE__*/ regeneratorRuntime.mark(_solveHanoi); return _context2.delegateYield(_solveHanoi(n, 1, 2, 3), "t0", 3); case 3: case "end": return _context2.stop(); } } }, _marked2); } function steps(n) { return Math.pow(2, n) - 1; } exports.solveHanoi = solveHanoi; exports.steps = steps; //# sourceMappingURL=hanoi.js.map