斐波那契密码高尔夫

编程入门 行业动态 更新时间:2024-10-16 16:42:07
本文介绍了斐波那契密码高尔夫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以尽可能少的字符数生成斐波那契数列.可以使用任何一种语言,但您使用一种运算符f定义的一种语言除外,该语言将打印斐波那契数字.

Generate the Fibonacci sequence in the fewest amount of characters possible. Any language is OK, except for one that you define with one operator, f, which prints the Fibonacci numbers.

起点: Haskell 中的 25 14个字符:

Starting point: 25 14 characters in Haskell:

f=0:1:zipWith(+)f(tail f)

f=0:scanl(+)1f

推荐答案

RePeNt, 9 ,8个字符

RePeNt, 9, 8 chars

1↓[2?+1]

打印10个字符:

1↓[2?+↓£1]

运行方式:

RePeNt "1↓[2?+1]"

RePeNt是我编写(并且还在不断改进)的基于堆栈的玩具语言,其中所有运算符/功能/块/循环都使用反向波兰表示法(RPN).

RePeNt is a stack based toy language I wrote (and am still improving) in which all operators/functions/blocks/loops use Reverse Polish Notation (RPN).

Command Explanation Stack ------- ----------- ----- 1 Push a 1 onto the stack 1 ↓ Push last stack value 1 1 [ Start a do-while loop 1 1 2? Push a two, then pop the 2 and copy the last 2 stack 1 1 1 1 items onto the stack + Add on the stack 1 1 2 ↓£ Push last stack value then print it 1 1 2 1 Push a 1 onto the stack 1 1 2 1 ] Pop value (1 in this case), if it is a 0 exit the loop 1 1 2 otherwise go back to the loop start.

答案在堆栈上,堆栈本身会像这样构建:

The answer is on the stack which builds itself up like:

1 1 1 1 2 1 1 2 3 1 1 2 3 5

它永远不会终止(它具有C#/JAVA do { } while(true)循环的效果),因为该序列永远不会终止,但是可以这样编写终止解决方案:

It never terminates (it has the eqivilent of a C#/JAVA do { } while(true) loop) because the sequence will never terminate, but a terminating solution can be written thus:

N_1↓nI{2?+}

这是12个字符.

我想知道是否有人会读到这个:(

I wonder if anyone will ever read this :(

更多推荐

斐波那契密码高尔夫

本文发布于:2023-11-29 20:58:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高尔夫   密码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!