Perl Golf:打印数字的幂
打印出硬编码的 2 位小数的前 9 次幂(例如 0.37)的最短 Perl 一行代码是什么?每行都占一行?
输出将类似于:
1
0.37
0.1369
[etc.]
官方 Perl 高尔夫规则:
- 最小数量的(键)击球获胜
- 您的击球计数包括命令行
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?
The output would look something like:
1
0.37
0.1369
[etc.]
Official Perl golf rules:
- Smallest number of (key)strokes wins
- Your stroke count includes the command line
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
对于 perl 5.10.0 及更高版本:
对于较旧的 perls,您没有
say
和 -E,但这有效:更新:第一个解决方案由 30 个击键组成。 去掉第一个0就得到29。可以节省另一个空间,所以我最终的解决方案是28笔:
With perl 5.10.0 and above:
With older perls you don't have
say
and -E, but this works: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:
31 个字符 - 我没有 5.10 来尝试使用“say”的明显改进,但这是 28:
31 characters - I don't have 5.10 to try out the obvious improvement using "say" but this is 28:
26 - 是的,那是作弊。 (是的,我正在做 1 到 9 的幂。0 到 8 太傻了。)
26 - Yes, that's cheating. (And yes, I'm doing powers from 1 to 9. 0 to 8 is just silly.)
只是为了玩 Perl 6:
28 个字符:
27 个字符:
至少基于当前的空白规则。)
Just for fun in Perl 6:
28 characters:
27 characters:
(At least based on current whitespace rules.)
如果将 -l 添加到选项中,则可以跳过 ,"\n" 部分
If you add -l to options you can skip the ,"\n" part
提交前砍程序的话23招。 :-P
23 strokes if you chop the program before submitting. :-P
只需快速输入即可。 :)
修复换行问题!
Just a quick entry. :)
Fixed to line break!