挑战:一线上最短的Fibonacci序列算法 [英] CHALLENGE: Shortest Algorithim for Fibonacci Sequence on ONE line

查看:60
本文介绍了挑战:一线上最短的Fibonacci序列算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

挑战是用任何编程语言创建最短的算法。


规则:

1.所有代码必须在一行上。

2.不允许使用防止这种情况的语言。 I.E大会,当然还有COBOL。所有其他语言都是公平的游戏。

3.序列必须达到至少 4181.



如果我错过了应该是的语言不允许请告诉我...

我的解决方案是Java。称重为@ 108字符没有空格。

展开 | 选择 | Wrap | 行号

解决方案

应该能够要做到这一点,虽然它的风格很糟糕。

int f = 0,t = 1;

这样的风格很糟糕,不管你的程序间距是多少。


c ++应该更短:

编辑...


可以通过改为for循环来缩短它:

int a = 1,b = 1; for(; b <4182; a = b +(b = a))System.out.println(b);


此外,<必须< 4182如果你想要4181打印你的算法。


在C中,编译器不允许我在任何其他行中使用#include。

所以,不确定这是否可接受。每规则。

<跨度类= codeLink 的onclick =模糊(此,this.parentNode.parentNode,的getChildren (this),true);>展开 | 选择 < span class =codeDivider> | Wrap | 行号


The challenge is to create the shortest algorithim, In any programming language.

RULES:
1. All code must be on one line.
2. Languages that prevent this are disallowed. I.E Assembly, and of course COBOL. All other languages are fair game.
3. Sequence must go up to at least 4181.


If i missed a languge that should be disallowed please let me know...
My solution is in Java. weighing in @ 108 Characters w/o spaces.

Expand|Select|Wrap|Line Numbers

解决方案

should be able to do this, although it''s bad style.
int f=0,t=1;
It''s bad style not spacing your program out anyways.

c++ should be shorter:
editing...


Can make it even shorter by making it a for loop instead:
int a=1,b=1;for(;b<4182;a=b+(b=a))System.out.println(b );

Also, < has to be < 4182 if you want 4181 to print for your algorithm.


In C, the compiler will not let me use #include in the same line as any other.
So, not sure if this is "acceptable" per your rules.

Expand|Select|Wrap|Line Numbers


这篇关于挑战:一线上最短的Fibonacci序列算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆