Math 如何在AEM中实施河内塔
我正在尝试实现递归算法求解河内塔 问题显而易见。我知道这种方法可能没有太多明显的效果 在实际应用中,我把它当作一个谜。我最终得到了一些东西 像这样:Math 如何在AEM中实施河内塔,math,recursion,aem,sightly,Math,Recursion,Aem,Sightly,我正在尝试实现递归算法求解河内塔 问题显而易见。我知道这种方法可能没有太多明显的效果 在实际应用中,我把它当作一个谜。我最终得到了一些东西 像这样: <sly data-sly-template.step="${@ n, src, aux, dst}" data-sly-unwrap> <sly data-sly-test="${n > 0}" data-sly-unwrap> <sly data-sly-call="${step @ n = (n
<sly data-sly-template.step="${@ n, src, aux, dst}" data-sly-unwrap>
<sly data-sly-test="${n > 0}" data-sly-unwrap>
<sly data-sly-call="${step @ n = (n-1), src = src, aux = dst, dst = aux}" data-sly-unwrap/>
${src} -> ${dst}<br/>
<sly data-sly-call="${step @ n = (n-1), src = aux, aux = src, dst = dst}" data-sly-unwrap/>
</sly>
</sly>
<sly data-sly-call="${step @ n = 3, src = 'A', aux = 'B', dst = 'C'}" data-sly-unwrap/>
<sly data-sly-template.step="${@ n, src, aux, dst}" data-sly-unwrap>
<sly data-sly-test="${n}" data-sly-unwrap>
<sly data-sly-call="${step @ n = n[0], src = src, aux = dst, dst = aux}" data-sly-unwrap/>
${src} -> ${dst}<br/>
<sly data-sly-call="${step @ n = n[0], src = aux, aux = src, dst = dst}" data-sly-unwrap/>
</sly>
</sly>
<sly data-sly-call="${step @ n = [[[[]]]], src = 'A', aux = 'B', dst = 'C'}" data-sly-unwrap/>
但是,上述表达式不能用作中的参数
数据sly调用
或在数据sly测试中
。我们只能展示它
立即,无需进一步处理
如果我可以使用某个计数器,您还有其他想法吗?使用空嵌套数组:
[]
为0,[[]]
为1,[[[]]
为2,等等。
如果n
是一个数字,则:
递减它(当我们得到内部数组时)n[0]
增加它(当我们用一个新数组包装[n]
时)n
将接受所有n>0(至少两个开口括号)数据测试
<sly data-sly-template.step="${@ n, src, aux, dst}" data-sly-unwrap>
<sly data-sly-test="${n > 0}" data-sly-unwrap>
<sly data-sly-call="${step @ n = (n-1), src = src, aux = dst, dst = aux}" data-sly-unwrap/>
${src} -> ${dst}<br/>
<sly data-sly-call="${step @ n = (n-1), src = aux, aux = src, dst = dst}" data-sly-unwrap/>
</sly>
</sly>
<sly data-sly-call="${step @ n = 3, src = 'A', aux = 'B', dst = 'C'}" data-sly-unwrap/>
<sly data-sly-template.step="${@ n, src, aux, dst}" data-sly-unwrap>
<sly data-sly-test="${n}" data-sly-unwrap>
<sly data-sly-call="${step @ n = n[0], src = src, aux = dst, dst = aux}" data-sly-unwrap/>
${src} -> ${dst}<br/>
<sly data-sly-call="${step @ n = n[0], src = aux, aux = src, dst = dst}" data-sly-unwrap/>
</sly>
</sly>
<sly data-sly-call="${step @ n = [[[[]]]], src = 'A', aux = 'B', dst = 'C'}" data-sly-unwrap/>
${src}->${dst}
有趣的是,这种整数的构造与。看来数学毕竟在web开发中很有用