Perl golf:打印数字的幂 [英] Perl golf: Print the powers of a number

查看:120
本文介绍了Perl golf:打印数字的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最短的Perl单行代码是什么,它打印出硬编码的2位小数的前9个幂(例如,.37),每行分别打印一行?

What's the shortest Perl one-liner that print out the first 9 powers of a hard-coded 2 digit decimal (say, for example, .37), each on its own line?

输出看起来像:

1
0.37
0.1369
[etc.]

Perl官方高尔夫规则:

Official Perl golf rules:

  1. (按键)击球次数最少
  2. 您的笔划数包括命令行

推荐答案

在Perl 5.10.0及更高版本中:

With perl 5.10.0 and above:

perl -E'say 0.37**$_ for 0..8'

使用较早的perls时,您没有say和-E,但这是可行的:

With older perls you don't have say and -E, but this works:

perl -le'print 0.37**$_ for 0..8'

更新:第一个解决方案由30个按键组成.删除第一个0会得到29.可以节省另一个空间,所以我的最终解决方案是用28个笔触:

Update: the first solution is made of 30 key strokes. Removing the first 0 gives 29. Another space can be saved, so my final solution is this with 28 strokes:

perl -E'say.37**$_ for 0..8'

这篇关于Perl golf:打印数字的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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