CodeGolf:计算给定数字的素因数
受到http://codegolf.com/prime-factors的启发,尝试用最少的方法解决这个问题击键次数。
遗憾的是,你只能与 Perl/PHP/Python/Ruby 竞争,我希望看到这个问题在其他不那么传统的语言中得到解决。
Inspired by http://codegolf.com/prime-factors, try to solve this problem using the least number of keystrokes.
Sadly, you can only compete with Perl/PHP/Python/Ruby and I would love to see this problem solved in other not so traditional languages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Python,214 个字符
我的第一个高尔夫代码,请不要评判。 可能可以做很多优化。
从好的方面来说,它的格式正确。
Python, 214 Characters
My first code golf, don't judge. Probably a lot of optimization that could be done.
On the upside, it formats properly.
Perl
Just 函数 - 返回质因数列表(49 个有效*字符):
用于查找常量的素数(23 个有效*字符):
用于从用户输入中查找数字的素数(28 个有效*字符):
* “重要”字符是非空格以及正确语法所需的任何空格。 对于任何好奇的人来说,重要的空白都是粗体。 :P
Perl
Just the function - returns a list of prime factors (49 significant* characters):
Used to find primes of a constant (23 significant* characters):
Used to find primes of a number from user input (28 significant* characters):
* "Significant" characters are non-whitespace as well as any whitespace that is needed for proper syntax. For anyone curious, significant whitespace is in bold. :P
Perl
10798 个字符
Perl
10798 charactersthat's
Haskell
我最近开始学习 Haskell - 这是一种鲜为人知(但非常好)的语言的尝试。
89 个字符,但确实作弊,因为输出格式又不正确。 我尝试更正输出,但无法得到少于 208 个字符的结果:
欢迎任何改进。 顺便说一句,我很惊讶 GHC 可以让你毫无抱怨地删除多少空白。
Haskell
I've started to learn Haskell recently - here's an attempt in that lesser known (but very nice) language.
89 characters, but cheating really because again the output format isn't right. I tried to correct the output but couldn't get it less than 208 chars:
Any improvements welcomed. On a side note, I was amazed how much whitespace GHC lets you remove without complaining.
PowerShell,146
161字符目前几乎没有问题。
PowerShell, 146
161charsAlmost ungolfed currently.
Python 127 个字符
Python 127 chars