密码高尔夫新年版-罗马数字整数 [英] Code Golf New Year Edition - Integer to Roman Numeral
问题描述
编写一个使用单个命令行参数N并打印出相应罗马数字.
Write a program that take a single command line argument N and prints out the corresponding Roman Numeral.
例如N = 2009,则应打印MMIX.
Eg N = 2009 should print MMIX.
让我们说这应该适用于0< N < 3000.
Let's say this should work for 0 < N < 3000.
(Had fun playing my first ever round of code golf with the Christmas edition, and thought this could fit for New Year. Googled to see if this has come up before elsewhere and it looks like it hasn't, but let me know if this is too hard or too easy or if the rules need changing. )
MMIX开心!
推荐答案
Perl:69个笔画(算作他们!)
69个笔画包括首先调用perl:
Perl: 69 strokes (count 'em!)
Sixty-nine strokes including calling perl in the first place:
$ perl -ple's!.!($#.=5x$&*8%29628)=~y$IVCXL4620-8$XLMCDIXV$d!eg;last}{'
3484
MMMCDLXXXIV
- 读一行,写一行.
- 工作范围为0到3999(含0和3999). (将空字符串打印为0.)
- 在Perl高尔夫比赛中,这通常得分为62杆=代码的58杆+切换杆的4杆.
- 为什么,是的,那些 是不匹配的花括号.感谢您的询问. =)
- Reads a single line, writes a single line.
- Works from 0 to 3999, inclusive. (Prints empty string for 0.)
- In Perl golf competitions, this is usually scored as 62 strokes = 58 for the code + 4 for the switches.
- Why, yes, those are mismatched braces. Thanks for asking. =)
信用:最初是由于 Ton Hospel .括号不匹配的技巧来自此帖子中的rev.pl
(顺便说一句, enentious ).
Credits: originally due to Ton Hospel. The trick involving the mismatched braces is from rev.pl
in this post (which incidentally, is ingenious).
这篇关于密码高尔夫新年版-罗马数字整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!